aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-08-01 23:01:45 (EDT)
committerzzhongwei2012-08-01 23:01:45 (EDT)
commit783fd5346d4913575a7f6d3407a706ffda6cf5bb (patch)
treebebd46ab7de8f0251325e049df560882748c6f83
parent24cf0482090dff67508aa043b7bf3b920acbd92f (diff)
downloadorg.eclipse.pdt-783fd5346d4913575a7f6d3407a706ffda6cf5bb.zip
org.eclipse.pdt-783fd5346d4913575a7f6d3407a706ffda6cf5bb.tar.gz
org.eclipse.pdt-783fd5346d4913575a7f6d3407a706ffda6cf5bb.tar.bz2
Bug 371051 - [PHP 5.4] Content Assist does not work after keyword
"insteadof"
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitStrategy.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitStrategy.java
new file mode 100644
index 0000000..46b2d76
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitStrategy.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Zend Technologies
+ *******************************************************************************/
+package org.eclipse.php.internal.core.codeassist.strategies;
+
+import java.util.List;
+
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.IType;
+import org.eclipse.dltk.core.SourceParserUtil;
+import org.eclipse.dltk.internal.core.SourceRange;
+import org.eclipse.dltk.ti.types.IEvaluatedType;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.php.core.codeassist.ICompletionContext;
+import org.eclipse.php.core.codeassist.IElementFilter;
+import org.eclipse.php.internal.core.codeassist.ICompletionReporter;
+import org.eclipse.php.internal.core.codeassist.ProposalExtraInfo;
+import org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext;
+import org.eclipse.php.internal.core.typeinference.PHPClassType;
+import org.eclipse.php.internal.core.typeinference.PHPTypeInferenceUtils;
+import org.eclipse.php.internal.core.typeinference.context.FileContext;
+
+/**
+ * This strategy completes builtin array keys, like in _SERVER.
+ *
+ * @author michael
+ */
+public class InUseTraitStrategy extends AbstractCompletionStrategy {
+
+ public InUseTraitStrategy(ICompletionContext context,
+ IElementFilter elementFilter) {
+ super(context, elementFilter);
+ }
+
+ public InUseTraitStrategy(ICompletionContext context) {
+ super(context);
+ }
+
+ public void apply(ICompletionReporter reporter) throws BadLocationException {
+ ICompletionContext context = getContext();
+ if (!(context instanceof AbstractCompletionContext)) {
+ return;
+ }
+
+ AbstractCompletionContext abstractContext = (AbstractCompletionContext) context;
+ int offset = abstractContext.getOffset();
+ ISourceModule sourceModule = abstractContext.getSourceModule();
+ List<String> useTypes = abstractContext.getUseTypes();
+ String prefix = abstractContext.getPrefix();
+ ModuleDeclaration moduleDeclaration = SourceParserUtil
+ .getModuleDeclaration(sourceModule, null);
+ FileContext fileContext = new FileContext(sourceModule,
+ moduleDeclaration, offset);
+ SourceRange replacementRange = getReplacementRange(abstractContext);
+ for (String useType : useTypes) {
+ if (useType.trim().startsWith(prefix)) {
+
+ IEvaluatedType type = PHPClassType.fromTraitName(useType,
+ sourceModule, offset);
+ IType[] modelElements = PHPTypeInferenceUtils.getModelElements(
+ type, fileContext, offset);
+ if (modelElements != null) {
+ for (IType typeElement : modelElements) {
+ reporter.reportType(typeElement, "", replacementRange,
+ ProposalExtraInfo.TYPE_ONLY);
+ }
+ }
+ }
+ }
+
+ }
+
+ public SourceRange getReplacementRange(ICompletionContext context)
+ throws BadLocationException {
+ SourceRange replacementRange = super.getReplacementRange(context);
+ boolean insertMode = isInsertMode();
+ if (replacementRange.getLength() > 0 && insertMode) {
+ return new SourceRange(replacementRange.getOffset(),
+ replacementRange.getLength() - 1);
+ }
+ return replacementRange;
+ }
+}