aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-08-28 01:42:37 (EDT)
committerzzhongwei2012-08-28 01:42:37 (EDT)
commitcfc21613c40ba0cf9622517fd465e3ab9d9c8fa8 (patch)
tree38ebea47a43d4006daaa26f3c4a51d98062e56f1
parent6e1098a870c7bb86288f8f0eb6da0fc65fceaa72 (diff)
downloadorg.eclipse.pdt-cfc21613c40ba0cf9622517fd465e3ab9d9c8fa8.zip
org.eclipse.pdt-cfc21613c40ba0cf9622517fd465e3ab9d9c8fa8.tar.gz
org.eclipse.pdt-cfc21613c40ba0cf9622517fd465e3ab9d9c8fa8.tar.bz2
388156: Add 'as' and 'insteadof' options for CA for traits
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388156 388155: No Content Assist for use trait if there is php comment before it https://bugs.eclipse.org/bugs/show_bug.cgi?id=388155
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/AbstractCompletionContext.java31
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java3
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitKeywordStrategy.java77
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt36
4 files changed, 146 insertions, 1 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/AbstractCompletionContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/AbstractCompletionContext.java
index e54efa4..7d59297 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/AbstractCompletionContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/AbstractCompletionContext.java
@@ -47,6 +47,7 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
public static final int NONE = 0;
public static final int TRAIT_NAME = 1;
+ public static final int TRAIT_KEYWORD = 2;
private CompletionCompanion companion;
private CompletionRequestor requestor;
private ISourceModule sourceModule;
@@ -734,7 +735,12 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
if (startTokenRegion.getStart() == 0) {
return NONE;
}
- types.add(startTokenRegion.getType());
+ if (startTokenRegion.getType() != PHPRegionTypes.PHP_LINE_COMMENT
+ && startTokenRegion.getType() != PHPRegionTypes.PHP_COMMENT
+ && startTokenRegion.getType() != PHPRegionTypes.WHITESPACE
+ && !startTokenRegion.getType().startsWith("PHPDOC")) {
+ types.add(startTokenRegion.getType());
+ }
if (startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_OPEN
|| startTokenRegion.getType() == PHPRegionTypes.PHP_INSTEADOF
|| startTokenRegion.getType() == PHPRegionTypes.PHP_SEMICOLON
@@ -755,16 +761,39 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
|| type == PHPRegionTypes.PHP_INSTEADOF
|| type == PHPRegionTypes.PHP_SEMICOLON) {
return TRAIT_NAME;
+ } else if (type == PHPRegionTypes.PHP_AS) {
+ return TRAIT_KEYWORD;
+ }
+ if (type == PHPRegionTypes.PHP_INSTEADOF) {
+ return TRAIT_KEYWORD;
}
} else if (types.size() == 2) {
String type1 = types.get(0);
String type = types.get(1);
+ try {
+ if (type == PHPRegionTypes.PHP_SEMICOLON
+ && type1 == PHPRegionTypes.PHP_STRING
+ && Character.isWhitespace(document.getChar(offset - 1))) {
+
+ return TRAIT_KEYWORD;
+ }
+ } catch (BadLocationException e) {
+ }
if (type == PHPRegionTypes.PHP_CURLY_OPEN
|| type == PHPRegionTypes.PHP_INSTEADOF
|| type == PHPRegionTypes.PHP_SEMICOLON
|| type1 == PHPRegionTypes.PHP_STRING) {
return TRAIT_NAME;
}
+ } else if (types.size() == 3) {
+ String type = types.get(0);
+ String type1 = types.get(1);
+ String type2 = types.get(2);
+ if (type == PHPRegionTypes.PHP_STRING
+ && type1 == PHPRegionTypes.PHP_STRING
+ && type2 == PHPRegionTypes.PHP_SEMICOLON) {
+ return TRAIT_KEYWORD;
+ }
}
return NONE;
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java
index 0af4f82..c8518e0 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java
@@ -157,6 +157,9 @@ public class CompletionStrategyFactory implements ICompletionStrategyFactory {
if (type == AbstractCompletionContext.TRAIT_NAME) {
return new ICompletionStrategy[] { new InUseTraitStrategy(
context) };
+ } else if (type == AbstractCompletionContext.TRAIT_KEYWORD) {
+ return new ICompletionStrategy[] { new InUseTraitKeywordStrategy(
+ context) };
} else {
return new ICompletionStrategy[] {};
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitKeywordStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitKeywordStrategy.java
new file mode 100644
index 0000000..4846692
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitKeywordStrategy.java
@@ -0,0 +1,77 @@
+package org.eclipse.php.internal.core.codeassist.strategies;
+
+import org.eclipse.dltk.internal.core.SourceRange;
+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.PHPVersion;
+import org.eclipse.php.internal.core.codeassist.ICompletionReporter;
+import org.eclipse.php.internal.core.codeassist.contexts.ClassStatementContext;
+import org.eclipse.php.internal.core.language.keywords.PHPKeywords.KeywordData;
+
+public class InUseTraitKeywordStrategy extends KeywordsStrategy {
+
+ // private static final String CALLABLE = "callable";
+ public static final String[] KEYWORDS = { "as", "insteadof" };
+
+ /**
+ * @param context
+ * @param elementFilter
+ */
+ public InUseTraitKeywordStrategy(ICompletionContext context,
+ IElementFilter elementFilter) {
+ super(context, elementFilter);
+ }
+
+ /**
+ * @param context
+ */
+ public InUseTraitKeywordStrategy(ICompletionContext context) {
+ super(context);
+ }
+
+ public void apply(ICompletionReporter reporter) throws BadLocationException {
+
+ ClassStatementContext context = (ClassStatementContext) getContext();
+ String prefix = context.getPrefix();
+ String suffix = "";
+ SourceRange replaceRange = getReplacementRange(context);
+ // if (context.getEnclosingType() != null) {
+ // try {
+ // int flags = context.getEnclosingType().getFlags();
+ // if (!PHPFlags.isNamespace(flags)) {
+ // for (String keyword : KEYWORDS) {
+ // if (keyword.startsWith(prefix)) {
+ // reporter.reportKeyword(keyword, suffix,
+ // replaceRange);
+ // }
+ // }
+ // }
+ // } catch (ModelException e) {
+ // PHPCorePlugin.log(e);
+ // }
+ // }
+
+ PHPVersion phpVersion = context.getPhpVersion();
+ if (phpVersion.isGreaterThan(PHPVersion.PHP5_3)) {
+ for (String keyword : KEYWORDS) {
+ if (keyword.startsWith(prefix)) {
+ reporter.reportKeyword(keyword, suffix, replaceRange);
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.php.internal.core.codeassist.strategies.KeywordsStrategy#
+ * filterKeyword
+ * (org.eclipse.php.internal.core.language.keywords.PHPKeywords.KeywordData)
+ */
+ @Override
+ protected boolean filterKeyword(KeywordData keyword) {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt
new file mode 100644
index 0000000..30a6034
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt
@@ -0,0 +1,36 @@
+--TEST--
+Test trait method conflict resolution 8
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+trait A {
+ public function smallTalk() {
+ echo 'a';
+ }
+ public function bigTalk() {
+ echo 'A';
+ }
+}
+
+trait B {
+ public function smallTalk() {
+ echo 'b';
+ }
+ public function bigTalk() {
+ echo 'B';
+ }
+}
+class Aliased_Talker {
+ use A, B {
+ B::smallTalk insteadof A;
+ A::bigTalk insteadof B;//test
+ B::bigTalk |;
+ }
+}
+$o= new Aliased_Talker();
+$o->|
+?>
+--EXPECT---
+keyword(as)-
+keyword(insteadof) \ No newline at end of file