Fixed syntaxhiglighting for single line comments. Example:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / lookup / CompilationUnitScope.java
index d50f6f7..49b458d 100644 (file)
@@ -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,14 +41,15 @@ public class CompilationUnitScope extends Scope {
   private ObjectVector referencedTypes;
 
   HashtableOfType constantPoolNameUsage;
+  public HashtableOfObject resolvedSingeTypeImports;
 
   public CompilationUnitScope(CompilationUnitDeclaration unit, LookupEnvironment environment) {
     super(COMPILATION_UNIT_SCOPE, null);
     this.environment = environment;
     this.referenceContext = unit;
     unit.scope = this;
-    this.currentPackageName = unit.currentPackage == null ? CharOperation.NO_CHAR_CHAR : unit.currentPackage.tokens;
-
+//    this.currentPackageName = unit.currentPackage == null ? CharOperation.NO_CHAR_CHAR : unit.currentPackage.tokens;
+    this.currentPackageName = null; 
     // if (environment.options.produceReferenceInfo) {
     //         this.qualifiedReferences = new CompoundNameVector();
     //         this.simpleNameReferences = new SimpleNameVector();
@@ -130,6 +135,7 @@ 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) {
@@ -150,21 +156,36 @@ public class CompilationUnitScope extends Scope {
 
     // allocate the import array, add java.lang.* by default
     int numberOfStatements = referenceContext.imports.length;
-    int numberOfImports = numberOfStatements + 1;
-    for (int i = 0; i < numberOfStatements; i++) {
-      ImportReference importReference = referenceContext.imports[i];
-      if (importReference.onDemand && CharOperation.equals(JAVA_LANG, importReference.tokens)) {
-        numberOfImports--;
-        break;
-      }
-    }
+//    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)) {
+//        numberOfImports--;
+//        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];
-      char[][] compoundName = importReference.tokens;
+      IFile file = importReference.getFile();
+      SourceTypeBinding typeBinding;
+//      char[][] compoundName = importReference.tokens;
+      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++)
@@ -242,96 +263,126 @@ public class CompilationUnitScope extends Scope {
   void faultInImports() {
     if (referenceContext.imports == null)
       return;
-
-    // collect the top level type names if a single type import exists
+//
+//    // collect the top level type names if a single type import exists
     int numberOfStatements = referenceContext.imports.length;
-    HashtableOfType typesBySimpleNames = null;
-    for (int i = 0; i < numberOfStatements; i++) {
-      if (!referenceContext.imports[i].onDemand) {
-        typesBySimpleNames = new HashtableOfType(topLevelTypes.length + numberOfStatements);
-        for (int j = 0, length = topLevelTypes.length; j < length; j++)
-          typesBySimpleNames.put(topLevelTypes[j].sourceName, topLevelTypes[j]);
-        break;
-      }
-    }
-
-    // allocate the import array, add java.lang.* by default
-    int numberOfImports = numberOfStatements + 1;
-    for (int i = 0; i < numberOfStatements; i++) {
-      ImportReference importReference = referenceContext.imports[i];
-      if (importReference.onDemand && CharOperation.equals(JAVA_LANG, importReference.tokens)) {
-        numberOfImports--;
-        break;
-      }
-    }
-    ImportBinding[] resolvedImports = new ImportBinding[numberOfImports];
-    resolvedImports[0] = environment.defaultImports[0];
-    int index = 1;
-
+//    HashtableOfType typesBySimpleNames = null;
+//    for (int i = 0; i < numberOfStatements; i++) {
+//      if (!referenceContext.imports[i].onDemand) {
+//        typesBySimpleNames = new HashtableOfType(topLevelTypes.length + numberOfStatements);
+//        for (int j = 0, length = topLevelTypes.length; j < length; j++)
+//          typesBySimpleNames.put(topLevelTypes[j].sourceName, topLevelTypes[j]);
+//        break;
+//      }
+//    }
+//
+//    // allocate the import array, add java.lang.* by default
+//    int numberOfImports = numberOfStatements + 1;
+//    for (int i = 0; i < numberOfStatements; i++) {
+//      ImportReference importReference = referenceContext.imports[i];
+//      if (importReference.onDemand && CharOperation.equals(JAVA_LANG, importReference.tokens)) {
+//        numberOfImports--;
+//        break;
+//      }
+//    }
+    ImportBinding[] resolvedImports = new ImportBinding[numberOfStatements];
+//    resolvedImports[0] = environment.defaultImports[0];
+//    int index = 1;
+    int index = 0;
     nextImport : for (int i = 0; i < numberOfStatements; i++) {
       ImportReference importReference = referenceContext.imports[i];
-      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)) {
-            problemReporter().unusedImport(importReference); // since skipped, must be reported now
-            continue nextImport;
-          }
-      if (importReference.onDemand == true)
-        if (CharOperation.equals(compoundName, currentPackageName)) {
-          problemReporter().unusedImport(importReference); // since skipped, must be reported now
-          continue nextImport;
-        }
-      if (importReference.onDemand) {
-        Binding importBinding = findOnDemandImport(compoundName);
-        if (!importBinding.isValidBinding()) {
-          problemReporter().importProblem(importReference, importBinding);
-          continue nextImport;
-        }
-        resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference);
-      } else {
-        Binding typeBinding = findSingleTypeImport(compoundName);
-        if (!typeBinding.isValidBinding()) {
-          problemReporter().importProblem(importReference, typeBinding);
-          continue nextImport;
-        }
-        if (typeBinding instanceof PackageBinding) {
-          problemReporter().cannotImportPackage(importReference);
-          continue nextImport;
-        }
-        if (typeBinding instanceof ReferenceBinding) {
-          ReferenceBinding referenceBinding = (ReferenceBinding) typeBinding;
-          if (importReference.isTypeUseDeprecated(referenceBinding, this)) {
-            problemReporter().deprecatedType((TypeBinding) typeBinding, importReference);
-          }
+      // create the file name segments here:
+//      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)) {
+//            problemReporter().unusedImport(importReference); // since skipped, must be reported now
+//            continue nextImport;
+//          }
+//      if (importReference.onDemand == true)
+//        if (CharOperation.equals(compoundName, currentPackageName)) {
+//          problemReporter().unusedImport(importReference); // since skipped, must be reported now
+//          continue nextImport;
+//        }
+//      if (importReference.onDemand) {
+//        Binding importBinding = findOnDemandImport(compoundName);
+//        if (!importBinding.isValidBinding()) {
+//          problemReporter().importProblem(importReference, importBinding);
+//          continue nextImport;
+//        }
+//        resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference);
+//      } else {
+      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();
         }
-        ReferenceBinding existingType = typesBySimpleNames.get(compoundName[compoundName.length - 1]);
-        if (existingType != null) {
-          // duplicate test above should have caught this case, but make sure
-          if (existingType == typeBinding) {
-            continue nextImport;
-          }
-          // either the type collides with a top level type or another imported type
-          for (int j = 0, length = topLevelTypes.length; j < length; j++) {
-            if (CharOperation.equals(topLevelTypes[j].sourceName, existingType.sourceName)) {
-              problemReporter().conflictingImport(importReference);
-              continue nextImport;
-            }
-          }
-          problemReporter().duplicateImport(importReference);
+        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;
-        }
+//        }
+    }
+//        if (typeBinding instanceof PackageBinding) {
+//          problemReporter().cannotImportPackage(importReference);
+//          continue nextImport;
+//        }
+//        if (typeBinding instanceof ReferenceBinding) {
+//          ReferenceBinding referenceBinding = (ReferenceBinding) typeBinding;
+//          if (importReference.isTypeUseDeprecated(referenceBinding, this)) {
+//            problemReporter().deprecatedType((TypeBinding) typeBinding, importReference);
+//          }
+//        }
+//        ReferenceBinding existingType = typesBySimpleNames.get(compoundName[compoundName.length - 1]);
+//        if (existingType != null) {
+//          // duplicate test above should have caught this case, but make sure
+//          if (existingType == typeBinding) {
+//            continue nextImport;
+//          }
+//          // either the type collides with a top level type or another imported type
+//          for (int j = 0, length = topLevelTypes.length; j < length; j++) {
+//            if (CharOperation.equals(topLevelTypes[j].sourceName, existingType.sourceName)) {
+//              problemReporter().conflictingImport(importReference);
+//              continue nextImport;
+//            }
+//          }
+//          problemReporter().duplicateImport(importReference);
+//          continue nextImport;
+//        }
         resolvedImports[index++] = new ImportBinding(compoundName, false, typeBinding, importReference);
-        typesBySimpleNames.put(compoundName[compoundName.length - 1], (ReferenceBinding) typeBinding);
-      }
+        imports = resolvedImports;
+//        typesBySimpleNames.put(compoundName[compoundName.length - 1], (ReferenceBinding) typeBinding);
+//      }
     }
-
-    // shrink resolvedImports... only happens if an error was reported
+//
+//    // 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;
+    
+    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();
@@ -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.
   *