aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-08-01 22:54:03 (EDT)
committerzzhongwei2012-08-01 22:54:03 (EDT)
commit68b32c7edc356ca79783fd006d96a6bd2343cc3a (patch)
tree659b1ada7068525b82822965ff988927ce0c38fa
parent4fb252a0a4b98730e7cf2595828f70df1ee6bcc1 (diff)
downloadorg.eclipse.pdt-68b32c7edc356ca79783fd006d96a6bd2343cc3a.zip
org.eclipse.pdt-68b32c7edc356ca79783fd006d96a6bd2343cc3a.tar.gz
org.eclipse.pdt-68b32c7edc356ca79783fd006d96a6bd2343cc3a.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/CodeAssistUtils.java50
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CompletionCompanion.java31
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/ProposalExtraInfo.java59
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/AbstractCompletionContext.java203
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassMemberContext.java9
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassFieldsStrategy.java4
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMethodsStrategy.java9
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java28
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java12
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java20
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposal.java11
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java11
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java5
13 files changed, 429 insertions, 23 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java
index 8ad8945..8cbeeaf 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java
@@ -390,6 +390,56 @@ public class CodeAssistUtils {
return result.toArray(new IType[result.size()]);
}
+ public static IType[] getTraitsFor(ISourceModule sourceModule,
+ TextSequence statementText, int endPosition, int offset) {
+ PHPVersion phpVersion = ProjectOptions.getPhpVersion(sourceModule
+ .getScriptProject().getProject());
+ if (phpVersion.isLessThan(PHPVersion.PHP5_4)) {
+ return EMPTY_TYPES;
+ }
+ endPosition = PHPTextSequenceUtilities.readBackwardSpaces(
+ statementText, endPosition); // read whitespace
+
+ boolean isClassTriger = false;
+
+ if (endPosition < 2) {
+ return EMPTY_TYPES;
+ }
+
+ String triggerText = statementText.subSequence(endPosition - 2,
+ endPosition).toString();
+ if (triggerText.equals(OBJECT_FUNCTIONS_TRIGGER)) {
+ } else if (triggerText.equals(PAAMAYIM_NEKUDOTAIM)) {
+ isClassTriger = true;
+ } else {
+ return EMPTY_TYPES;
+ }
+
+ int propertyEndPosition = PHPTextSequenceUtilities.readBackwardSpaces(
+ statementText, endPosition - triggerText.length());
+ // int lastObjectOperator = PHPTextSequenceUtilities
+ // .getPrivousTriggerIndex(statementText, propertyEndPosition);
+ // String text = statementText.subSequence(0, propertyEndPosition)
+ // .toString();
+ int classNameStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
+ phpVersion, statementText, propertyEndPosition, true);
+ String className = statementText.subSequence(classNameStart,
+ propertyEndPosition).toString();
+ ModuleDeclaration moduleDeclaration = SourceParserUtil
+ .getModuleDeclaration(sourceModule, null);
+ FileContext context = new FileContext(sourceModule, moduleDeclaration,
+ offset);
+ IEvaluatedType type = PHPClassType.fromTraitName(className,
+ sourceModule, offset);
+ IType[] modelElements = PHPTypeInferenceUtils.getModelElements(type,
+ context, offset);
+ if (modelElements != null) {
+ return modelElements;
+ }
+ return EMPTY_TYPES;
+
+ }
+
/**
* example:(new class1())->avc2()[1][1]->avc1()
*
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CompletionCompanion.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CompletionCompanion.java
index 8a8745d..46602dd 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CompletionCompanion.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CompletionCompanion.java
@@ -73,8 +73,35 @@ public class CompletionCompanion {
triggerEnd = PHPTextSequenceUtilities.readBackwardSpaces(
statementText, triggerEnd);
- rhTypesCache.put(offset, CodeAssistUtils.getTypesFor(aContext
- .getSourceModule(), statementText, triggerEnd, offset));
+ rhTypesCache.put(offset, CodeAssistUtils.getTypesFor(
+ aContext.getSourceModule(), statementText, triggerEnd,
+ offset));
+ }
+ return rhTypesCache.get(offset);
+ }
+
+ public IType[] getLeftHandType(ICompletionContext context, boolean isType) {
+ AbstractCompletionContext aContext = (AbstractCompletionContext) context;
+ int offset = aContext.getOffset();
+ if (!rhTypesCache.containsKey(offset)) {
+
+ TextSequence statementText = aContext.getStatementText();
+ int triggerEnd = PHPTextSequenceUtilities.readBackwardSpaces(
+ statementText, statementText.length());
+ triggerEnd = PHPTextSequenceUtilities.readIdentifierStartIndex(
+ statementText, triggerEnd, true);
+ triggerEnd = PHPTextSequenceUtilities.readBackwardSpaces(
+ statementText, triggerEnd);
+
+ if (isType) {
+ rhTypesCache.put(offset, CodeAssistUtils.getTypesFor(
+ aContext.getSourceModule(), statementText, triggerEnd,
+ offset));
+ } else {
+ rhTypesCache.put(offset, CodeAssistUtils.getTraitsFor(
+ aContext.getSourceModule(), statementText, triggerEnd,
+ offset));
+ }
}
return rhTypesCache.get(offset);
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/ProposalExtraInfo.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/ProposalExtraInfo.java
index 90dea94..ab99711 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/ProposalExtraInfo.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/ProposalExtraInfo.java
@@ -1,8 +1,59 @@
package org.eclipse.php.internal.core.codeassist;
public final class ProposalExtraInfo {
- public static final String TYPE_ONLY = "TYPE_ONLY";
- //the stub is a type of class/method/field,which does not exist yet
- public static final String STUB = "STUB";
- public static final String MAGIC_METHOD = "MAGIC_METHOD";
+ public static final int TYPE_ONLY = 1 << 1;
+ public static final int MAGIC_METHOD = 1 << 2;
+ // this is for namespace
+ public static final int FULL_NAME = 1 << 3;
+ // the stub is a type of class/method/field,which does not exist yet
+ public static final int STUB = 1 << 4;
+ public static final int METHOD_ONLY = 1 << 5;
+
+ public static boolean isTypeOnly(int flags) {
+ return (flags & TYPE_ONLY) != 0;
+ }
+
+ public static boolean isMagicMethod(int flags) {
+ return (flags & MAGIC_METHOD) != 0;
+ }
+
+ public static boolean isFullName(int flags) {
+ return (flags & FULL_NAME) != 0;
+ }
+
+ public static boolean isTypeOnly(Object flags) {
+ if (flags instanceof Integer) {
+ return isTypeOnly(((Integer) flags).intValue());
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean isMethodOnly(Object flags) {
+ if (flags instanceof Integer) {
+ return isMethodOnly(((Integer) flags).intValue());
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean isMethodOnly(int flags) {
+ return (flags & METHOD_ONLY) != 0;
+ }
+
+ public static boolean isMagicMethod(Object flags) {
+ if (flags instanceof Integer) {
+ return isMagicMethod(((Integer) flags).intValue());
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean isFullName(Object flags) {
+ if (flags instanceof Integer) {
+ return isFullName(((Integer) flags).intValue());
+ } else {
+ return false;
+ }
+ }
}
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 76afda5..e54efa4 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
@@ -12,6 +12,8 @@
package org.eclipse.php.internal.core.codeassist.contexts;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@@ -43,6 +45,8 @@ import org.eclipse.wst.sse.core.internal.provisional.text.*;
*/
public abstract class AbstractCompletionContext implements ICompletionContext {
+ public static final int NONE = 0;
+ public static final int TRAIT_NAME = 1;
private CompletionCompanion companion;
private CompletionRequestor requestor;
private ISourceModule sourceModule;
@@ -374,6 +378,11 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
structuredDocumentRegion, true);
}
+ public TextSequence getStatementText(int offset) {
+ return PHPTextSequenceUtilities.getStatement(offset,
+ structuredDocumentRegion, true);
+ }
+
/**
* Returns whether there are whitespace characters before the cursor where
* code assist was being invoked
@@ -670,4 +679,198 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
}
return document.getChar(offset);
}
+
+ public int getUseTraitStatementContext() {
+ return getUseTraitStatementContext(offset, structuredDocumentRegion);
+ }
+
+ public int getUseTraitStatementContext(int offset,
+ IStructuredDocumentRegion sdRegion) {
+ List<String> types = new ArrayList<String>();
+ if (sdRegion == null) {
+ sdRegion = structuredDocumentRegion;
+ }
+ int documentOffset = offset;
+ if (documentOffset == sdRegion.getEndOffset()) {
+ documentOffset -= 1;
+ }
+ ITextRegion tRegion = sdRegion
+ .getRegionAtCharacterOffset(documentOffset);
+
+ ITextRegionCollection container = sdRegion;
+
+ if (tRegion instanceof ITextRegionContainer) {
+ container = (ITextRegionContainer) tRegion;
+ tRegion = container.getRegionAtCharacterOffset(offset);
+ }
+ if (tRegion != null && tRegion.getType() == PHPRegionContext.PHP_CLOSE) {
+ tRegion = container.getRegionAtCharacterOffset(container
+ .getStartOffset() + tRegion.getStart() - 1);
+ }
+
+ // This text region must be of type PhpScriptRegion:
+ if (tRegion != null
+ && tRegion.getType() == PHPRegionContext.PHP_CONTENT) {
+ IPhpScriptRegion phpScriptRegion = (IPhpScriptRegion) tRegion;
+
+ try {
+ // Set default starting position to the beginning of the
+ // PhpScriptRegion:
+ int startOffset = container.getStartOffset()
+ + phpScriptRegion.getStart();
+
+ // Now, search backwards for the statement start (in this
+ // PhpScriptRegion):
+ ITextRegion startTokenRegion;
+ if (documentOffset == startOffset) {
+ startTokenRegion = phpScriptRegion.getPhpToken(0);
+ } else {
+ startTokenRegion = phpScriptRegion.getPhpToken(offset
+ - startOffset - 1);
+ }
+ // If statement start is at the beginning of the PHP script
+ // region:
+ while (true) {
+ if (startTokenRegion.getStart() == 0) {
+ return NONE;
+ }
+ types.add(startTokenRegion.getType());
+ if (startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_OPEN
+ || startTokenRegion.getType() == PHPRegionTypes.PHP_INSTEADOF
+ || startTokenRegion.getType() == PHPRegionTypes.PHP_SEMICOLON
+ || startTokenRegion.getType() == PHPRegionTypes.PHP_AS) {
+ break;
+ }
+
+ startTokenRegion = phpScriptRegion
+ .getPhpToken(startTokenRegion.getStart() - 1);
+ }
+
+ } catch (BadLocationException e) {
+ }
+ }
+ if (types.size() == 1) {
+ String type = types.get(0);
+ if (type == PHPRegionTypes.PHP_CURLY_OPEN
+ || type == PHPRegionTypes.PHP_INSTEADOF
+ || type == PHPRegionTypes.PHP_SEMICOLON) {
+ return TRAIT_NAME;
+ }
+ } else if (types.size() == 2) {
+ String type1 = types.get(0);
+ String type = types.get(1);
+ if (type == PHPRegionTypes.PHP_CURLY_OPEN
+ || type == PHPRegionTypes.PHP_INSTEADOF
+ || type == PHPRegionTypes.PHP_SEMICOLON
+ || type1 == PHPRegionTypes.PHP_STRING) {
+ return TRAIT_NAME;
+ }
+ }
+
+ return NONE;
+ }
+
+ public boolean isInUseTraitStatement() {
+ return isInUseTraitStatement(offset, structuredDocumentRegion);
+ }
+
+ private List<String> useTypes;
+
+ public boolean isInUseTraitStatement(int offset,
+ IStructuredDocumentRegion sdRegion) {
+ PHPVersion phpVersion = ProjectOptions.getPhpVersion(sourceModule
+ .getScriptProject().getProject());
+ if (phpVersion.isLessThan(PHPVersion.PHP5_4)) {
+ return false;
+ }
+ if (useTypes != null) {
+ return true;
+ }
+ if (sdRegion == null) {
+ sdRegion = structuredDocumentRegion;
+ }
+ int documentOffset = offset;
+ if (documentOffset == sdRegion.getEndOffset()) {
+ documentOffset -= 1;
+ }
+ ITextRegion tRegion = sdRegion
+ .getRegionAtCharacterOffset(documentOffset);
+
+ ITextRegionCollection container = sdRegion;
+
+ if (tRegion instanceof ITextRegionContainer) {
+ container = (ITextRegionContainer) tRegion;
+ tRegion = container.getRegionAtCharacterOffset(offset);
+ }
+ if (tRegion != null && tRegion.getType() == PHPRegionContext.PHP_CLOSE) {
+ tRegion = container.getRegionAtCharacterOffset(container
+ .getStartOffset() + tRegion.getStart() - 1);
+ }
+
+ // This text region must be of type PhpScriptRegion:
+ if (tRegion != null
+ && tRegion.getType() == PHPRegionContext.PHP_CONTENT) {
+ IPhpScriptRegion phpScriptRegion = (IPhpScriptRegion) tRegion;
+
+ try {
+ // Set default starting position to the beginning of the
+ // PhpScriptRegion:
+ int startOffset = container.getStartOffset()
+ + phpScriptRegion.getStart();
+
+ // Now, search backwards for the statement start (in this
+ // PhpScriptRegion):
+ ITextRegion startTokenRegion;
+ if (documentOffset == startOffset) {
+ startTokenRegion = phpScriptRegion.getPhpToken(0);
+ } else {
+ startTokenRegion = phpScriptRegion.getPhpToken(offset
+ - startOffset - 1);
+ }
+ // If statement start is at the beginning of the PHP script
+ // region:
+ while (true) {
+ if (startTokenRegion.getStart() == 0) {
+ return false;
+ }
+ if (startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_OPEN) {
+ // Calculate starting position of the statement (it
+ // should go right after this startTokenRegion):
+ // startOffset += startTokenRegion.getEnd();
+ TextSequence statementText1 = getStatementText(startOffset
+ + startTokenRegion.getStart() - 1);
+ startTokenRegion = phpScriptRegion
+ .getPhpToken(startTokenRegion.getStart()
+ - statementText1.length());
+ if (startTokenRegion != null
+ && startTokenRegion.getType() == PHPRegionTypes.PHP_USE) {
+ String[] types = statementText1.toString().trim()
+ .substring(3).trim().split(",");
+ useTypes = new ArrayList<String>();
+ for (String type : types) {
+ useTypes.add(type.trim());
+ }
+ return true;
+ } else {
+ return false;
+ }
+ } else if (startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_CLOSE) {
+ return false;
+ }
+
+ startTokenRegion = phpScriptRegion
+ .getPhpToken(startTokenRegion.getStart() - 1);
+ }
+
+ } catch (BadLocationException e) {
+ }
+ }
+
+ return false;
+ }
+
+ public List<String> getUseTypes() {
+ return useTypes;
+ }
+
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassMemberContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassMemberContext.java
index 27326df..6d1bde0 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassMemberContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassMemberContext.java
@@ -66,6 +66,13 @@ public abstract class ClassMemberContext extends StatementContext {
}
TextSequence statementText = getStatementText();
+ // boolean b = isInUseTraitStatement();
+ // if (b) {
+ // return false;
+ // }
+ // TextSequence statementText1 = getStatementText(statementText
+ // .getOriginalOffset(0) - 2);
+ // statementText1.toString();
int totalLength = statementText.length();
elementStart = PHPTextSequenceUtilities.readBackwardSpaces(
statementText, totalLength);
@@ -88,7 +95,7 @@ public abstract class ClassMemberContext extends StatementContext {
return false;
}
- types = getCompanion().getLeftHandType(this);
+ types = getCompanion().getLeftHandType(this, !isInUseTraitStatement());
return true;
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassFieldsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassFieldsStrategy.java
index 2bd89d3..e7b56e8 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassFieldsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassFieldsStrategy.java
@@ -89,7 +89,9 @@ public class ClassFieldsStrategy extends ClassMembersStrategy {
for (IField field : removeOverriddenElements(Arrays
.asList(fields))) {
- if (!isFiltered(field, type, concreteContext)) {
+ if (concreteContext.isInUseTraitStatement()) {
+ result.add(field);
+ } else if (!isFiltered(field, type, concreteContext)) {
result.add(field);
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMethodsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMethodsStrategy.java
index e8a706b..df2a917 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMethodsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMethodsStrategy.java
@@ -96,7 +96,11 @@ public class ClassMethodsStrategy extends ClassMembersStrategy {
for (IMethod method : removeOverriddenElements(Arrays
.asList(methods))) {
- if ((!isConstructor(method) || inConstructor
+ if (concreteContext.isInUseTraitStatement()) {
+ // result.add(method);
+ reporter.reportMethod((IMethod) method, "",
+ replaceRange, ProposalExtraInfo.METHOD_ONLY);
+ } else if ((!isConstructor(method) || inConstructor
&& isSuperConstructor(method, type, concreteContext))
&& !isFiltered(method, type, concreteContext)) {
if (magicMethods.contains(method.getElementName())) {
@@ -127,8 +131,7 @@ public class ClassMethodsStrategy extends ClassMembersStrategy {
if (concreteContext.getOffset() > construtorRange
.getOffset()
&& concreteContext.getOffset() < construtorRange
- .getOffset()
- + construtorRange.getLength()) {
+ .getOffset() + construtorRange.getLength()) {
return true;
}
}
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 0b77eb3..7e5b434 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
@@ -149,11 +149,22 @@ public class CompletionStrategyFactory implements ICompletionStrategyFactory {
return new ICompletionStrategy[] { new MethodNameStrategy(context) };
}
if (contextClass == ClassStatementContext.class) {
- return new ICompletionStrategy[] {
- new ClassKeywordsStrategy(context),
- new GlobalConstantsStrategy(context),
- // new GlobalTypesStrategy(context)
- };
+ if (((ClassStatementContext) context).isInUseTraitStatement()) {
+ int type = ((ClassStatementContext) context)
+ .getUseTraitStatementContext();
+ if (type == AbstractCompletionContext.TRAIT_NAME) {
+ return new ICompletionStrategy[] { new InUseTraitStrategy(
+ context) };
+ } else {
+ return new ICompletionStrategy[] {};
+ }
+ } else {
+ return new ICompletionStrategy[] {
+ new ClassKeywordsStrategy(context),
+ new GlobalConstantsStrategy(context),
+ // new GlobalTypesStrategy(context)
+ };
+ }
}
if (contextClass == GlobalStatementContext.class) {
return new ICompletionStrategy[] { new GlobalElementsCompositeStrategy(
@@ -178,6 +189,13 @@ public class CompletionStrategyFactory implements ICompletionStrategyFactory {
return new ICompletionStrategy[] { new ExceptionClassInstantiationStrategy(
context) };
}
+ // if (contextClass ==
+ // ClassStaticMemberContext.class&&((ClassStaticMemberContext)context).isInUseTraitStatement())
+ // {
+ // return new ICompletionStrategy[] {
+ // new ClassFieldsStrategy(context),
+ // new ClassMethodsStrategy(context) };
+ // }
if (contextClass == ClassStaticMemberContext.class
|| contextClass == ClassObjMemberContext.class) {
return new ICompletionStrategy[] {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java
index ce2afaa..4dac31b 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java
@@ -155,6 +155,18 @@ public class PHPClassType extends ClassType implements IClassType {
}
}
+ public static PHPClassType fromTraitName(String typeName,
+ ISourceModule sourceModule, int offset) {
+ String namespace = PHPModelUtils.extractNamespaceName(typeName,
+ sourceModule, offset);
+
+ if (namespace != null) {
+ return new PHPTraitType(namespace,
+ PHPModelUtils.extractElementName(typeName));
+ }
+ return new PHPTraitType(typeName);
+ }
+
/**
* Creates evaluated type from the given IType.
*
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java
index 990ebac..5f9fc43 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java
@@ -41,6 +41,8 @@ import org.eclipse.php.internal.core.Logger;
import org.eclipse.php.internal.core.PHPCoreConstants;
import org.eclipse.php.internal.core.PHPCorePlugin;
import org.eclipse.php.internal.core.PHPVersion;
+import org.eclipse.php.internal.core.ast.nodes.Identifier;
+import org.eclipse.php.internal.core.ast.nodes.NamespaceName;
import org.eclipse.php.internal.core.compiler.ast.nodes.*;
import org.eclipse.php.internal.core.compiler.ast.parser.ASTUtils;
import org.eclipse.php.internal.core.compiler.ast.visitor.PHPASTVisitor;
@@ -2190,6 +2192,24 @@ public class PHPModelUtils {
return typeName;
}
+ public static String getFullName(NamespaceName namespaceName) {
+
+ StringBuffer sb = new StringBuffer();
+ if (namespaceName.isGlobal()) {
+ sb.append(NamespaceReference.NAMESPACE_SEPARATOR);
+ }
+ List<Identifier> segments = namespaceName.segments();
+ for (Identifier identifier : segments) {
+ if (sb.length() == 0 && namespaceName.isGlobal()) {
+ sb.append(NamespaceReference.NAMESPACE_SEPARATOR);
+ } else if (sb.length() > 0) {
+ sb.append(NamespaceReference.NAMESPACE_SEPARATOR);
+ }
+ sb.append(identifier.getName());
+ }
+ return sb.toString();
+ }
+
public static String getLineSeparator(IProject project) {
String lineSeparator = null;
if (project != null) {
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposal.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposal.java
index 2abd6af..7ea975f 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposal.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposal.java
@@ -59,7 +59,16 @@ public class PHPCompletionProposal extends ScriptCompletionProposal {
if (word.startsWith("$") && !prefix.startsWith("$")) {
word = word.substring(1);
}
- return isPrefix(prefix, word);
+ boolean result = isPrefix(prefix, word);
+ // int index = word.indexOf(" - ");
+ // if (!result && index >= 0 && prefix.indexOf('\\') >= 0) {
+ // StringBuffer sb = new StringBuffer();
+ // sb.append(word.substring(index + " - ".length()));
+ // sb.append('\\');
+ // sb.append(word.substring(0, index));
+ // result = isPrefix(prefix, sb.toString());
+ // }
+ return result;
}
protected boolean isSmartTrigger(char trigger) {
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java
index 3f8d794..cc47af6 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java
@@ -273,8 +273,7 @@ public class PHPCompletionProposalCollector extends
String defaultResult = EMPTY_STRING;
if (type instanceof AliasType) {
}
- if (ProposalExtraInfo.TYPE_ONLY.equals(typeProposal
- .getExtraInfo())
+ if (ProposalExtraInfo.isTypeOnly(typeProposal.getExtraInfo())
|| !PHPModelUtils.hasStaticOrConstMember(type)) {
return defaultResult;
}
@@ -310,10 +309,10 @@ public class PHPCompletionProposalCollector extends
@Override
public int computeRelevance(CompletionProposal proposal) {
- if (ProposalExtraInfo.STUB.equals(proposal.getExtraInfo())) {
- return Integer.MAX_VALUE;
- }
- if (ProposalExtraInfo.MAGIC_METHOD.equals(proposal.getExtraInfo())) {
+ // if (ProposalExtraInfo.STUB.equals(proposal.getExtraInfo())) {
+ // return Integer.MAX_VALUE;
+ // }
+ if (ProposalExtraInfo.isMagicMethod(proposal.getExtraInfo())) {
return -1;
}
return super.computeRelevance(proposal);
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java
index 0ddf23f..9e7885c 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java
@@ -26,6 +26,7 @@ import org.eclipse.jface.text.link.*;
import org.eclipse.php.internal.core.PHPCoreConstants;
import org.eclipse.php.internal.core.PHPCorePlugin;
import org.eclipse.php.internal.core.codeassist.AliasType;
+import org.eclipse.php.internal.core.codeassist.ProposalExtraInfo;
import org.eclipse.php.internal.core.typeinference.FakeConstructor;
import org.eclipse.php.internal.ui.PHPUiPlugin;
import org.eclipse.php.internal.ui.text.template.contentassist.PositionBasedCompletionProposal;
@@ -227,6 +228,10 @@ public final class ParameterGuessingProposal extends
}
public String getReplacementString() {
+ if (ProposalExtraInfo.isMethodOnly(extraInfo)) {
+ setReplacementString(method.getElementName());
+ return super.getReplacementString();
+ }
boolean fileArgumentNames = Platform.getPreferencesService()
.getBoolean(PHPCorePlugin.ID,
PHPCoreConstants.CODEASSIST_FILL_ARGUMENT_NAMES, true,