From: khartlage Date: Tue, 9 Sep 2003 19:15:37 +0000 (+0000) Subject: Changed "Open PHP Declarartion" action in the PHP editor: X-Git-Url: http://secure.phpeclipse.com Changed "Open PHP Declarartion" action in the PHP editor: - StringLiterals in defines [i.e. define("TESTME", "Teste dies") ] are now also been indexed - Added a ListSelectionDialog(), if more than 1 possible file could be opened. - "Project->Build Project" creates a completly new index file. --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index 2fa5f0b..3391262 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -218,6 +218,8 @@ public class Scanner implements IScanner, ITerminalSymbols { public int getCurrentTokenEndPosition() { return this.currentPosition - 1; } + + public final char[] getCurrentTokenSource() { // Return the token REAL source (aka unicodes are precomputed) @@ -275,6 +277,18 @@ public class Scanner implements IScanner, ITerminalSymbols { public int getCurrentTokenStartPosition() { return this.startPosition; } + + public final char[] getCurrentStringLiteralSource() { + // Return the token REAL source (aka unicodes are precomputed) + + char[] result; + + int length; + System.arraycopy(source, startPosition+1, result = new char[length = currentPosition - startPosition - 2], 0, length); + // } + return result; + } + /* * Search the source position corresponding to the end of a given line number * diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorActon.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorActon.java index babeffc..a84c8bf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorActon.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorActon.java @@ -27,12 +27,16 @@ 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.IWorkbenchWindow; import org.eclipse.ui.actions.ActionDelegate; +import org.eclipse.ui.dialogs.ListSelectionDialog; +import org.eclipse.ui.internal.dialogs.ListContentProvider; public class PHPOpenDeclarationEditorActon extends ActionDelegate implements IEditorActionDelegate { @@ -68,30 +72,58 @@ public class PHPOpenDeclarationEditorActon extends ActionDelegate implements IEd // determine the current Project from a (file-based) Editor IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile(); fProject = f.getProject(); -// System.out.println(fProject.toString()); + // System.out.println(fProject.toString()); ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection(); IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); int pos = selection.getOffset(); String word = getPHPIdentifier(doc, pos); // System.out.println(word); - if (word!=null && ! word.equals("")) { - IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject); - List list = indexManager.getLocations(word); - if (list!=null && list.size()>0) { - String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString(); - // TODO show all entries of the list in a dialog box - // at the moment allways the first entry will be opened - PHPIdentifierLocation location = (PHPIdentifierLocation)list.get(0); - String filename = workspaceLocation + location.getFilename(); -// System.out.println(filename); - try { - PHPeclipsePlugin.getDefault().openFileInTextEditor(filename, 0, word); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (word != null && !word.equals("")) { + IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject); + List list = indexManager.getLocations(word); + if (list != null && list.size() > 0) { + String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString(); + // TODO show all entries of the list in a dialog box + // at the moment always the first entry will be opened + if (list.size() > 1) { + ListSelectionDialog listSelectionDialog = + new ListSelectionDialog( + PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), + list, + 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); + PHPeclipsePlugin.getDefault().openFileInTextEditor(filename, 0, word); + } + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } else { + try { + PHPIdentifierLocation location = (PHPIdentifierLocation) list.get(0); + String filename = workspaceLocation + location.getFilename(); + // System.out.println(filename); + PHPeclipsePlugin.getDefault().openFileInTextEditor(filename, 0, word); + + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - } + } } } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java index dd2672b..365620c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java @@ -98,6 +98,17 @@ public class IdentifierIndexManager { } parseDeclarations(buf, true); } + } else if (fToken == TokenNamedefine) { + getNextToken(); + if (fToken == TokenNameLPAREN) { + getNextToken(); + if (fToken == TokenNameStringLiteral) { + ident = fScanner.getCurrentStringLiteralSource(); + buf.append("\td"); + buf.append(ident); + getNextToken(); + } + } } else if ((fToken == TokenNameLBRACE) || (fToken == TokenNameDOLLAR_LBRACE)) { getNextToken(); counter++; @@ -157,6 +168,17 @@ public class IdentifierIndexManager { parseDeclarations(buf, true); } + } else if (fToken == TokenNamedefine) { + getNextToken(); + if (fToken == TokenNameLPAREN) { + getNextToken(); + if (fToken == TokenNameStringLiteral) { + ident = fScanner.getCurrentStringLiteralSource(); + buf.append("\td"); + buf.append(ident); + getNextToken(); + } + } } else { getNextToken(); } @@ -244,6 +266,10 @@ public class IdentifierIndexManager { classname = identifier; phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CLASS, phpFileName); break; + case 'd' : // define + identifier = token.substring(1); + phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.DEFINE, phpFileName); + break; case 'f' : // function name identifier = token.substring(1); phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.FUNCTION, phpFileName); @@ -386,6 +412,10 @@ public class IdentifierIndexManager { classname = identifier; phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CLASS, phpFileName); break; + case 'd' : // define + identifier = token.substring(1); + phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.DEFINE, phpFileName); + break; case 'f' : // function name identifier = token.substring(1); phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.FUNCTION, phpFileName); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java index f3fb463..0b3f252 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java @@ -57,4 +57,11 @@ public class PHPIdentifierLocation extends PHPIdentifier { fFilename = string; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return super.toString()+fFilename; + } + } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ParserBuilder.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ParserBuilder.java index 4fd5108..d351132 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ParserBuilder.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ParserBuilder.java @@ -1,6 +1,5 @@ package net.sourceforge.phpeclipse.builder; -import java.io.File; import java.util.Map; import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPIdentifier.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPIdentifier.java index 5c59457..05820af 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPIdentifier.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPIdentifier.java @@ -8,17 +8,36 @@ public class PHPIdentifier { public final static int CLASS = 1; public final static int FUNCTION = 2; + public final static int METHOD = 4; public final static int VARIABLE = 3; - public final static int METHOD = 4; + public final static int DEFINE = 5; + private String fIdentifier; private int fType; - private String fIdentifier; public PHPIdentifier(String identifier, int type) { fType = type; fIdentifier = identifier; } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (!(obj instanceof PHPIdentifier)) { + return false; + } + return ((PHPIdentifier) obj).fType == fType && ((PHPIdentifier) obj).fIdentifier.equals(fIdentifier); + } + + public String getIdentifier() { + return fIdentifier; + } + + public int getType() { + return fType; + } + public boolean isClass() { return fType == CLASS; } @@ -31,31 +50,39 @@ public class PHPIdentifier { return fType == VARIABLE; } - public void setType(int fType) { - this.fType = fType; + public boolean isMethod() { + return fType == METHOD; } - public int getType() { - return fType; + public boolean isDefine() { + return fType == DEFINE; } public void setIdentifier(String fIdentifier) { this.fIdentifier = fIdentifier; } - public String getIdentifier() { - return fIdentifier; + public void setType(int fType) { + this.fType = fType; } /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) + * @see java.lang.Object#toString() */ - public boolean equals(Object obj) { - if (!(obj instanceof PHPIdentifier)) { - return false; + public String toString() { + switch (fType) { + case CLASS : + return "class "; + case DEFINE : + return "define "; + case FUNCTION : + return "function "; + case METHOD : + return "method "; + case VARIABLE : + return "variable "; } - return ((PHPIdentifier) obj).fType == fType && - ((PHPIdentifier) obj).fIdentifier.equals(fIdentifier); + return ""; } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java index b091a43..016372d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java @@ -214,7 +214,6 @@ public class PHPContentOutlinePage extends AbstractContentOutlinePage { public OutlineLabelProvider() { fRegistry = PHPeclipsePlugin.getImageDescriptorRegistry(); - ; } /** * The LabelProvider implementation of this