X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/CompilationUnitScope.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/CompilationUnitScope.java index c6dcbb6..49b458d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/CompilationUnitScope.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/CompilationUnitScope.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter; import net.sourceforge.phpdt.internal.compiler.util.CompoundNameVector; +import net.sourceforge.phpdt.internal.compiler.util.HashtableOfObject; import net.sourceforge.phpdt.internal.compiler.util.HashtableOfType; import net.sourceforge.phpdt.internal.compiler.util.ObjectVector; import net.sourceforge.phpdt.internal.compiler.util.SimpleNameVector; @@ -22,6 +23,9 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclarati import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference; import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IPath; + public class CompilationUnitScope extends Scope { public LookupEnvironment environment; @@ -37,6 +41,7 @@ public class CompilationUnitScope extends Scope { private ObjectVector referencedTypes; HashtableOfType constantPoolNameUsage; + public HashtableOfObject resolvedSingeTypeImports; public CompilationUnitScope(CompilationUnitDeclaration unit, LookupEnvironment environment) { super(COMPILATION_UNIT_SCOPE, null); @@ -130,27 +135,29 @@ public class CompilationUnitScope extends Scope { if (count != topLevelTypes.length) System.arraycopy(topLevelTypes, 0, topLevelTypes = new SourceTypeBinding[count], 0, count); } -// void checkAndSetImports() { -// // initialize the default imports if necessary... share the default java.lang.* import -// if (environment.defaultImports == null) { -// Binding importBinding = environment.getTopLevelPackage(JAVA); -// if (importBinding != null) -// importBinding = ((PackageBinding) importBinding).getTypeOrPackage(JAVA_LANG[1]); -// -// // abort if java.lang cannot be found... -// if (importBinding == null || !importBinding.isValidBinding()) -// problemReporter().isClassPathCorrect(JAVA_LANG_OBJECT, referenceCompilationUnit()); -// -// environment.defaultImports = new ImportBinding[] { new ImportBinding(JAVA_LANG, true, importBinding, null)}; -// } -// if (referenceContext.imports == null) { -// imports = environment.defaultImports; -// return; -// } -// -// // allocate the import array, add java.lang.* by default -// int numberOfStatements = referenceContext.imports.length; + + void checkAndSetImports() { + // initialize the default imports if necessary... share the default java.lang.* import + if (environment.defaultImports == null) { + Binding importBinding = environment.getTopLevelPackage(JAVA); + if (importBinding != null) + importBinding = ((PackageBinding) importBinding).getTypeOrPackage(JAVA_LANG[1]); + + // abort if java.lang cannot be found... + if (importBinding == null || !importBinding.isValidBinding()) + problemReporter().isClassPathCorrect(JAVA_LANG_OBJECT, referenceCompilationUnit()); + + environment.defaultImports = new ImportBinding[] { new ImportBinding(JAVA_LANG, true, importBinding, null)}; + } + if (referenceContext.imports == null) { + imports = environment.defaultImports; + return; + } + + // allocate the import array, add java.lang.* by default + int numberOfStatements = referenceContext.imports.length; // int numberOfImports = numberOfStatements + 1; + int numberOfImports = numberOfStatements; // for (int i = 0; i < numberOfStatements; i++) { // ImportReference importReference = referenceContext.imports[i]; // if (importReference.onDemand && CharOperation.equals(JAVA_LANG, importReference.tokens)) { @@ -158,38 +165,52 @@ public class CompilationUnitScope extends Scope { // break; // } // } -// ImportBinding[] resolvedImports = new ImportBinding[numberOfImports]; -// resolvedImports[0] = environment.defaultImports[0]; -// int index = 1; -// -// nextImport : for (int i = 0; i < numberOfStatements; i++) { -// ImportReference importReference = referenceContext.imports[i]; + ImportBinding[] resolvedImports = new ImportBinding[numberOfImports]; + resolvedImports[0] = environment.defaultImports[0]; + int index = 1; + + nextImport : for (int i = 0; i < numberOfStatements; i++) { + ImportReference importReference = referenceContext.imports[i]; + IFile file = importReference.getFile(); + SourceTypeBinding typeBinding; // char[][] compoundName = importReference.tokens; -// -// // skip duplicates or imports of the current package -// for (int j = 0; j < index; j++) -// if (resolvedImports[j].onDemand == importReference.onDemand) -// if (CharOperation.equals(compoundName, resolvedImports[j].compoundName)) -// continue nextImport; -// if (importReference.onDemand == true) -// if (CharOperation.equals(compoundName, currentPackageName)) -// continue nextImport; -// -// if (importReference.onDemand) { -// Binding importBinding = findOnDemandImport(compoundName); -// if (!importBinding.isValidBinding()) -// continue nextImport; // we report all problems in faultInImports() -// resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference); -// } else { -// resolvedImports[index++] = new ImportBinding(compoundName, false, null, importReference); -// } -// } -// -// // shrink resolvedImports... only happens if an error was reported -// if (resolvedImports.length > index) -// System.arraycopy(resolvedImports, 0, resolvedImports = new ImportBinding[index], 0, index); -// imports = resolvedImports; -// } + char[][] compoundName=null; + if (file != null){ + IPath path = file.getProjectRelativePath(); + String[] segs = path.segments(); + compoundName = new char[segs.length][]; + for (int j = 0; j < segs.length; j++) { + compoundName[j] = segs[j].toCharArray(); + } + } + if (compoundName==null) { + continue nextImport; + } + + // skip duplicates or imports of the current package + for (int j = 0; j < index; j++) + if (resolvedImports[j].onDemand == importReference.onDemand) + if (CharOperation.equals(compoundName, resolvedImports[j].compoundName)) + continue nextImport; + if (importReference.onDemand == true) + if (CharOperation.equals(compoundName, currentPackageName)) + continue nextImport; + + if (importReference.onDemand) { + Binding importBinding = findOnDemandImport(compoundName); + if (!importBinding.isValidBinding()) + continue nextImport; // we report all problems in faultInImports() + resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference); + } else { + resolvedImports[index++] = new ImportBinding(compoundName, false, null, importReference); + } + } + + // shrink resolvedImports... only happens if an error was reported + if (resolvedImports.length > index) + System.arraycopy(resolvedImports, 0, resolvedImports = new ImportBinding[index], 0, index); + imports = resolvedImports; + } /* * INTERNAL USE-ONLY * Innerclasses get their name computed as they are generated, since some may not @@ -239,12 +260,12 @@ public class CompilationUnitScope extends Scope { for (int i = 0, length = topLevelTypes.length; i < length; i++) topLevelTypes[i].scope.connectTypeHierarchy(); } -// void faultInImports() { -// if (referenceContext.imports == null) -// return; + void faultInImports() { + if (referenceContext.imports == null) + return; // // // collect the top level type names if a single type import exists -// int numberOfStatements = referenceContext.imports.length; + int numberOfStatements = referenceContext.imports.length; // HashtableOfType typesBySimpleNames = null; // for (int i = 0; i < numberOfStatements; i++) { // if (!referenceContext.imports[i].onDemand) { @@ -264,12 +285,13 @@ public class CompilationUnitScope extends Scope { // break; // } // } -// ImportBinding[] resolvedImports = new ImportBinding[numberOfImports]; + ImportBinding[] resolvedImports = new ImportBinding[numberOfStatements]; // resolvedImports[0] = environment.defaultImports[0]; // int index = 1; -// -// nextImport : for (int i = 0; i < numberOfStatements; i++) { -// ImportReference importReference = referenceContext.imports[i]; + int index = 0; + nextImport : for (int i = 0; i < numberOfStatements; i++) { + ImportReference importReference = referenceContext.imports[i]; + // create the file name segments here: // char[][] compoundName = importReference.tokens; // // // skip duplicates or imports of the current package @@ -292,11 +314,31 @@ public class CompilationUnitScope extends Scope { // } // resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference); // } else { -// Binding typeBinding = findSingleTypeImport(compoundName); + IFile file = importReference.getFile(); + SourceTypeBinding typeBinding; + char[][] compoundName; + if (file != null){ + typeBinding = new SourceTypeBinding(); +// findSingleTypeImport(compoundName); + IPath path = file.getProjectRelativePath(); + String[] segs = path.segments(); + compoundName = new char[segs.length][]; + for (int j = 0; j < segs.length; j++) { + compoundName[j] = segs[j].toCharArray(); + } + typeBinding.compoundName = compoundName; // compoundName; +// this.fPackage = fPackage; + typeBinding.fileName = file.getLocation().toString().toCharArray(); +// typeBinding.modifiers = scope.referenceContext.modifiers; +// typeBinding.sourceName = scope.referenceContext.name; + typeBinding.sourceName = path.lastSegment().toCharArray(); +// this.scope = scope; + } else { // if (!typeBinding.isValidBinding()) { // problemReporter().importProblem(importReference, typeBinding); -// continue nextImport; + continue nextImport; // } + } // if (typeBinding instanceof PackageBinding) { // problemReporter().cannotImportPackage(importReference); // continue nextImport; @@ -323,18 +365,27 @@ public class CompilationUnitScope extends Scope { // problemReporter().duplicateImport(importReference); // continue nextImport; // } -// resolvedImports[index++] = new ImportBinding(compoundName, false, typeBinding, importReference); + resolvedImports[index++] = new ImportBinding(compoundName, false, typeBinding, importReference); + imports = resolvedImports; // typesBySimpleNames.put(compoundName[compoundName.length - 1], (ReferenceBinding) typeBinding); // } -// } + } // // // shrink resolvedImports... only happens if an error was reported -// if (resolvedImports.length > index) -// System.arraycopy(resolvedImports, 0, resolvedImports = new ImportBinding[index], 0, index); -// imports = resolvedImports; -// } + if (resolvedImports.length > index) + System.arraycopy(resolvedImports, 0, resolvedImports = new ImportBinding[index], 0, index); + imports = resolvedImports; + + int length = imports.length; + resolvedSingeTypeImports = new HashtableOfObject(length); + for (int i = 0; i < length; i++) { + ImportBinding binding = imports[i]; + if (!binding.onDemand) + resolvedSingeTypeImports.put(binding.compoundName[binding.compoundName.length - 1], binding); + } + } public void faultInTypes() { -// faultInImports(); + faultInImports(); if (topLevelTypes==null) { topLevelTypes = new SourceTypeBinding[0]; } @@ -393,7 +444,7 @@ public class CompilationUnitScope extends Scope { return type; } private Binding findSingleTypeImport(char[][] compoundName) { - if (compoundName.length == 1) { +// if (compoundName.length == 1) { // findType records the reference // the name cannot be a package // if (environment.defaultPackage == null @@ -404,8 +455,8 @@ public class CompilationUnitScope extends Scope { return new ProblemReferenceBinding(compoundName, NotFound); else return typeBinding; - } - return findOnDemandImport(compoundName); +// } +// return findOnDemandImport(compoundName); } /* Answer the problem reporter to use for raising new problems. *