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;
import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
+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;
private ObjectVector referencedTypes;
HashtableOfType constantPoolNameUsage;
+ public HashtableOfObject resolvedSingeTypeImports;
public CompilationUnitScope(CompilationUnitDeclaration unit, LookupEnvironment environment) {
super(COMPILATION_UNIT_SCOPE, null);
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)) {
// 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
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) {
// 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
// }
// 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;
// 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];
}
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
return new ProblemReferenceBinding(compoundName, NotFound);
else
return typeBinding;
- }
- return findOnDemandImport(compoundName);
+// }
+// return findOnDemandImport(compoundName);
}
/* Answer the problem reporter to use for raising new problems.
*