import java.util.Iterator;
import java.util.SortedMap;
+import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
import net.sourceforge.phpdt.internal.corext.template.ContextType;
import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
private ContextType fContextType;
/** The result proposals. */
private ArrayList fProposals = new ArrayList();
+ /** Token determines last which declarations are allowed for proposal */
+ private int fLastSignificantToken;
+
+ private IFile fFile;
+ private String fFileName;
/**
* Creates the template engine for a particular context type.
* See <code>TemplateContext</code> for supported context types.
*/
- public DeclarationEngine(ContextType contextType) {
+ public DeclarationEngine(ContextType contextType, int lastSignificantToken, IFile file) {
// Assert.isNotNull(contextType);
fContextType = contextType;
+
+ fLastSignificantToken = lastSignificantToken;
+ fFile = file;
+ if (fFile != null) {
+ fFileName = fFile.getFullPath().toString();
+ } else {
+ fFileName = "";
+ }
}
/**
* @param completionPosition the context position in the document of the text viewer
* @param compilationUnit the compilation unit (may be <code>null</code>)
*/
- public void complete(ITextViewer viewer, int completionPosition, SortedMap map)
- //,ICompilationUnit compilationUnit)
- //hrows JavaModelException
- {
+ public void complete(ITextViewer viewer, int completionPosition, SortedMap map) {
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);
}
}
- ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y); //mpilationUnit);
+ ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);
PHPUnitContext context = (PHPUnitContext) fContextType.createContext();
int start = context.getStart();
if (context.canEvaluate(identifier)) {
list = (ArrayList) subMap.get(identifier);
for (int i = 0; i < list.size(); i++) {
+ location = (PHPIdentifierLocation) list.get(i);
+ int type = location.getType();
+ switch (fLastSignificantToken) {
+ case ITerminalSymbols.TokenNameMINUS_GREATER :
+ if (type != PHPIdentifierLocation.METHOD && type != PHPIdentifierLocation.VARIABLE) {
+ continue; // for loop
+ }
+ break;
+ case ITerminalSymbols.TokenNamethis :
+ if (type != PHPIdentifierLocation.METHOD && type != PHPIdentifierLocation.VARIABLE) {
+ continue; // for loop
+ }
+ 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, (PHPIdentifierLocation) list.get(i), context, region, viewer));
+ fProposals.add(new DeclarationProposal(identifier, location, context, region, viewer));
}
}
}