Merged "Open PHP Declaration" and "Open Include File" into one action "Open Declarati...
authoraxelcl <axelcl>
Wed, 5 Jan 2005 19:36:13 +0000 (19:36 +0000)
committeraxelcl <axelcl>
Wed, 5 Jan 2005 19:36:13 +0000 (19:36 +0000)
14 files changed:
net.sourceforge.phpeclipse/plugin.properties
net.sourceforge.phpeclipse/plugin.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/BinaryTypeBinding.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/CompilationUnitScope.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/LookupEnvironment.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/ReferenceBinding.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/SourceTypeBinding.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelOperation.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/PackageFragment.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/SearchableEnvironment.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorAction.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenIncludeEditorAction.java [deleted file]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/internal/compiler/ast/ImportReference.java

index 83a4ccf..dab4d83 100644 (file)
@@ -23,6 +23,7 @@ newWizardHTMLFile.name=HTML file
 NewPHPClass.label= Class
 NewPHPClass.description=Create a PHP class
 
+OpenDeclaration=Open Declaration/Include
 ExportWizards.Obfuscator = Obfuscate PHP Project to File system
 ExportWizards.ObfuscatorDescription = Obfuscate PHP resources to the local file system
 
index 63cea1a..57699a0 100644 (file)
@@ -11,6 +11,7 @@
       <library name="phpeclipse.jar">
         <export name="*"/>
       </library>
+ <!--     <library name="lib/xstream-1.0.2.jar" /> -->
    </runtime>
    <requires>
       <import plugin="org.eclipse.core.runtime.compatibility"/>
   
       <viewerContribution
             targetID="#PHPEditorContext"
-            id="net.sourceforge.phpeclipse.actions.popupOpenDeclaration">
-         <action
-               label="Open PHP Declaration"
-               class="net.sourceforge.phpeclipse.actions.PHPOpenDeclarationEditorAction"
-               menubarPath="additions"
-               id="net.sourceforge.phpeclipse.actions.opendeclaration">
-         </action>
-      </viewerContribution>
-      <viewerContribution
-            targetID="#PHPEditorContext"
-            id="net.sourceforge.phpeclipse.actions.popupOpenAllIncludes">
+            id="net.sourceforge.phpeclipse.actions.popupOpenSQLTable">
          <action
-               label="Open Included Files List"
-               class="net.sourceforge.phpeclipse.actions.PHPOpenAllIncludesEditorAction"
+               label="Open Quantum SQL Table View"
+               class="net.sourceforge.phpeclipse.actions.PHPOpenSQLTableEditorAction"
                menubarPath="additions"
-               id="net.sourceforge.phpeclipse.actions.openallincludes">
+               id="net.sourceforge.phpeclipse.actions.opensqltable">
          </action>
       </viewerContribution>
       <viewerContribution
             targetID="#PHPEditorContext"
-            id="net.sourceforge.phpeclipse.actions.popupOpenInclude">
+            id="net.sourceforge.phpeclipse.actions.popupHTMLWizard">
          <action
-               label="Open Include File"
-               class="net.sourceforge.phpeclipse.actions.PHPOpenIncludeEditorAction"
+               label="Insert HTML (dl,ul,ol,table)"
+               class="net.sourceforge.phpeclipse.wizards.html.InsertHTMLElementAction"
                menubarPath="additions"
-               id="net.sourceforge.phpeclipse.actions.openinclude">
+               id="net.sourceforge.phpeclipse.actions.wizards.html">
          </action>
       </viewerContribution>
       <viewerContribution
             targetID="#PHPEditorContext"
-            id="net.sourceforge.phpeclipse.actions.popupOpenSQLTable">
+            id="net.sourceforge.phpeclipse.actions.popupOpenAllIncludes">
          <action
-               label="Open Quantum SQL Table View"
-               class="net.sourceforge.phpeclipse.actions.PHPOpenSQLTableEditorAction"
+               label="Open Included Files List"
+               class="net.sourceforge.phpeclipse.actions.PHPOpenAllIncludesEditorAction"
                menubarPath="additions"
-               id="net.sourceforge.phpeclipse.actions.opensqltable">
+               id="net.sourceforge.phpeclipse.actions.openallincludes">
          </action>
       </viewerContribution>
       <viewerContribution
             targetID="#PHPEditorContext"
-            id="net.sourceforge.phpeclipse.actions.popupHTMLWizard">
+            id="net.sourceforge.phpeclipse.actions.popupOpenDeclaration">
          <action
-               label="Insert HTML (dl,ul,ol,table)"
-               class="net.sourceforge.phpeclipse.wizards.html.InsertHTMLElementAction"
+               label="%OpenDeclaration"
+               class="net.sourceforge.phpeclipse.actions.PHPOpenDeclarationEditorAction"
                menubarPath="additions"
-               id="net.sourceforge.phpeclipse.actions.wizards.html">
+               definitionId="net.sourceforge.phpeclipse.actions.opendeclaration"
+               id="net.sourceforge.phpeclipse.actions.PHPOpenDeclarationEditorAction">
          </action>
       </viewerContribution>
-   
+      
       <viewerContribution
             targetID="#PHPRulerContext"
             id="net.sourceforge.phpdt.ui.PHPEditorPopupActions">
       <editorContribution
             id="org.eclipse.ui.texteditor.ruler.actions"
             targetID="net.sourceforge.phpeclipse.PHPUnitEditor">
-
                <action
                        id="org.eclipse.ui.texteditor.BookmarkRulerAction"
                        actionID="RulerDoubleClick"
             targetID="net.sourceforge.phpeclipse.PHPUnitEditor">
          <action 
                definitionId="net.sourceforge.phpeclipse.actions.opendeclaration"
-               label="Open PHP Declaration"
+               label="%OpenDeclaration"
                class="net.sourceforge.phpeclipse.actions.PHPOpenDeclarationEditorAction"
                id="net.sourceforge.phpeclipse.actions.PHPOpenDeclarationEditorAction">
          </action>
       </keyBinding>
       
       <command
-            name="Open PHP Declaration" 
-            description="Open PHP Declaration"
+            name="%OpenDeclaration" 
+            description="%OpenDeclaration"
             category="net.sourceforge.phpeclipse.ui.category.source"
             id="net.sourceforge.phpeclipse.actions.opendeclaration">
       </command>
index b9dafb5..04dd47d 100644 (file)
@@ -42,7 +42,7 @@ public final class BinaryTypeBinding extends ReferenceBinding {
        private LookupEnvironment environment;
 public BinaryTypeBinding(PackageBinding packageBinding, IBinaryType binaryType, LookupEnvironment environment) {
        this.compoundName = CharOperation.splitOn('/', binaryType.getName());
-       computeId();
+//     computeId();
 
        this.tagBits |= IsBinaryBinding;
        this.environment = environment;
index 8825732..49b458d 100644 (file)
@@ -15,12 +15,17 @@ 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;
 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;
@@ -36,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);
@@ -129,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)) {
@@ -157,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
@@ -238,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) {
@@ -263,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
@@ -291,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;
@@ -322,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];
     }
@@ -392,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 
@@ -403,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.
   *
index c2be8ee..249d948 100644 (file)
@@ -217,12 +217,13 @@ public void completeTypeBindings(CompilationUnitDeclaration parsedUnit) {
 public void completeTypeBindings(CompilationUnitDeclaration parsedUnit, boolean buildFieldsAndMethods) {
        if (parsedUnit.scope == null) return; // parsing errors were too severe
 
-//     parsedUnit.scope.checkAndSetImports();
+       parsedUnit.scope.checkAndSetImports();
        parsedUnit.scope.connectTypeHierarchy();
 
        if (buildFieldsAndMethods)
                parsedUnit.scope.buildFieldsAndMethods();
 }
+
 private PackageBinding computePackageFrom(char[][] constantPoolName) {
        if (constantPoolName.length == 1)
                return defaultPackage;
index 81faa08..ab0d9cf 100644 (file)
@@ -180,121 +180,121 @@ public final boolean canBeSeenBy(Scope scope) {
        // isDefault()
        return invocationType.fPackage == fPackage;
 }
-public void computeId() {
-       if (compoundName.length != 3) {
-               if (compoundName.length == 4 && CharOperation.equals(JAVA_LANG_REFLECT_CONSTRUCTOR, compoundName)) {
-                       id = T_JavaLangReflectConstructor;
-                       return;
-               }
-               return;         // all other types are in java.*.*
-       }
-
-       if (!CharOperation.equals(JAVA, compoundName[0]))
-               return;         // assumes we only look up types in java
-
-       if (!CharOperation.equals(LANG, compoundName[1])) {
-               if (CharOperation.equals(JAVA_IO_PRINTSTREAM, compoundName)) {
-                       id = T_JavaIoPrintStream;
-                       return;
-               }
-               return;         // all other types are in java.lang
-       }
-
-       if (CharOperation.equals(JAVA_LANG_OBJECT, compoundName)) {
-               id = T_JavaLangObject;
-               return;
-       }
-       if (CharOperation.equals(JAVA_LANG_STRING, compoundName)) {
-               id = T_JavaLangString;
-               return;
-       }
-
-       // well-known exception types
-       if (CharOperation.equals(JAVA_LANG_THROWABLE, compoundName)) {
-               id = T_JavaLangThrowable;
-               return;
-       }
-       if (CharOperation.equals(JAVA_LANG_ERROR, compoundName)) {
-               id = T_JavaLangError;
-               return;
-       }
-       if (CharOperation.equals(JAVA_LANG_EXCEPTION, compoundName)) {
-               id = T_JavaLangException;
-               return;
-       }
-       if (CharOperation.equals(JAVA_LANG_CLASSNOTFOUNDEXCEPTION, compoundName)) {
-               id = T_JavaLangClassNotFoundException;
-               return;
-       }
-       if (CharOperation.equals(JAVA_LANG_NOCLASSDEFERROR, compoundName)) {
-               id = T_JavaLangNoClassDefError;
-               return;
-       }
-
-       // other well-known types
-       if (CharOperation.equals(JAVA_LANG_CLASS, compoundName)) {
-               id = T_JavaLangClass;
-               return;
-       }
-       if (CharOperation.equals(JAVA_LANG_STRINGBUFFER, compoundName)) {
-               id = T_JavaLangStringBuffer;
-               return;
-       }
-       if (CharOperation.equals(JAVA_LANG_SYSTEM, compoundName)) {
-               id = T_JavaLangSystem;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_INTEGER, compoundName)) {
-               id = T_JavaLangInteger;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_BYTE, compoundName)) {
-               id = T_JavaLangByte;
-               return;
-       }       
-
-       if (CharOperation.equals(JAVA_LANG_CHARACTER, compoundName)) {
-               id = T_JavaLangCharacter;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_FLOAT, compoundName)) {
-               id = T_JavaLangFloat;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_DOUBLE, compoundName)) {
-               id = T_JavaLangDouble;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_BOOLEAN, compoundName)) {
-               id = T_JavaLangBoolean;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_SHORT, compoundName)) {
-               id = T_JavaLangShort;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_LONG, compoundName)) {
-               id = T_JavaLangLong;
-               return;
-       }
-
-       if (CharOperation.equals(JAVA_LANG_VOID, compoundName)) {
-               id = T_JavaLangVoid;
-               return;
-       }
-       
-       if (CharOperation.equals(JAVA_LANG_ASSERTIONERROR, compoundName)) {
-               id = T_JavaLangAssertionError;
-               return;
-       }
-}
+//public void computeId() {
+//     if (compoundName.length != 3) {
+//             if (compoundName.length == 4 && CharOperation.equals(JAVA_LANG_REFLECT_CONSTRUCTOR, compoundName)) {
+//                     id = T_JavaLangReflectConstructor;
+//                     return;
+//             }
+//             return;         // all other types are in java.*.*
+//     }
+//
+//     if (!CharOperation.equals(JAVA, compoundName[0]))
+//             return;         // assumes we only look up types in java
+//
+//     if (!CharOperation.equals(LANG, compoundName[1])) {
+//             if (CharOperation.equals(JAVA_IO_PRINTSTREAM, compoundName)) {
+//                     id = T_JavaIoPrintStream;
+//                     return;
+//             }
+//             return;         // all other types are in java.lang
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_OBJECT, compoundName)) {
+//             id = T_JavaLangObject;
+//             return;
+//     }
+//     if (CharOperation.equals(JAVA_LANG_STRING, compoundName)) {
+//             id = T_JavaLangString;
+//             return;
+//     }
+//
+//     // well-known exception types
+//     if (CharOperation.equals(JAVA_LANG_THROWABLE, compoundName)) {
+//             id = T_JavaLangThrowable;
+//             return;
+//     }
+//     if (CharOperation.equals(JAVA_LANG_ERROR, compoundName)) {
+//             id = T_JavaLangError;
+//             return;
+//     }
+//     if (CharOperation.equals(JAVA_LANG_EXCEPTION, compoundName)) {
+//             id = T_JavaLangException;
+//             return;
+//     }
+//     if (CharOperation.equals(JAVA_LANG_CLASSNOTFOUNDEXCEPTION, compoundName)) {
+//             id = T_JavaLangClassNotFoundException;
+//             return;
+//     }
+//     if (CharOperation.equals(JAVA_LANG_NOCLASSDEFERROR, compoundName)) {
+//             id = T_JavaLangNoClassDefError;
+//             return;
+//     }
+//
+//     // other well-known types
+//     if (CharOperation.equals(JAVA_LANG_CLASS, compoundName)) {
+//             id = T_JavaLangClass;
+//             return;
+//     }
+//     if (CharOperation.equals(JAVA_LANG_STRINGBUFFER, compoundName)) {
+//             id = T_JavaLangStringBuffer;
+//             return;
+//     }
+//     if (CharOperation.equals(JAVA_LANG_SYSTEM, compoundName)) {
+//             id = T_JavaLangSystem;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_INTEGER, compoundName)) {
+//             id = T_JavaLangInteger;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_BYTE, compoundName)) {
+//             id = T_JavaLangByte;
+//             return;
+//     }       
+//
+//     if (CharOperation.equals(JAVA_LANG_CHARACTER, compoundName)) {
+//             id = T_JavaLangCharacter;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_FLOAT, compoundName)) {
+//             id = T_JavaLangFloat;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_DOUBLE, compoundName)) {
+//             id = T_JavaLangDouble;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_BOOLEAN, compoundName)) {
+//             id = T_JavaLangBoolean;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_SHORT, compoundName)) {
+//             id = T_JavaLangShort;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_LONG, compoundName)) {
+//             id = T_JavaLangLong;
+//             return;
+//     }
+//
+//     if (CharOperation.equals(JAVA_LANG_VOID, compoundName)) {
+//             id = T_JavaLangVoid;
+//             return;
+//     }
+//     
+//     if (CharOperation.equals(JAVA_LANG_ASSERTIONERROR, compoundName)) {
+//             id = T_JavaLangAssertionError;
+//             return;
+//     }
+//}
 /* Answer the receiver's constant pool name.
 *
 * NOTE: This method should only be used during/after code gen.
index 13e8646..97f6ed8 100644 (file)
@@ -53,7 +53,7 @@ public SourceTypeBinding(char[][] compoundName, PackageBinding fPackage, ClassSc
        this.sourceName = scope.referenceContext.name;
        this.scope = scope;
 
-       computeId();
+//     computeId();
 }
 private void addDefaultAbstractMethod(MethodBinding abstractMethod) {
        MethodBinding defaultAbstract = new MethodBinding(
index dfb95ea..fb2c252 100644 (file)
@@ -44,6 +44,7 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
 
 public class Parser //extends PHPParserSuperclass
     implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
@@ -3396,12 +3397,16 @@ public class Parser //extends PHPParserSuperclass
           //      System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
           IProject project = resource.getProject();
           if (project != null) {
-            if (PHPFileUtil.determineFilePath(includeNameString, resource, project) == null) {
+            IPath path = PHPFileUtil.determineFilePath(includeNameString, resource, project);
+            
+            if (path == null) {
               //              reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
               //                  + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
               String[] args = { expression.toStringExpression(), project.getLocation().toString() };
               problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
                   compilationUnit.compilationResult);
+            } else {
+              impt.setFile( project.getFile(path) );
             }
           }
         }
index 2efde2a..f33c7a9 100644 (file)
@@ -737,7 +737,7 @@ public abstract class JavaModelOperation implements IWorkspaceRunnable, IProgres
                                // - the operation is a top level operation
                                // - the operation did produce some delta(s)
                                // - but the operation has not modified any resource
-                               if (this.isTopLevelOperation()) {
+                               if (this.isTopLevelOperation()) {
                                        if ((manager.javaModelDeltas.size() > previousDeltaCount || !manager.reconcileDeltas.isEmpty()) 
                                                        && !this.hasModifiedResource()) {
                                                manager.fire(null, JavaModelManager.DEFAULT_CHANGE_EVENT);
index 405364b..06f1c5f 100644 (file)
@@ -233,7 +233,7 @@ protected Object createElementInfo() {
 //}
 /**
  * @see IPackageFragment#getCompilationUnit(String)
- * @exception IllegalArgumentExcpetion if the name does not end with ".java"
+ * @exception IllegalArgumentExcpetion if the name does not end with a php file extension
  */
 public ICompilationUnit getCompilationUnit(String cuName) {
        if (!  PHPFileUtil.isValidPHPUnitName(cuName)) {
index a7795eb..87fe51a 100644 (file)
@@ -73,6 +73,7 @@ public class SearchableEnvironment implements ISearchableNameEnvironment, IJavaS
     if (packageName == null)
       packageName = IPackageFragment.DEFAULT_PACKAGE_NAME;
    
+    if (this.nameLookup!=null) { // ins axelcl
     IType type = this.nameLookup.findType(typeName, packageName, false, NameLookup.ACCEPT_CLASSES | NameLookup.ACCEPT_INTERFACES);
     if (type != null) {
       //                       if (type instanceof BinaryType) {
@@ -107,6 +108,7 @@ public class SearchableEnvironment implements ISearchableNameEnvironment, IJavaS
       }
       //                       }
     }
+    }
     return null;
   }
 
index 313e6de..2dd8a72 100644 (file)
@@ -1,11 +1,10 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Common Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/cpl-v10.html
+/***********************************************************************************************************************************
+ * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
  * 
  * Contributors: www.phpeclipse.de
- ******************************************************************************/
+ **********************************************************************************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
 import java.io.File;
@@ -19,9 +18,11 @@ import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
 
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -39,59 +40,7 @@ import org.eclipse.ui.actions.ActionDelegate;
 import org.eclipse.ui.dialogs.ListSelectionDialog;
 import org.eclipse.ui.internal.dialogs.ListContentProvider;
 
-public class PHPOpenDeclarationEditorAction extends ActionDelegate implements
-    IEditorActionDelegate {
-
-//  class Include implements Comparable {
-//    final public static int UNDEFINED_MATCH = 0;
-//    final public static int PATTERN_MATCH = 1;
-//    final public static int EXACT_MATCH = 2;
-//
-//    String fName;
-//
-//    int fMatch;
-//
-//    public Include(String name, int match) {
-//      fName = name;
-//      fMatch = match;
-//    }
-//
-//    /*
-//     * (non-Javadoc)
-//     * 
-//     * @see java.lang.Object#toString()
-//     */
-//    public String toString() {
-//      switch (fMatch) {
-//      case UNDEFINED_MATCH:
-//        return fName;
-//      case PATTERN_MATCH:
-//        return "[pattern included] " + fName;
-//      case EXACT_MATCH:
-//        return "[included] " + fName;
-//      }
-//      return fName;
-//    }
-//
-//    /**
-//     * @return Returns the name.
-//     */
-//    public String getName() {
-//      return fName;
-//    }
-//    /* (non-Javadoc)
-//     * @see java.lang.Comparable#compareTo(java.lang.Object)
-//     */
-//    public int compareTo(Object o) {
-//      Include i = (Include)o;
-//      if (fMatch>i.fMatch) {
-//        return 1;
-//      } else if (fMatch<i.fMatch) {
-//        return -1;
-//      }
-//      return fName.compareTo(i.fName);
-//    }
-//  }
+public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IEditorActionDelegate {
 
   private IWorkbenchWindow fWindow;
 
@@ -99,6 +48,8 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements
 
   private IProject fProject;
 
+  private boolean isIncludeString;
+
   public void dispose() {
   }
 
@@ -110,8 +61,7 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements
     if (!selection.isEmpty()) {
       if (selection instanceof TextSelection) {
         action.setEnabled(true);
-      } else if (fWindow.getActivePage() != null
-          && fWindow.getActivePage().getActivePart() != null) {
+      } else if (fWindow.getActivePage() != null && fWindow.getActivePage().getActivePart() != null) {
         //
       }
     }
@@ -130,90 +80,145 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements
       fProject = f.getProject();
       //      System.out.println(fProject.toString());
 
-      ITextSelection selection = (ITextSelection) fEditor
-          .getSelectionProvider().getSelection();
-      IDocument doc = fEditor.getDocumentProvider().getDocument(
-          fEditor.getEditorInput());
+      ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
+      IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
       int pos = selection.getOffset();
       //  System.out.println(selection.getText());
-      String word = getPHPIdentifier(doc, pos);
+      String identifierOrInclude = getIdentifierOrInclude(doc, pos);
       //      System.out.println(word);
-      if (word != null && !word.equals("")) {
-        IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault()
-            .getIndexManager(fProject);
-        List locationsList = indexManager.getLocations(word);
-        if (locationsList != null && locationsList.size() > 0) {
-
-//          String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot()
-//              .getLocation().toString();
-          
-          String workspaceLocation = fProject.getLocation().toString()+File.separatorChar;
-          // TODO show all entries of the list in a dialog box
-          // at the moment always the first entry will be opened
-          if (locationsList.size() > 1) {
-            // determine all includes:
-            IncludesScanner includesScanner = new IncludesScanner(fProject,
-                (IFileEditorInput) fEditor.getEditorInput());
-            includesScanner.addFile(f);
-            Set exactIncludeSet = includesScanner.getSet();
-
-            PHPIdentifierLocation includeName;
-            for (int i = 0; i < locationsList.size(); i++) {
-              includeName = (PHPIdentifierLocation) locationsList.get(i);
-              if (exactIncludeSet.contains(includeName.getFilename())) {
-                includeName.setMatch(PHPIdentifierLocation.EXACT_MATCH);
-              } else {
-                includeName.setMatch(PHPIdentifierLocation.UNDEFINED_MATCH);
+      if (identifierOrInclude != null && !identifierOrInclude.equals("")) {
+        if (isIncludeString) {
+          openIncludeFile(identifierOrInclude);
+        } else {
+          openIdentifierDeclaration(f, identifierOrInclude);
+        }
+      }
+    }
+  }
+
+  /**
+   * @param filename
+   */
+  private void openIncludeFile(String filename) {
+    if (filename != null && !filename.equals("")) {
+      try {
+        IFile file = getIncludeFile(fProject, (IFileEditorInput) fEditor.getEditorInput(), filename);
+        if (file != null && file.exists()) {
+          PHPeclipsePlugin.getDefault().openFileInTextEditor(file.getLocation().toString());
+          return;
+        }
+      } catch (Exception e) {
+        // ignore
+      }
+
+      try {
+
+        IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
+        //            filename = StringUtil.replaceRegExChars(filename);
+        List list = indexManager.getFileList(filename);
+        if (list != null && list.size() > 0) {
+          //String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
+          String workspaceLocation = fProject.getLocation().toString() + File.separatorChar;
+
+          ListSelectionDialog listSelectionDialog = new ListSelectionDialog(PHPeclipsePlugin.getDefault().getWorkbench()
+              .getActiveWorkbenchWindow().getShell(), list, new ListContentProvider(), new LabelProvider(),
+              "Select the includes to open.");
+          listSelectionDialog.setTitle("Multiple includes found");
+          if (listSelectionDialog.open() == Window.OK) {
+            Object[] locations = listSelectionDialog.getResult();
+            if (locations != null) {
+              try {
+                for (int i = 0; i < locations.length; i++) {
+                  //                    PHPIdentifierLocation location = (PHPIdentifierLocation)
+                  // locations[i];
+                  String openFilename = workspaceLocation + ((String) locations[i]);
+                  PHPeclipsePlugin.getDefault().openFileInTextEditor(openFilename);
+                }
+              } catch (CoreException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
               }
             }
-            Collections.sort(locationsList);
-            
-            ListSelectionDialog listSelectionDialog = new ListSelectionDialog(
-                PHPeclipsePlugin.getDefault().getWorkbench()
-                    .getActiveWorkbenchWindow().getShell(), locationsList,
-                new ListContentProvider(), new LabelProvider(),
-                "Select the resources to open.");
-            listSelectionDialog.setTitle("Multiple declarations found");
-            if (listSelectionDialog.open() == Window.OK) {
-              Object[] locations = listSelectionDialog.getResult();
-              if (locations != null) {
-                try {
-                  for (int i = 0; i < locations.length; i++) {
-                    PHPIdentifierLocation location = (PHPIdentifierLocation) locations[i];
-                    String filename = workspaceLocation
-                        + location.getFilename();
-                    //                                 System.out.println(filename);
-                    if (location.getOffset() >= 0) {
-                      PHPeclipsePlugin.getDefault().openFileAndGotoOffset(
-                          filename, location.getOffset(), word.length());
-                    } else {
-                      PHPeclipsePlugin.getDefault().openFileAndFindString(
-                          filename, word);
-                    }
+          }
+
+        }
+      } catch (Exception e) {
+      }
+
+    }
+    return;
+  }
+
+  /**
+   * @param f
+   * @param identiifer
+   */
+  private void openIdentifierDeclaration(IFile f, String identiifer) {
+    if (identiifer != null && !identiifer.equals("")) {
+      IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
+      List locationsList = indexManager.getLocations(identiifer);
+      if (locationsList != null && locationsList.size() > 0) {
+
+        //          String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot()
+        //              .getLocation().toString();
+
+        String workspaceLocation = fProject.getLocation().toString() + File.separatorChar;
+        // TODO show all entries of the list in a dialog box
+        // at the moment always the first entry will be opened
+        if (locationsList.size() > 1) {
+          // determine all includes:
+          IncludesScanner includesScanner = new IncludesScanner(fProject, (IFileEditorInput) fEditor.getEditorInput());
+          includesScanner.addFile(f);
+          Set exactIncludeSet = includesScanner.getSet();
+
+          PHPIdentifierLocation includeName;
+          for (int i = 0; i < locationsList.size(); i++) {
+            includeName = (PHPIdentifierLocation) locationsList.get(i);
+            if (exactIncludeSet.contains(includeName.getFilename())) {
+              includeName.setMatch(PHPIdentifierLocation.EXACT_MATCH);
+            } else {
+              includeName.setMatch(PHPIdentifierLocation.UNDEFINED_MATCH);
+            }
+          }
+          Collections.sort(locationsList);
+
+          ListSelectionDialog listSelectionDialog = new ListSelectionDialog(PHPeclipsePlugin.getDefault().getWorkbench()
+              .getActiveWorkbenchWindow().getShell(), locationsList, new ListContentProvider(), new LabelProvider(),
+              "Select the resources to open.");
+          listSelectionDialog.setTitle("Multiple declarations found");
+          if (listSelectionDialog.open() == Window.OK) {
+            Object[] locations = listSelectionDialog.getResult();
+            if (locations != null) {
+              try {
+                for (int i = 0; i < locations.length; i++) {
+                  PHPIdentifierLocation location = (PHPIdentifierLocation) locations[i];
+                  String filename = workspaceLocation + location.getFilename();
+                  //                                   System.out.println(filename);
+                  if (location.getOffset() >= 0) {
+                    PHPeclipsePlugin.getDefault().openFileAndGotoOffset(filename, location.getOffset(), identiifer.length());
+                  } else {
+                    PHPeclipsePlugin.getDefault().openFileAndFindString(filename, identiifer);
                   }
-                } catch (CoreException e) {
-                  // TODO Auto-generated catch block
-                  e.printStackTrace();
                 }
+              } catch (CoreException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
               }
             }
-          } else {
-            try {
-              PHPIdentifierLocation location = (PHPIdentifierLocation) locationsList
-                  .get(0);
-              String filename = workspaceLocation + location.getFilename();
-              //                                       System.out.println(filename);
-              if (location.getOffset() >= 0) {
-                PHPeclipsePlugin.getDefault().openFileAndGotoOffset(filename,
-                    location.getOffset(), word.length());
-              } else {
-                PHPeclipsePlugin.getDefault().openFileAndFindString(filename,
-                    word);
-              }
-            } catch (CoreException e) {
-              // TODO Auto-generated catch block
-              e.printStackTrace();
+          }
+        } else {
+          try {
+            PHPIdentifierLocation location = (PHPIdentifierLocation) locationsList.get(0);
+            String filename = workspaceLocation + location.getFilename();
+            //                                 System.out.println(filename);
+            if (location.getOffset() >= 0) {
+              PHPeclipsePlugin.getDefault().openFileAndGotoOffset(filename, location.getOffset(), identiifer.length());
+            } else {
+              PHPeclipsePlugin.getDefault().openFileAndFindString(filename, identiifer);
             }
+          } catch (CoreException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
           }
         }
       }
@@ -226,8 +231,54 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements
     }
   }
 
-  private String getPHPIdentifier(IDocument doc, int pos) {
-    Point word = PHPWordExtractor.findWord(doc, pos);
+  private String getIdentifierOrInclude(IDocument doc, int pos) {
+    //    private String getPHPIncludeText(IDocument doc, int pos) {
+    Point word = null;
+    int start = -1;
+    int end = -1;
+    isIncludeString = false;
+    try {
+      //    try to find an include string
+      int position = pos;
+      char character = ' ';
+
+      while (position >= 0) {
+        character = doc.getChar(position);
+        if ((character == '\"') || (character == '\'') || (character == '\r') || (character == '\n'))
+          break;
+        --position;
+      }
+      if ((character == '\"') || (character == '\'')) {
+        start = position;
+
+        position = pos;
+        int length = doc.getLength();
+        character = ' ';
+        while (position < length) {
+          character = doc.getChar(position);
+          if ((character == '\"') || (character == '\'') || (character == '\r') || (character == '\n'))
+            break;
+          ++position;
+        }
+        if ((character == '\"') || (character == '\'')) {
+          start++;
+          end = position;
+
+          if (end > start) {
+            word = new Point(start, end - start); // include name found
+            isIncludeString = true;
+          }
+        }
+      }
+
+      // try to find an identifier
+      if (word == null) {
+        word = PHPWordExtractor.findWord(doc, pos); // identifier found
+        isIncludeString = false;
+      }
+    } catch (BadLocationException x) {
+    }
+
     if (word != null) {
       try {
         return doc.get(word.x, word.y);
@@ -236,4 +287,47 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements
     }
     return "";
   }
+
+  //    
+  //    
+  //    Point word = PHPWordExtractor.findWord(doc, pos);
+  //    if (word != null) {
+  //      try {
+  //        return doc.get(word.x, word.y);
+  //      } catch (BadLocationException e) {
+  //      }
+  //    }
+  //    return "";
+  //  }
+  private IContainer getWorkingLocation(IFileEditorInput editorInput) {
+    if (editorInput == null || editorInput.getFile() == null) {
+      return null;
+    }
+    return editorInput.getFile().getParent();
+  }
+
+  private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
+    IContainer container = getWorkingLocation(editorInput);
+    String fullPath = project.getLocation().toString();
+    IFile file = null;
+    if (relativeFilename.startsWith("../")) {
+      Path path = new Path(relativeFilename);
+      file = container.getFile(path);
+      return file;
+    }
+    int index = relativeFilename.lastIndexOf('/');
+
+    if (index >= 0) {
+      Path path = new Path(relativeFilename);
+      file = project.getFile(path);
+      if (file.exists()) {
+        return file;
+      }
+    }
+
+    Path path = new Path(relativeFilename);
+    file = container.getFile(path);
+
+    return file;
+  }
 }
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenIncludeEditorAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenIncludeEditorAction.java
deleted file mode 100644 (file)
index 12aa5c6..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Common Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/cpl-v10.html
- * 
- * Contributors: www.phpeclipse.de
- ******************************************************************************/
-package net.sourceforge.phpeclipse.actions;
-
-import java.io.File;
-import java.util.List;
-
-import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
-import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.ui.IEditorActionDelegate;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.actions.ActionDelegate;
-import org.eclipse.ui.dialogs.ListSelectionDialog;
-import org.eclipse.ui.internal.dialogs.ListContentProvider;
-
-public class PHPOpenIncludeEditorAction extends ActionDelegate implements IEditorActionDelegate {
-
-  private IWorkbenchWindow fWindow;
-  private PHPEditor fEditor;
-  private IProject fProject;
-
-  public void dispose() {
-  }
-
-  public void init(IWorkbenchWindow window) {
-    this.fWindow = window;
-  }
-
-  public void selectionChanged(IAction action, ISelection selection) {
-    if (!selection.isEmpty()) {
-      if (selection instanceof TextSelection) {
-        action.setEnabled(true);
-      } else if (fWindow.getActivePage() != null && fWindow.getActivePage().getActivePart() != null) {
-        //
-      }
-    }
-  }
-  private IWorkbenchPage getActivePage() {
-    IWorkbenchWindow workbenchWindow = fEditor.getEditorSite().getWorkbenchWindow();
-    IWorkbenchPage page = workbenchWindow.getActivePage();
-    return page;
-  }
-  public IContainer getWorkingLocation(IFileEditorInput editorInput) {
-    if (editorInput == null || editorInput.getFile() == null) {
-      return null;
-    }
-    return editorInput.getFile().getParent();
-  }
-  private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
-    IContainer container = getWorkingLocation(editorInput);
-    String fullPath = project.getLocation().toString();
-    IFile file = null;
-    if (relativeFilename.startsWith("../")) {
-      Path path = new Path(relativeFilename);
-         file = container.getFile(path);
-         return file;
-    }
-    int index = relativeFilename.lastIndexOf('/');
-    
-    if (index >= 0) {
-      Path path = new Path(relativeFilename);
-      file = project.getFile(path);
-      if (file.exists()) {
-           return file;
-         }
-    } 
-    
-       Path path = new Path(relativeFilename);
-       file = container.getFile(path);
-    
-    return file;
-  }
-
-  public void run(IAction action) {
-    if (fEditor == null) {
-      IEditorPart targetEditor = fWindow.getActivePage().getActiveEditor();
-      if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
-        fEditor = (PHPEditor) targetEditor;
-      }
-    }
-    if (fEditor != null) {
-      // determine the current Project from a (file-based) Editor
-      IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile();
-      fProject = f.getProject();
-      //      System.out.println(fProject.toString());
-
-      ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
-      IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
-      int pos = selection.getOffset();
-      //  System.out.println(selection.getText());
-      String filename = getPHPIncludeText(doc, pos);
-      //      System.out.println(word);
-      if (filename != null && !filename.equals("")) {
-        try {
-          IFile file = getIncludeFile(fProject, (IFileEditorInput) fEditor.getEditorInput(), filename);
-          if (file != null && file.exists()) {
-            PHPeclipsePlugin.getDefault().openFileInTextEditor(file.getLocation().toString());
-            return;
-          }
-        } catch (Exception e) {
-          // ignore
-        }
-
-        try {
-
-          IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
-          //            filename = StringUtil.replaceRegExChars(filename);
-          List list = indexManager.getFileList(filename);
-          if (list != null && list.size() > 0) { 
-            //String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
-            String workspaceLocation = fProject.getLocation().toString()+File.separatorChar;
-            
-            ListSelectionDialog listSelectionDialog = new ListSelectionDialog(PHPeclipsePlugin.getDefault().getWorkbench()
-                .getActiveWorkbenchWindow().getShell(), list, new ListContentProvider(), new LabelProvider(),
-                "Select the includes to open.");
-            listSelectionDialog.setTitle("Multiple includes found");
-            if (listSelectionDialog.open() == Window.OK) {
-              Object[] locations = listSelectionDialog.getResult();
-              if (locations != null) {
-                try {
-                  for (int i = 0; i < locations.length; i++) {
-                    //                    PHPIdentifierLocation location = (PHPIdentifierLocation)
-                    // locations[i];
-                    String openFilename = workspaceLocation + ((String) locations[i]);
-                    PHPeclipsePlugin.getDefault().openFileInTextEditor(openFilename);
-                  }
-                } catch (CoreException e) {
-                  // TODO Auto-generated catch block
-                  e.printStackTrace();
-                }
-              }
-            }
-
-          }
-        } catch (Exception e) {
-        }
-
-      }
-    }
-  }
-
-  public void setActiveEditor(IAction action, IEditorPart targetEditor) {
-    if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
-      fEditor = (PHPEditor) targetEditor;
-    }
-  }
-
-  private String getPHPIncludeText(IDocument doc, int pos) {
-    Point word = null;
-    int start = -1;
-    int end = -1;
-
-    try {
-
-      int position = pos;
-      char character;
-
-      while (position >= 0) {
-        character = doc.getChar(position);
-        if ((character == '\"') || (character == '\'') || (character == '\r') || (character == '\n'))
-          break;
-        --position;
-      }
-
-      start = position;
-
-      position = pos;
-      int length = doc.getLength();
-
-      while (position < length) {
-        character = doc.getChar(position);
-        if ((character == '\"') || (character == '\'') || (character == '\r') || (character == '\n'))
-          break;
-        ++position;
-      }
-
-      start++;
-      end = position;
-
-      if (end > start)
-        word = new Point(start, end - start);
-
-    } catch (BadLocationException x) {
-    }
-
-    if (word != null) {
-      try {
-        return doc.get(word.x, word.y);
-      } catch (BadLocationException e) {
-      }
-    }
-    return "";
-  }
-}
\ No newline at end of file
index ce10dac..8c1a460 100644 (file)
@@ -13,6 +13,9 @@ package net.sourceforge.phpeclipse.internal.compiler.ast;
 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
 import net.sourceforge.phpdt.internal.compiler.lookup.CompilationUnitScope;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+
 public class ImportReference extends ASTNode {
        
 //     public char[][] tokens;
@@ -22,7 +25,8 @@ public class ImportReference extends ASTNode {
        public int declarationEnd;// doesn't include an potential trailing comment
        public int declarationSourceStart;
        public int declarationSourceEnd;
-       public boolean used;
+       public boolean used; 
+       private IFile fFile;
 
 public ImportReference(char[] sourceString, int start, int end, boolean d) { // char[][] sources , long[] poss , boolean d) {
 //     tokens = sources ;
@@ -31,6 +35,7 @@ public ImportReference(char[] sourceString, int start, int end, boolean d) { //
        onDemand = d;
        sourceEnd = end;//(int)(sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
        sourceStart = start;//(int)(sourcePositions[0]>>>32) ;
+       fFile = null;
 }
 /**
  * @return char[][]
@@ -65,4 +70,16 @@ public void traverse(IAbstractSyntaxTreeVisitor visitor, CompilationUnitScope sc
        visitor.visit(this, scope);
        visitor.endVisit(this, scope);
 }
+/**
+ * @return Returns the filePath.
+ */
+public IFile getFile() {
+  return fFile;
+}
+/**
+ * @param filePath The filePath to set.
+ */
+public void setFile(IFile filePath) {
+  fFile = filePath;
+}
 }