X-Git-Url: http://secure.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationEngine.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationEngine.java
index fa9aba0..56274cd 100644
--- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationEngine.java
+++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationEngine.java
@@ -8,13 +8,17 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.SortedMap;
-import net.sourceforge.phpdt.internal.corext.template.ContextType;
+import net.sourceforge.phpdt.core.ICompilationUnit;
+import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
-import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
+import net.sourceforge.phpdt.internal.corext.template.php.JavaContext;
+import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
@@ -26,20 +30,32 @@ import org.eclipse.swt.graphics.Point;
public class DeclarationEngine {
/** The context type. */
- private ContextType fContextType;
+ private JavaContextType fContextType;
/** The result proposals. */
private ArrayList fProposals = new ArrayList();
- /** Use only methods or variables inside a class*/
- private boolean fUseClassEntries;
+ /** Token determines last which declarations are allowed for proposal */
+ private int fLastSignificantToken;
+
+ private IProject fProject;
+ private IFile fFile;
+// private String fFileName;
/**
* Creates the template engine for a particular context type.
* See TemplateContext
for supported context types.
*/
- public DeclarationEngine(ContextType contextType, boolean useClassEntries) {
+ public DeclarationEngine(IProject project, JavaContextType contextType, int lastSignificantToken, IFile file) {
// Assert.isNotNull(contextType);
+ fProject = project;
fContextType = contextType;
- fUseClassEntries = useClassEntries;
+
+ fLastSignificantToken = lastSignificantToken;
+ fFile = file;
+// if (fFile != null) {
+// fFileName = fFile.getFullPath().toString();
+// } else {
+// fFileName = "";
+// }
}
/**
@@ -66,16 +82,17 @@ public class DeclarationEngine {
* @param completionPosition the context position in the document of the text viewer
* @param compilationUnit the compilation unit (may be null
)
*/
- public void complete(ITextViewer viewer, int completionPosition, SortedMap map) {
+ public void complete(ITextViewer viewer, int completionPosition, SortedMap map, ICompilationUnit compilationUnit) {
IDocument document = viewer.getDocument();
if (!(fContextType instanceof CompilationUnitContextType))
return;
Point selection = viewer.getSelectedRange();
+
// remember selected text
String selectedText = null;
-
+
if (selection.y != 0) {
try {
selectedText = document.get(selection.x, selection.y);
@@ -83,14 +100,17 @@ public class DeclarationEngine {
}
}
- ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);
+// ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);
+
+// CompilationUnitContext context = (CompilationUnitContext) fContextType.createContext();
+ JavaContext context = (JavaContext) fContextType.createContext(document, completionPosition,selection.y,compilationUnit);
+ context.setVariable("selection", selectedText); //$NON-NLS-1$
- PHPUnitContext context = (PHPUnitContext) fContextType.createContext();
int start = context.getStart();
int end = context.getEnd();
String prefix = context.getKey();
IRegion region = new Region(start, end - start);
-
+
String identifier = null;
SortedMap subMap = map.subMap(prefix, prefix + '\255');
@@ -105,19 +125,40 @@ public class DeclarationEngine {
for (int i = 0; i < list.size(); i++) {
location = (PHPIdentifierLocation) list.get(i);
int type = location.getType();
- if (fUseClassEntries) {
- if (type != PHPIdentifierLocation.METHOD && type != PHPIdentifierLocation.VARIABLE) {
- continue; // for loop
- }
- } else {
- if (type == PHPIdentifierLocation.METHOD || type == PHPIdentifierLocation.VARIABLE) {
- continue; // for loop
- }
+ switch (fLastSignificantToken) {
+ case ITerminalSymbols.TokenNameMINUS_GREATER :
+ if (type != PHPIdentifierLocation.METHOD && type != PHPIdentifierLocation.VARIABLE) {
+ continue; // for loop
+ }
+ break;
+ case ITerminalSymbols.TokenNameVariable :
+ if (type != PHPIdentifierLocation.METHOD && type != PHPIdentifierLocation.VARIABLE) {
+ continue; // for loop
+ }
+ break;
+ case ITerminalSymbols.TokenNamethis_PHP_COMPLETION:
+ if (type != PHPIdentifierLocation.METHOD && type != PHPIdentifierLocation.VARIABLE) {
+ continue; // for loop
+ }
+ // check all filenames of the subclasses
+// if (!fFileName.equals(location.getFilename())) {
+// continue; // for loop
+// }
+ break;
+ case ITerminalSymbols.TokenNamenew :
+ if (type != PHPIdentifierLocation.CLASS && type != PHPIdentifierLocation.CONSTRUCTOR) {
+ continue; // for loop
+ }
+ break;
+ default :
+ if (type == PHPIdentifierLocation.METHOD || type == PHPIdentifierLocation.CONSTRUCTOR || type == PHPIdentifierLocation.VARIABLE) {
+ continue; // for loop
+ }
}
if (maxProposals-- < 0) {
return;
}
- fProposals.add(new DeclarationProposal(identifier, location, context, region, viewer));
+ fProposals.add( new DeclarationProposal(fProject, identifier, location, context, region, viewer));
}
}
}