Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDawid Pakuła2018-02-08 05:08:37 -0500
committerDawid Pakula2019-11-04 11:25:49 -0500
commit9f8b9aea5af6f3d91b24a65066617d5a1242ba81 (patch)
tree3e9d02b0587fd7a9f61281a51c6c7215ecff28dc
parent63da89a985f4f10b71cc05a735226dadb929b663 (diff)
downloadorg.eclipse.pdt-9f8b9aea5af6f3d91b24a65066617d5a1242ba81.tar.gz
org.eclipse.pdt-9f8b9aea5af6f3d91b24a65066617d5a1242ba81.tar.xz
org.eclipse.pdt-9f8b9aea5af6f3d91b24a65066617d5a1242ba81.zip
Bug 530721 - Reduce code assist complexity
* Reduce ClassStatementContext#isValid to class body only * Temporary move Trait info calculation * ITextRegion based scope detector with tests * Drop deprecated methods from AbstractCompletionContext Change-Id: I155cf0488902d8e157371d7f7520c16692e8b6dd Signed-off-by: Dawid Pakuła <zulus@w3des.net>
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/CompletionCompanion.java138
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionContext.java1
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionScope.java32
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/PHPCompletionEngine.java1
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/AbstractCompletionContext.java160
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassMemberContext.java6
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassObjMemberContext.java3
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStaticMemberContext.java3
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/CompletionContextResolver.java3
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java (renamed from plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStatementContext.java)70
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/UseStatementContext.java42
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/CompletionScope.java96
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/ScopeParser.java507
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractClassInstantiationStrategy.java33
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractCompletionStrategy.java10
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ArrayStringKeysStrategy.java10
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/BuiltinArrayKeysStrategy.java5
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CatchTypeStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassDeclarationKeywordsStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassFieldsStrategy.java19
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassInstantiationStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMembersStrategy.java21
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMethodsStrategy.java16
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassPropertiesStrategy.java4
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java13
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ConstantsStrategy.java14
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ElementsCompositeStrategy.java10
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ExceptionClassInstantiationStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionArgumentsStrategy.java7
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterKeywordTypeStrategy.java5
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterTypeStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionReturnTypeStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionsStrategy.java6
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GotoStatementStrategy.java3
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitKeywordStrategy.java4
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InUseTraitStrategy.java103
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/IncludeStatementStrategy.java4
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InterfaceDeclarationKeywordsStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/KeywordsStrategy.java6
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategy.java8
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategyForArray.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java5
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodNameStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocParamVariableStrategy.java1
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocVarVariableStrategy.java1
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/TypesStrategy.java27
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseFunctionStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseNameStrategy.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/VariablesStrategy.java10
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java68
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/Symbols.java10
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/PHPPairMatcher.java3
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java9
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/TestUtils.java22
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/CodeAssistTests.java11
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopePdttFile.java107
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopeTests.java271
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/alternate01.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile01.pdtt17
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile02.pdtt18
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile03.pdtt18
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile04.pdtt18
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile05.pdtt21
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile06.pdtt21
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment01.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment02.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment03.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment04.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment05.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment06.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment07.pdtt13
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control01.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control02.pdtt11
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control03.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control04.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control05.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control06.pdtt17
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control07.pdtt17
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control08.pdtt36
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control09.pdtt37
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions01.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions02.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions03.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function01.pdtt13
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function02.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function03.pdtt13
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function04.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface01.pdtt19
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface02.pdtt20
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface03.pdtt19
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile01.pdtt6
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile02.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure01.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure02.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure03.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace01.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace02.pdtt11
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace03.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace04.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace05.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace06.pdtt11
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace07.pdtt12
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace08.pdtt15
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait01.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait02.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait03.pdtt20
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait04.pdtt24
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/use01.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/classConst.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/exceptions01.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use01.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use02.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use03.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use04.pdtt9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use05.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use06.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use07.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use08.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use09.pdtt10
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use10.pdtt10
120 files changed, 2354 insertions, 461 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/CompletionCompanion.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/CompletionCompanion.java
index b18858401..d08632ee0 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/CompletionCompanion.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/CompletionCompanion.java
@@ -21,6 +21,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.dltk.annotations.NonNull;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.compiler.env.IModuleSource;
import org.eclipse.dltk.core.*;
import org.eclipse.dltk.internal.core.hierarchy.TypeHierarchy;
@@ -28,17 +29,18 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.php.core.PHPToolkitUtil;
import org.eclipse.php.core.PHPVersion;
-import org.eclipse.php.core.compiler.ast.nodes.NamespaceReference;
+import org.eclipse.php.core.codeassist.ICompletionScope.Type;
+import org.eclipse.php.core.compiler.ast.nodes.PHPModuleDeclaration;
import org.eclipse.php.core.project.ProjectOptions;
import org.eclipse.php.internal.core.Logger;
import org.eclipse.php.internal.core.codeassist.CodeAssistUtils;
import org.eclipse.php.internal.core.codeassist.IPHPCompletionRequestor;
import org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext;
+import org.eclipse.php.internal.core.codeassist.scope.ScopeParser;
import org.eclipse.php.internal.core.documentModel.parser.PHPRegionContext;
import org.eclipse.php.internal.core.documentModel.parser.regions.IPHPScriptRegion;
import org.eclipse.php.internal.core.documentModel.parser.regions.PHPRegionTypes;
import org.eclipse.php.internal.core.documentModel.partitioner.PHPPartitionTypes;
-import org.eclipse.php.internal.core.format.PHPHeuristicScanner;
import org.eclipse.php.internal.core.util.text.PHPTextSequenceUtilities;
import org.eclipse.php.internal.core.util.text.TextSequence;
import org.eclipse.wst.sse.core.StructuredModelManager;
@@ -73,6 +75,8 @@ public class CompletionCompanion {
private ITextRegionCollection regionCollection;
private IPHPScriptRegion phpScriptRegion;
private String partitionType;
+ private PHPModuleDeclaration phpModuleDeclaration;
+ private ICompletionScope scope;
private static class FakeTypeHierarchy extends TypeHierarchy {
public FakeTypeHierarchy() {
@@ -90,30 +94,29 @@ public class CompletionCompanion {
this.phpVersion = ProjectOptions.getPHPVersion(getSourceModule().getScriptProject().getProject());
try {
this.document = determineDocument(sourceModule, requestor);
- if (this.document != null) {
-
- structuredDocumentRegion = determineStructuredDocumentRegion(document, offset);
- if (structuredDocumentRegion != null) {
-
- regionCollection = determineRegionCollection(document, structuredDocumentRegion, offset);
- if (regionCollection != null) {
-
- phpScriptRegion = determinePHPRegion(document, regionCollection, offset);
- if (phpScriptRegion != null) {
-
- partitionType = determinePartitionType(regionCollection, phpScriptRegion, offset);
- if (partitionType != null) {
- determineNamespace();
- }
-
- }
- }
- }
+ if (this.document == null) {
+ return;
+ }
+ structuredDocumentRegion = determineStructuredDocumentRegion(document, offset);
+ if (structuredDocumentRegion == null) {
+ return;
+ }
+ regionCollection = determineRegionCollection(document, structuredDocumentRegion, offset);
+ if (regionCollection == null) {
+ return;
+ }
+ phpScriptRegion = determinePHPRegion(document, regionCollection, offset);
+ if (phpScriptRegion == null) {
+ return;
+ }
+ partitionType = determinePartitionType(regionCollection, phpScriptRegion, offset);
+ if (partitionType != null) {
+ determineScope();
+ determineNamespace();
}
} catch (ResourceAlreadyExists | IOException | CoreException | BadLocationException e) {
Logger.logException(e);
}
-
}
/**
@@ -347,64 +350,14 @@ public class CompletionCompanion {
return partitionType;
}
- private void determineNamespace() throws BadLocationException {
- int pos = offset;
- if (pos >= document.getLength() - 1) {
- pos = document.getLength() - 1;
- }
+ private void determineNamespace() {
+ ICompletionScope parent = scope.findParent(Type.NAMESPACE);
- PHPHeuristicScanner scanner = new PHPHeuristicScanner(document,
- IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, PHPPartitionTypes.PHP_DEFAULT);
- int token = PHPHeuristicScanner.UNBOUND;
- while (token != PHPHeuristicScanner.NOT_FOUND && pos > 0) {
- token = scanner.previousToken(pos, PHPHeuristicScanner.UNBOUND);
- pos = scanner.getPosition();
- if (token != PHPHeuristicScanner.NOT_FOUND) {
- ITextRegion textRegion = scanner.getTextRegion(pos);
- if (textRegion != null && textRegion.getType() == PHPRegionTypes.PHP_NAMESPACE) {
- int nameStart = scanner.findNonWhitespaceForward(pos, PHPHeuristicScanner.UNBOUND);
- if (!Character.isWhitespace(document.getChar(pos))) {
- continue;
- }
- int nameEnd = nameStart;
- int detectRange = PHPHeuristicScanner.NOT_FOUND;
- char part = document.getChar(nameEnd);
- if (part != PHPHeuristicScanner.LBRACE) {
- StringBuilder name = new StringBuilder();
- while (Character.isJavaIdentifierPart(part) || part == NamespaceReference.NAMESPACE_SEPARATOR) {
- name.append(part);
- nameEnd++;
- part = document.getChar(nameEnd);
- }
- currentNamespaceName = name.toString();
- if (Character.isWhitespace(part)) {
- nameEnd = scanner.findNonWhitespaceForward(nameEnd, PHPHeuristicScanner.UNBOUND);
- if (nameEnd != PHPHeuristicScanner.NOT_FOUND) {
- part = document.getChar(nameEnd);
- }
- }
- if (part == PHPHeuristicScanner.LBRACE) {
- detectRange = nameEnd;
- }
- } else {
- detectRange = nameStart;
- }
- if (detectRange != PHPHeuristicScanner.NOT_FOUND) {
- int close = scanner.findClosingPeer(detectRange, PHPHeuristicScanner.LBRACE,
- PHPHeuristicScanner.RBRACE);
- if (close != PHPHeuristicScanner.NOT_FOUND) {
- currentNamespaceRange = new SourceRange(textRegion.getStart(),
- close - textRegion.getStart());
- }
- }
- break;
- } else if (textRegion instanceof IPHPScriptRegion) {
- pos = textRegion.getStart() - 1;
- }
- }
- }
- if (currentNamespaceRange == null) {
- currentNamespaceRange = new SourceRange(0, document.getLength());
+ if (parent != null) {
+ currentNamespaceName = parent.getName();
+ currentNamespaceRange = parent;
+ } else {
+ currentNamespaceRange = scope.findParent(Type.FILE);
}
}
@@ -519,4 +472,31 @@ public class CompletionCompanion {
public ISourceRange getCurrentNamespaceRange() {
return currentNamespaceRange;
}
+
+ public PHPModuleDeclaration getModuleDeclaration() {
+ if (phpModuleDeclaration == null) {
+ ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(getSourceModule(), null);
+ if (moduleDeclaration instanceof PHPModuleDeclaration) {
+ phpModuleDeclaration = (PHPModuleDeclaration) moduleDeclaration;
+ }
+ }
+
+ return phpModuleDeclaration;
+ }
+
+ private void determineScope() {
+ ScopeParser scopeParser = new ScopeParser(document);
+ scope = scopeParser.parse(offset);
+ }
+
+ @SuppressWarnings("null")
+ @NonNull
+ public ICompletionScope getScope() {
+ if (scope == null) {
+ determineScope();
+ currentNamespaceRange = scope;
+ }
+
+ return scope;
+ }
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionContext.java
index e6ec62843..158a92b9d 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionContext.java
@@ -25,6 +25,7 @@ import org.eclipse.dltk.core.ISourceModule;
* @author michael
*/
public interface ICompletionContext {
+ static final Class<?>[] EMPTY = new Class[0];
/**
* Returns whether this context is applicable for the position in the document
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionScope.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionScope.java
new file mode 100644
index 000000000..34eb6570e
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/codeassist/ICompletionScope.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Dawid Pakuła and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Dawid Pakuła - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.core.codeassist;
+
+import org.eclipse.dltk.core.ISourceRange;
+
+public interface ICompletionScope extends ISourceRange {
+ public static enum Type {
+ FILE, NAMESPACE, TRAIT, INTERFACE, CLASS, TYPE_STATEMENT, FUNCTION, CONST, FIELD, USE, USE_CONST, USE_FUNCTION, USE_GROUP, TRAIT_USE, TRAIT_PRECEDENCE, COMMENT, PHPDOC, HEAD, BLOCK, IF, WHILE, DOWHILE, FOR, FOREACH, SWITCH, CASE, TRY, CATCH, FINALLY
+
+ ;
+ }
+
+ Type getType();
+
+ String getName();
+
+ ICompletionScope getParent();
+
+ ICompletionScope findParent(Type... types);
+
+}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/PHPCompletionEngine.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/PHPCompletionEngine.java
index 1a1c761cc..36be4e0cf 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/PHPCompletionEngine.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/PHPCompletionEngine.java
@@ -377,6 +377,7 @@ public class PHPCompletionEngine extends ScriptCompletionEngine implements IComp
@Override
public void reportType(IType type, String prefix, String suffix, ISourceRange replaceRange, Object extraInfo,
int subRelevance) {
+
if (processedElements.containsKey(type) && processedElements.get(type).getClass() == type.getClass()) {
return;
}
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 066e8cbb9..f08aa4a26 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
@@ -22,7 +22,6 @@ import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.core.*;
import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.codeassist.CompletionCompanion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.compiler.ast.nodes.NamespaceReference;
@@ -39,7 +38,10 @@ import org.eclipse.php.internal.core.documentModel.partitioner.PHPPartitionTypes
import org.eclipse.php.internal.core.format.PHPHeuristicScanner;
import org.eclipse.php.internal.core.util.text.PHPTextSequenceUtilities;
import org.eclipse.php.internal.core.util.text.TextSequence;
-import org.eclipse.wst.sse.core.internal.provisional.text.*;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
/**
* This is an abstract completion context containing all common utilities.
@@ -503,94 +505,6 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
return NONE;
}
- public boolean isInUseTraitStatement() {
- return isInUseTraitStatement(offset, companion.getStructuredDocumentRegion());
- }
-
- private List<String> useTypes;
-
- public boolean isInUseTraitStatement(int offset, IStructuredDocumentRegion sdRegion) {
- if (companion.getPHPVersion().isLessThan(PHPVersion.PHP5_4)) {
- return false;
- }
- if (useTypes != null) {
- return true;
- }
- if (sdRegion == null) {
- sdRegion = companion.getStructuredDocumentRegion();
- }
- 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 = PHPTextSequenceUtilities.getStatement(
- startOffset + startTokenRegion.getStart() - 1, companion.getStructuredDocumentRegion(),
- true);
- startTokenRegion = phpScriptRegion
- .getPHPToken(startTokenRegion.getStart() - statementText1.length());
- if (startTokenRegion.getType() == PHPRegionTypes.PHP_USE) {
- String[] types = statementText1.toString().trim().substring(3).trim().split(","); //$NON-NLS-1$
- useTypes = new ArrayList<>();
- 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;
- }
-
/**
* This method get enclosing type element. It completely ignore statements
* without {
@@ -646,10 +560,6 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
return null;
}
- public List<String> getUseTypes() {
- return useTypes;
- }
-
private void calculateNames() throws BadLocationException {
if (namesCalculated) {
return;
@@ -762,7 +672,7 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
ISourceModule sourceModule = companion.getSourceModule();
final ISourceRange validRange = companion.getCurrentNamespaceRange();
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
try {
int searchEnd = name.indexOf(NamespaceReference.NAMESPACE_SEPARATOR);
String search;
@@ -864,64 +774,4 @@ public abstract class AbstractCompletionContext implements ICompletionContext {
public TextSequence getStatementText() {
return PHPTextSequenceUtilities.getStatement(offset, companion.getStructuredDocumentRegion(), true);
}
-
- @Deprecated
- public final int getOffset() {
- return getCompanion().getOffset();
- }
-
- @Deprecated
- public final ISourceModule getSourceModule() {
- return getCompanion().getSourceModule();
- }
-
- @Deprecated
- public final IStructuredDocument getDocument() {
- return getCompanion().getDocument();
- }
-
- @Deprecated
- public final PHPVersion getPHPVersion() {
- return getCompanion().getPHPVersion();
- }
-
- @Deprecated
- public final IPHPScriptRegion getPHPScriptRegion() {
- return getCompanion().getPHPScriptRegion();
- }
-
- @Deprecated
- public final ITextRegion getPHPToken() throws BadLocationException {
- return getCompanion().getPHPToken();
- }
-
- @Deprecated
- public final ITextRegion getPHPToken(int offset) throws BadLocationException {
- return getCompanion().getPHPToken(offset);
- }
-
- @Deprecated
- public final String getCurrentNamespace() {
- return getCompanion().getCurrentNamespace();
- }
-
- @Deprecated
- public final boolean isGlobalNamespace() {
- return getCompanion().isGlobalNamespace();
- }
-
- @Deprecated
- public final ISourceRange getCurrentNamespaceRange() {
- return getCompanion().getCurrentNamespaceRange();
- }
-
- @Deprecated
- public final String getPartitionType() {
- return getCompanion().getPartitionType();
- }
-
- @Deprecated
- public final IStructuredDocumentRegion getStructuredDocumentRegion() {
- return getCompanion().getStructuredDocumentRegion();
- }
} \ No newline at end of file
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 f22c33882..d2983d994 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
@@ -20,6 +20,7 @@ import java.util.List;
import org.eclipse.dltk.annotations.NonNull;
import org.eclipse.dltk.core.*;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.php.core.codeassist.ICompletionScope.Type;
import org.eclipse.php.core.compiler.PHPFlags;
import org.eclipse.php.internal.core.PHPCorePlugin;
import org.eclipse.php.internal.core.documentModel.parser.regions.IPHPScriptRegion;
@@ -89,7 +90,6 @@ public abstract class ClassMemberContext extends StatementContext {
// characters
return false;
}
-
String triggerText = statementText.subSequence(elementStart - 2, elementStart).toString();
if (triggerText.equals("->")) { //$NON-NLS-1$
triggerType = Trigger.OBJECT;
@@ -115,8 +115,8 @@ public abstract class ClassMemberContext extends StatementContext {
} catch (ModelException e) {
PHPCorePlugin.log(e);
}
-
- tmpTypes.addAll(Arrays.asList(getCompanion().getLeftHandType(this, !isInUseTraitStatement())));
+ tmpTypes.addAll(Arrays.asList(
+ getCompanion().getLeftHandType(this, getCompanion().getScope().findParent(Type.TRAIT_USE) == null)));
types = tmpTypes.toArray(new IType[0]);
return true;
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassObjMemberContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassObjMemberContext.java
index c521ce12a..801f16f6f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassObjMemberContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassObjMemberContext.java
@@ -20,7 +20,6 @@ import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.core.CompletionRequestor;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.dltk.core.IType;
-import org.eclipse.dltk.core.SourceParserUtil;
import org.eclipse.dltk.ti.IContext;
import org.eclipse.dltk.ti.types.IEvaluatedType;
import org.eclipse.php.core.compiler.ast.nodes.NamespaceReference;
@@ -85,7 +84,7 @@ public class ClassObjMemberContext extends ClassMemberContext {
IType[] types = getLhsTypes();
if (ArrayUtils.isNotEmpty(types)) {
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
if (moduleDeclaration != null) {
IContext context = ASTUtils.findContext(sourceModule, moduleDeclaration, offset);
if (context instanceof MethodContext) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStaticMemberContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStaticMemberContext.java
index 81d61ca94..8e8513a0c 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStaticMemberContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStaticMemberContext.java
@@ -19,7 +19,6 @@ import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.core.CompletionRequestor;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.dltk.core.IType;
-import org.eclipse.dltk.core.SourceParserUtil;
import org.eclipse.dltk.ti.IContext;
import org.eclipse.dltk.ti.types.IEvaluatedType;
import org.eclipse.php.core.PHPVersion;
@@ -99,7 +98,7 @@ public class ClassStaticMemberContext extends ClassMemberContext {
if (!isParent || !isSelf) {
IType[] types = getLhsTypes();
if (ArrayUtils.isNotEmpty(types)) {
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
if (moduleDeclaration != null) {
IContext context = ASTUtils.findContext(sourceModule, moduleDeclaration, offset);
if (context instanceof MethodContext) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/CompletionContextResolver.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/CompletionContextResolver.java
index ec5939978..32dbce049 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/CompletionContextResolver.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/CompletionContextResolver.java
@@ -78,7 +78,7 @@ public class CompletionContextResolver implements ICompletionContextResolver {
new PHPDocReturnTagContext(), new PHPDocMagicTagsContext(), new PHPDocTagInnerContext(),
new ArrayKeyContext(), new CatchTypeContext(), new CatchVariableContext(),
new ClassDeclarationKeywordContext(), new ClassExtendsContext(), new ClassImplementsContext(),
- new ClassInstantiationContext(), new ClassObjMemberContext(), new ClassStatementContext(),
+ new ClassInstantiationContext(), new ClassObjMemberContext(), new TypeStatementContext(),
new ClassStaticMemberContext(), new FunctionParameterTypeContext(), new FunctionReturnTypeContext(),
new FunctionParameterValueContext(), new FunctionParameterVariableContext(), new MethodNameContext(),
new GlobalStatementContext(), new GlobalMethodStatementContext(), new InstanceOfContext(),
@@ -101,7 +101,6 @@ public class CompletionContextResolver implements ICompletionContextResolver {
// find correct completion contexts according to known information:
for (ICompletionContext context : contexts) {
context.init(companion);
-
try {
if (context.isValid(sourceModule, offset, requestor)) {
result.add(context);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStatementContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java
index 51eb15798..ec76d1eaa 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/ClassStatementContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java
@@ -14,9 +14,10 @@
package org.eclipse.php.internal.core.codeassist.contexts;
import org.eclipse.dltk.annotations.NonNull;
-import org.eclipse.dltk.core.*;
+import org.eclipse.dltk.core.CompletionRequestor;
+import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.php.core.compiler.PHPFlags;
+import org.eclipse.php.core.codeassist.ICompletionScope;
import org.eclipse.php.internal.core.PHPCorePlugin;
import org.eclipse.php.internal.core.format.PHPHeuristicScanner;
@@ -32,9 +33,19 @@ import org.eclipse.php.internal.core.format.PHPHeuristicScanner;
*
* @author michael
*/
-public final class ClassStatementContext extends AbstractGlobalStatementContext {
+public final class TypeStatementContext extends AbstractGlobalStatementContext {
private boolean isAssignment = false;
+ public enum Type {
+ CLASS, TRAIT, INTERFACE;
+ }
+
+ private Type type;
+
+ public Type getType() {
+ return type;
+ }
+
@Override
public boolean isValid(@NonNull ISourceModule sourceModule, int offset, CompletionRequestor requestor) {
if (!super.isValid(sourceModule, offset, requestor)) {
@@ -43,31 +54,40 @@ public final class ClassStatementContext extends AbstractGlobalStatementContext
// check whether enclosing element is class
try {
- IModelElement enclosingElement = getEnclosingElement();
- while (enclosingElement instanceof IField) {
- enclosingElement = enclosingElement.getParent();
+
+ PHPHeuristicScanner scanner2 = PHPHeuristicScanner.createHeuristicScanner(getCompanion().getDocument(),
+ offset, true);
+ if (!scanner2.isDefaultPartition(offset)) {
+ return false;
}
- if (enclosingElement instanceof IType && !PHPFlags.isNamespace(((IType) enclosingElement).getFlags())) {
- if (isBeforeName(offset, (IType) enclosingElement)) {
- return false;
- }
- if (offset > 0) {
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=495022
- offset--;
- }
- PHPHeuristicScanner scanner = PHPHeuristicScanner.createHeuristicScanner(getCompanion().getDocument(),
- offset, true);
- isAssignment = scanner.scanBackward(offset, ((IType) enclosingElement).getSourceRange().getOffset(),
- '=') > -1;
- return true;
+ ICompletionScope scope = getCompanion().getScope();
+
+ if (scope.getType() == ICompletionScope.Type.FIELD || scope.getType() == ICompletionScope.Type.FUNCTION
+ || scope.getType() == ICompletionScope.Type.TRAIT_USE
+ || scope.getType() == ICompletionScope.Type.TRAIT_PRECEDENCE) {
+ scope = scope.getParent();
}
- if (enclosingElement instanceof IMethod) {
- if (isBeforeName(offset, (IMethod) enclosingElement)) {
- return true;
- }
+ if (scope.getType() != ICompletionScope.Type.BLOCK) {
+ return false;
}
- } catch (ModelException e) {
- PHPCorePlugin.log(e);
+ scope = scope.getParent();
+ switch (scope.getType()) {
+ case CLASS:
+ type = Type.CLASS;
+ break;
+ case INTERFACE:
+ type = Type.INTERFACE;
+ break;
+ case TRAIT:
+ type = Type.TRAIT;
+ break;
+ default:
+ return false;
+ }
+
+ isAssignment = scanner2.scanBackward(offset, getCompanion().getScope().getOffset(), '=') > -1;
+
+ return true;
} catch (BadLocationException e) {
PHPCorePlugin.log(e);
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/UseStatementContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/UseStatementContext.java
index 018f1e552..77853eda6 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/UseStatementContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/UseStatementContext.java
@@ -20,6 +20,7 @@ import org.eclipse.dltk.annotations.Nullable;
import org.eclipse.dltk.core.CompletionRequestor;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.php.core.PHPVersion;
+import org.eclipse.php.core.codeassist.ICompletionScope;
import org.eclipse.php.core.compiler.ast.nodes.NamespaceReference;
import org.eclipse.php.internal.core.documentModel.parser.regions.PHPRegionTypes;
import org.eclipse.php.internal.core.util.MagicMemberUtil;
@@ -119,29 +120,37 @@ public abstract class UseStatementContext extends StatementContext {
}
}
- private boolean buildUseStatement(int offset, @NonNull IStructuredDocumentRegion sdRegion,
- boolean isClassStatementContext) {
+ private boolean buildUseStatement(int offset, @NonNull IStructuredDocumentRegion sdRegion) {
ContextRegion[] foundDelimiter = new ContextRegion[1];
TextSequence statementText = PHPTextSequenceUtilities.getStatement(offset, sdRegion, true, null, 0,
foundDelimiter);
biggestCommonStatementText = longestPrefixTextBeforeCursor = rebuiltUseStatementText = statementText;
isCursorInsideGroupStatement = isUseFunctionStatement = isUseConstStatement = false;
type = TYPES.NONE;
+ ICompletionScope scope = getCompanion().getScope();
- boolean hasUsePrefix = hasUsePrefix(statementText);
- if (hasUsePrefix) {
- if (isClassStatementContext) {
- if (getCompanion().getPHPVersion().isLessThan(PHPVersion.PHP5_4)) {
- return false;
- }
- type = TYPES.TRAIT;
- } else {
- type = TYPES.USE;
- findConstOrFunctionWord(statementText, 1, false);
+ switch (scope.getType()) {
+ case USE:
+ case USE_CONST:
+ case USE_FUNCTION:
+ type = TYPES.USE;
+ findConstOrFunctionWord(statementText, 1, false);
+ if (hasUsePrefix(statementText)) {
+ return true;
+ }
+ break;
+ case USE_GROUP:
+ type = TYPES.USE_GROUP;
+ isCursorInsideGroupStatement = true;
+ break;
+ case TRAIT_USE:
+ case TRAIT_PRECEDENCE:
+ type = TYPES.TRAIT;
+ if (getCompanion().getPHPVersion().isLessThan(PHPVersion.PHP5_4)) {
+ return false;
}
return true;
- }
- if (isClassStatementContext) {
+ default:
return false;
}
@@ -279,9 +288,6 @@ public abstract class UseStatementContext extends StatementContext {
if (!super.isValid(sourceModule, offset, requestor)) {
return false;
}
- ClassStatementContext classStatementContext = new ClassStatementContext();
- classStatementContext.init(getCompanion());
- boolean isClassStatementContext = classStatementContext.isValid(sourceModule, offset, requestor);
- return buildUseStatement(offset, getCompanion().getStructuredDocumentRegion(), isClassStatementContext);
+ return buildUseStatement(offset, getCompanion().getStructuredDocumentRegion());
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/CompletionScope.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/CompletionScope.java
new file mode 100644
index 000000000..9ef12af6d
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/CompletionScope.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Dawid Pakuła and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Dawid Pakuła - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.internal.core.codeassist.scope;
+
+import org.eclipse.php.core.codeassist.ICompletionScope;
+
+/**
+ * Provisoinal API
+ */
+public class CompletionScope implements ICompletionScope {
+
+ private final Type type;
+
+ private final ICompletionScope parent;
+
+ private final int offset;
+ private final int length;
+
+ private final String name;
+
+ public CompletionScope(Type type, int offset, int length, ICompletionScope parent) {
+ this.type = type;
+ this.parent = parent;
+ this.offset = offset;
+ this.length = length;
+ this.name = null;
+ }
+
+ public CompletionScope(Type type, String name, int offset, int length, ICompletionScope parent) {
+ this.type = type;
+ this.parent = parent;
+ this.offset = offset;
+ this.length = length;
+ this.name = name;
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ @Override
+ public ICompletionScope getParent() {
+ return parent;
+ }
+
+ @Override
+ public ICompletionScope findParent(Type... types) {
+ ICompletionScope test = this;
+ SEARCH: do {
+ for (Type type : types) {
+ if (test.getType() == type) {
+ break SEARCH;
+ }
+ }
+ test = test.getParent();
+ } while (test != null);
+
+ return test;
+ }
+
+ @Override
+ public int getLength() {
+ return length;
+ }
+
+ @Override
+ public int getOffset() {
+ return offset;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(type.name());
+ sb.append('(').append(offset).append(',').append(length);
+ if (name != null) {
+ sb.append(',').append(name);
+ }
+ return sb.append(')').toString();
+ }
+}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/ScopeParser.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/ScopeParser.java
new file mode 100644
index 000000000..f51d26883
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/scope/ScopeParser.java
@@ -0,0 +1,507 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Dawid Pakuła and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Dawid Pakuła - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.internal.core.codeassist.scope;
+
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.eclipse.dltk.annotations.NonNull;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.php.core.codeassist.ICompletionScope;
+import org.eclipse.php.core.codeassist.ICompletionScope.Type;
+import org.eclipse.php.internal.core.Logger;
+import org.eclipse.php.internal.core.documentModel.parser.PHPRegionContext;
+import org.eclipse.php.internal.core.documentModel.parser.regions.PHPRegionTypes;
+import org.eclipse.php.internal.core.documentModel.parser.regions.PHPScriptRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+
+public class ScopeParser {
+ private final IDocument document;
+
+ private int internalOffset;
+
+ private class State {
+ public ICompletionScope.Type type;
+ public int start;
+ public int length;
+ public int nest = 0;
+
+ public State(ICompletionScope.Type type, int start) {
+ this.type = type;
+ this.start = start;
+ }
+
+ public State(ICompletionScope.Type type, int start, int length) {
+ this.type = type;
+ this.start = start;
+ this.length = length;
+ }
+ }
+
+ private class SimpleBlockState extends State {
+ public SimpleBlockState(Type type, int start) {
+ super(type, start);
+ }
+
+ }
+
+ private class ControlState extends State {
+ public boolean block = false;
+
+ public ControlState(ICompletionScope.Type type, int start) {
+ super(type, start);
+ }
+ }
+
+ private class NamedState extends ControlState {
+ public StringBuilder name = new StringBuilder();
+
+ public NamedState(ICompletionScope.Type type, int start) {
+ super(type, start);
+ }
+ }
+
+ private Deque<State> states;
+ private Deque<State> memory;
+ private LinkedList<ITextRegion> buffer;
+ private boolean collectName = false;
+
+ @NonNull
+ private final ICompletionScope parentScope;
+
+ public ScopeParser(IDocument document) {
+ this.document = document;
+ this.parentScope = new CompletionScope(ICompletionScope.Type.FILE, 0,
+ document != null ? document.getLength() : 0, null);
+ }
+
+ public ICompletionScope parse(int offset) {
+ states = new LinkedList<>();
+ states.push(new State(Type.FILE, parentScope.getOffset(), parentScope.getLength()));
+ memory = new LinkedList<>();
+ buffer = new LinkedList<>();
+ if (document instanceof IStructuredDocument) {
+ return parse((IStructuredDocument) document, parentScope, offset);
+ }
+
+ return parentScope;
+ }
+
+ protected ICompletionScope parse(IStructuredDocument document, ICompletionScope mainScope, int offset) {
+ ICompletionScope scope = mainScope;
+ internalOffset = offset;
+ ITextRegion previousRegion = null;
+ for (IStructuredDocumentRegion region : document.getStructuredDocumentRegions()) {
+ if (region.getStartOffset() > offset) {
+ break;
+ }
+ if (!region.getType().equals(PHPRegionContext.PHP_CONTENT)) {
+ continue;
+ }
+ int pos = region.getStartOffset();
+ for (Iterator<?> it = region.getRegions().iterator(); it.hasNext();) {
+ ITextRegion sub = (ITextRegion) it.next();
+ if (sub.getStart() + pos > offset) {
+ break;
+ }
+ if (sub instanceof PHPScriptRegion) {
+ PHPScriptRegion scriptRegion = (PHPScriptRegion) sub;
+ try {
+ ITextRegion[] phpTokens = scriptRegion.getPHPTokens(0, scriptRegion.getLength()); // read
+ // all
+
+ for (ITextRegion phpToken : phpTokens) {
+ if (phpToken.getType() != PHPRegionTypes.WHITESPACE) {
+ buffer.add(phpToken);
+ }
+ State current = states.peek();
+ int tokenStart = pos + sub.getStart() + phpToken.getStart();
+ int tokenEnd = tokenStart + phpToken.getTextLength();
+ switch (phpToken.getType()) {
+ case PHPRegionTypes.WHITESPACE:
+ continue;
+ case PHPRegionTypes.PHP_LINE_COMMENT:
+ pushState(new State(Type.COMMENT, tokenStart));
+ popState(tokenEnd);
+ break;
+ case PHPRegionTypes.PHP_COMMENT_START:
+ pushState(new State(Type.COMMENT, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_COMMENT_END:
+ if (current.type == Type.COMMENT) {
+ popState(tokenEnd);
+ }
+ break;
+ case PHPRegionTypes.PHPDOC_COMMENT_START:
+ pushState(new State(Type.PHPDOC, tokenStart));
+ break;
+ case PHPRegionTypes.PHPDOC_COMMENT_END:
+ if (current.type == Type.PHPDOC) {
+ popState(tokenEnd);
+ }
+ break;
+ case PHPRegionTypes.PHP_ABSTRACT:
+ case PHPRegionTypes.PHP_CLASS:
+ if (previousRegion != null
+ && previousRegion.getType() == PHPRegionTypes.PHP_PAAMAYIM_NEKUDOTAYIM) {
+ break;
+ }
+ if (current.type == Type.BLOCK || current.type == Type.FILE) {
+ pushState(new NamedState(Type.CLASS, tokenStart));
+ }
+ break;
+ case PHPRegionTypes.PHP_TRAIT:
+ pushState(new NamedState(Type.TRAIT, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_INTERFACE:
+ pushState(new NamedState(Type.INTERFACE, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_NAMESPACE:
+ pushState(new NamedState(Type.NAMESPACE, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_FUNCTION:
+ if (current.type == Type.USE) {
+ states.pop();
+ pushState(new State(Type.USE_FUNCTION, current.start));
+ current = states.peek();
+ } else if (current.type == Type.TYPE_STATEMENT) {
+ states.pop();
+ pushState(new NamedState(Type.FUNCTION, current.start));
+ current = states.peek();
+ } else if (current.type != Type.USE_GROUP) {
+ pushState(new NamedState(Type.FUNCTION, tokenStart));
+ }
+ break;
+ case PHPRegionTypes.PHP_CURLY_OPEN:
+ if (current.type == Type.USE || current.type == Type.USE_CONST
+ || current.type == Type.USE_FUNCTION) {
+ pushState(new State(Type.USE_GROUP, tokenStart));
+ } else if (current.type == Type.TRAIT_USE) {
+ pushState(new State(Type.TRAIT_PRECEDENCE, tokenStart));
+ } else {
+ pushState(new State(Type.BLOCK, tokenStart));
+ }
+ collectName = false;
+ break;
+ case PHPRegionTypes.PHP_IF:
+ pushState(new ControlState(Type.IF, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_SWITCH:
+ pushState(new ControlState(Type.SWITCH, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_FOR:
+ pushState(new ControlState(Type.FOR, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_FOREACH:
+ pushState(new ControlState(Type.FOREACH, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_WHILE:
+ if (current.type != Type.DOWHILE) {
+ pushState(new ControlState(Type.WHILE, tokenStart));
+ }
+ break;
+ case PHPRegionTypes.PHP_USE:
+ if (current.type == Type.BLOCK) {
+ states.pop(); // for a moment
+ if (states.peek().type == Type.CLASS || states.peek().type == Type.TRAIT) {
+ states.push(current);
+ pushState(new ControlState(Type.TRAIT_USE, tokenStart));
+ } else {
+ states.push(current);
+ pushState(new ControlState(Type.USE, tokenStart));
+ }
+ } else if (current.type == Type.FILE) {
+ pushState(new ControlState(Type.USE, tokenStart));
+ }
+
+ break;
+ case PHPRegionTypes.PHP_TRY:
+ pushState(new ControlState(Type.TRY, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_CATCH:
+ pushState(new ControlState(Type.CATCH, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_FINALLY:
+ pushState(new ControlState(Type.FINALLY, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_DO:
+ pushState(new ControlState(Type.DOWHILE, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_CURLY_CLOSE:
+ if (current.type == Type.BLOCK || current.type == Type.USE_GROUP
+ || current.type == Type.TRAIT_PRECEDENCE) {
+ popState(tokenEnd);
+ current = states.peek();
+ if (current.type == Type.TRAIT_PRECEDENCE) {
+ popState(tokenEnd);
+ current = states.peek();
+ }
+ }
+ switch (current.type) {
+ case DOWHILE: // we waiting for HEAD ";"
+ break;
+ default:
+ if (current instanceof ControlState) {
+ popState(tokenEnd);
+ break;
+ }
+ }
+ break;
+ case PHPRegionTypes.PHP_NS_SEPARATOR:
+ if (previousRegion != null
+ && previousRegion.getType() == PHPRegionTypes.PHP_NAMESPACE) {
+ states.pop();
+ buffer.pop();
+ buffer.add(previousRegion);
+ buffer.add(phpToken);
+ current = states.peek();
+ }
+ case PHPRegionTypes.PHP_LABEL:
+ if (current instanceof NamedState && collectName) {
+ ((NamedState) current).name
+ .append(document.get(tokenStart, phpToken.getTextLength()));
+ }
+ break;
+ case PHPRegionTypes.PHP_SEMICOLON:
+ collectName = false;
+ switch (current.type) {
+ case NAMESPACE:
+ current.length = parentScope.getLength() - current.start;
+ pushState(new State(Type.BLOCK, tokenStart + 1));
+ break;
+ case TYPE_STATEMENT:
+ case CONST:
+ case FIELD:
+ case FUNCTION:
+ case USE:
+ case USE_FUNCTION:
+ case USE_CONST:
+ case TRAIT_USE:
+ popState(tokenEnd);
+ break;
+ case WHILE:
+ case IF:
+ case FOR:
+ case FOREACH:
+ case DOWHILE:
+ if (!((ControlState) (current)).block) {
+ if (!buffer.isEmpty()) {
+ pushState(new SimpleBlockState(Type.BLOCK,
+ pos + sub.getStart() + buffer.get(0).getStart()));
+ } else {
+ pushState(new SimpleBlockState(Type.BLOCK, tokenStart));
+ }
+ popState(tokenEnd);
+ ((ControlState) (current)).block = true;
+ }
+
+ popState(tokenEnd);
+ break;
+ default:
+ }
+ break;
+ case PHPRegionTypes.PHP_TOKEN:
+ switch (document.getChar(tokenStart)) {
+ case ':':
+ switch (current.type) {
+ case SWITCH:
+ case WHILE:
+ case FOR:
+ case FOREACH:
+ case IF:
+ pushState(new State(Type.BLOCK, tokenStart));
+ collectName = false;
+ break;
+ default:
+ }
+ break;
+ case '(':
+ switch (current.type) {
+ case SWITCH:
+ case WHILE:
+ case FOR:
+ case FOREACH:
+ case DOWHILE:
+ case CATCH:
+ case FUNCTION:
+ case IF:
+ pushState(new State(Type.HEAD, tokenStart));
+ collectName = false;
+ break;
+ case HEAD:
+ current.nest++;
+ break;
+ default:
+ }
+ case ')':
+ if (current.type == Type.HEAD) {
+ if (current.nest > 0) {
+ current.nest--;
+ } else {
+ popState(tokenStart + 1); // ignore
+ // whitespace
+ }
+ }
+ }
+ break;
+ case PHPRegionTypes.PHP_ENDIF:
+ if (current.type == Type.BLOCK) {
+ states.pop(); // remove for a moment
+ if (states.peek().type == Type.IF) {
+ states.push(current);
+ popState(tokenEnd);
+ popState(tokenEnd);
+ }
+ }
+ break;
+ case PHPRegionTypes.PHP_ENDSWITCH:
+ if (current.type == Type.BLOCK) {
+ states.pop(); // remove for a moment
+ if (states.peek().type == Type.SWITCH) {
+ states.push(current);
+ popState(tokenEnd);
+ popState(tokenEnd);
+ }
+ }
+ break;
+ case PHPRegionTypes.PHP_ENDFOREACH:
+ if (current.type == Type.BLOCK) {
+ states.pop(); // remove for a moment
+ if (states.peek().type == Type.FOREACH) {
+ states.push(current);
+ popState(tokenEnd);
+ popState(tokenEnd);
+ }
+ }
+ break;
+ case PHPRegionTypes.PHP_ENDWHILE:
+ if (current.type == Type.BLOCK) {
+ states.pop(); // remove for a moment
+ if (states.peek().type == Type.WHILE) {
+ states.push(current);
+ popState(tokenEnd);
+ popState(tokenEnd);
+ }
+ }
+ break;
+ case PHPRegionTypes.PHP_ENDFOR:
+ if (current.type == Type.BLOCK) {
+ states.pop(); // remove for a moment
+ if (states.peek().type == Type.FOR) {
+ states.push(current);
+ popState(tokenEnd);
+ popState(tokenEnd);
+ }
+ }
+ break;
+ case PHPRegionTypes.PHP_VAR:
+ pushState(new State(Type.FIELD, tokenStart));
+ break;
+ case PHPRegionTypes.PHP_VARIABLE:
+ if (current.type == Type.TYPE_STATEMENT) {
+ states.pop();
+ pushState(new State(Type.FIELD, current.start));
+ current = states.peek();
+ }
+ break;
+ case PHPRegionTypes.PHP_CONST:
+ if (current.type == Type.USE) {
+ states.pop();
+ pushState(new State(Type.USE_CONST, current.start));
+ current = states.peek();
+ } else if (current.type != Type.USE_GROUP) {
+ pushState(new State(Type.CONST, tokenStart));
+ }
+ break;
+
+ case PHPRegionTypes.PHP_PRIVATE:
+ case PHPRegionTypes.PHP_STATIC:
+ case PHPRegionTypes.PHP_PROTECTED:
+ case PHPRegionTypes.PHP_PUBLIC:
+ if (current.type != Type.TYPE_STATEMENT) {
+ pushState(new State(Type.TYPE_STATEMENT, tokenStart));
+ }
+ break;
+ case PHPRegionTypes.PHP_EXTENDS:
+ case PHPRegionTypes.PHP_IMPLEMENTS:
+ collectName = false;
+ break;
+ }
+
+ // System.out.println(phpToken);
+ // System.out.println("'" + document.get(tokenStart,
+ // phpToken.getLength()) +
+ // "'");
+ previousRegion = phpToken;
+ }
+ } catch (BadLocationException e) {
+ Logger.logException(e);
+ }
+ }
+ }
+ }
+ while (states.size() > 1) { // unfinished states, recovery as end file
+ popState(scope.getLength() + scope.getOffset());
+ }
+ if (!memory.isEmpty()) {
+ for (State state : memory) {
+ if (state instanceof NamedState) {
+ String name = ((NamedState) state).name.length() == 0 ? null : ((NamedState) state).name.toString();
+ scope = new CompletionScope(state.type, name, state.start, state.length, scope);
+ } else {
+ scope = new CompletionScope(state.type, state.start, state.length, scope);
+ }
+
+ }
+ }
+ memory.clear();
+ states.clear();
+
+ return scope;
+ }
+
+ private void popState(int end) {
+ State state = states.pop();
+ state.length = end - state.start;
+ if (state.start <= internalOffset && end >= internalOffset) {
+ memory.addFirst(state);
+ }
+ if (states.peek() instanceof SimpleBlockState) {
+ popState(end);
+ popState(end);
+ }
+ }
+
+ private void pushState(State state) {
+ if (state.type == Type.BLOCK && states.peek() instanceof ControlState) {
+ ((ControlState) states.peek()).block = true;
+ }
+ if (state instanceof ControlState && states.peek() instanceof ControlState
+ && !((ControlState) states.peek()).block) {
+ // nested one-line block
+ pushState(new SimpleBlockState(Type.BLOCK, state.start));
+ }
+ states.push(state);
+ buffer.clear();
+ if (state instanceof NamedState) {
+ collectName = true;
+ } else if (state instanceof ControlState) {
+ collectName = false;
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractClassInstantiationStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractClassInstantiationStrategy.java
index cf71aa5c9..620a661c2 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractClassInstantiationStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractClassInstantiationStrategy.java
@@ -3,13 +3,14 @@
*/
package org.eclipse.php.internal.core.codeassist.strategies;
-import org.eclipse.dltk.compiler.env.IModuleSource;
import org.eclipse.dltk.core.*;
import org.eclipse.dltk.core.search.IDLTKSearchScope;
import org.eclipse.dltk.internal.core.ModelElement;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionReporter;
+import org.eclipse.php.core.codeassist.ICompletionScope;
+import org.eclipse.php.core.codeassist.ICompletionScope.Type;
import org.eclipse.php.core.compiler.PHPFlags;
import org.eclipse.php.core.compiler.ast.nodes.NamespaceReference;
import org.eclipse.php.internal.core.Logger;
@@ -28,7 +29,7 @@ import org.eclipse.php.internal.core.typeinference.FakeConstructor;
*/
public abstract class AbstractClassInstantiationStrategy extends TypesStrategy {
- private IType enclosingClass;
+ private String enclosingClass;
public AbstractClassInstantiationStrategy(ICompletionContext context, int trueFlag, int falseFlag) {
super(context, trueFlag, falseFlag);
@@ -44,21 +45,9 @@ public abstract class AbstractClassInstantiationStrategy extends TypesStrategy {
ICompletionContext context = getContext();
AbstractCompletionContext concreteContext = (AbstractCompletionContext) context;
- enclosingClass = null;
- try {
- IModelElement enclosingElement = concreteContext.getSourceModule()
- .getElementAt(concreteContext.getOffset());
- while (enclosingElement instanceof IField) {
- enclosingElement = enclosingElement.getParent();
- }
- if (enclosingElement instanceof IMethod) {
- IModelElement parent = ((IMethod) enclosingElement).getParent();
- if (parent instanceof IType) {
- enclosingClass = (IType) parent;
- }
- }
- } catch (ModelException e) {
- PHPCorePlugin.log(e);
+ ICompletionScope scope = getCompanion().getScope().findParent(Type.CLASS, Type.INTERFACE);
+ if (scope != null) {
+ enclosingClass = scope.getName();
}
ISourceRange replaceRange = getReplacementRangeForMember(concreteContext);
@@ -83,12 +72,13 @@ public abstract class AbstractClassInstantiationStrategy extends TypesStrategy {
if (!concreteContext.getCompletionRequestor().isContextInformationMode()) {
// here we use fake method,and do the real work in class
// ParameterGuessingProposal
- IMethod ctorMethod = FakeConstructor.createFakeConstructor(null, type, type.equals(enclosingClass));
+ IMethod ctorMethod = FakeConstructor.createFakeConstructor(null, type,
+ enclosingClass != null && enclosingClass.equals(type.getElementName()));
reporter.reportMethod(ctorMethod, suffix, replaceRange, ProposalExtraInfo.FULL_NAME);
} else {
// if this is context information mode,we use this,
// because the number of types' length is very small
- IMethod[] ctors = FakeConstructor.getConstructors(type, type.equals(enclosingClass));
+ IMethod[] ctors = FakeConstructor.getConstructors(type, type.getElementName().equals(enclosingClass));
if (ctors != null && ctors.length == 2) {
if (ctors[1] != null) {
reporter.reportMethod(ctors[1], suffix, replaceRange, ProposalExtraInfo.FULL_NAME);
@@ -103,10 +93,11 @@ public abstract class AbstractClassInstantiationStrategy extends TypesStrategy {
}
@Override
- protected void reportAlias(ICompletionReporter reporter, IDLTKSearchScope scope, IModuleSource module,
+ protected void reportAlias(ICompletionReporter reporter, IDLTKSearchScope scope, ISourceModule module,
ISourceRange replacementRange, IType type, String fullyQualifiedName, String alias, String suffix) {
IType aliasType = new AliasType((ModelElement) type, fullyQualifiedName, alias);
- IMethod ctorMethod = FakeConstructor.createFakeConstructor(null, aliasType, type.equals(enclosingClass));
+ IMethod ctorMethod = FakeConstructor.createFakeConstructor(null, aliasType,
+ type.getElementName().equals(enclosingClass));
reporter.reportMethod(ctorMethod, "", replacementRange, ProposalExtraInfo.FULL_NAME); //$NON-NLS-1$
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractCompletionStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractCompletionStrategy.java
index a195c5dc6..50554cfad 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractCompletionStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/AbstractCompletionStrategy.java
@@ -76,7 +76,7 @@ public abstract class AbstractCompletionStrategy implements ICompletionStrategy
AbstractCompletionContext completionContext = (AbstractCompletionContext) context;
- int offset = completionContext.getOffset();
+ int offset = getCompanion().getOffset();
int start = completionContext.getReplacementStart();
int prefixEnd = completionContext.getReplacementEnd();
@@ -91,7 +91,7 @@ public abstract class AbstractCompletionStrategy implements ICompletionStrategy
AbstractCompletionContext completionContext = (AbstractCompletionContext) context;
- int offset = completionContext.getOffset();
+ int offset = getCompanion().getOffset();
int start = completionContext.getReplacementStart();
int prefixEnd = completionContext.getReplacementEnd();
@@ -118,7 +118,7 @@ public abstract class AbstractCompletionStrategy implements ICompletionStrategy
AbstractCompletionContext completionContext = (AbstractCompletionContext) context;
- int offset = completionContext.getOffset();
+ int offset = getCompanion().getOffset();
int start = completionContext.getReplacementStart();
int prefixEnd = completionContext.getReplacementEnd();
@@ -126,7 +126,7 @@ public abstract class AbstractCompletionStrategy implements ICompletionStrategy
int length = Math.max(offset, prefixEnd) - start;
- IDocument document = completionContext.getDocument();
+ IDocument document = getCompanion().getDocument();
int endOfReplacement = start + length;
if (document.getLength() == start) {
@@ -192,7 +192,7 @@ public abstract class AbstractCompletionStrategy implements ICompletionStrategy
* Creates search scope
*/
protected IDLTKSearchScope createSearchScope() {
- ISourceModule sourceModule = ((AbstractCompletionContext) context).getSourceModule();
+ ISourceModule sourceModule = getCompanion().getSourceModule();
IScriptProject scriptProject = sourceModule.getScriptProject();
if (scriptProject != null) {
return SearchEngine.createSearchScope(scriptProject);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ArrayStringKeysStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ArrayStringKeysStrategy.java
index ebca6927b..0b6223f6e 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ArrayStringKeysStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ArrayStringKeysStrategy.java
@@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.core.CompletionRequestor;
import org.eclipse.dltk.core.ISourceRange;
-import org.eclipse.dltk.core.SourceParserUtil;
import org.eclipse.dltk.core.SourceRange;
import org.eclipse.dltk.internal.core.ModelElement;
import org.eclipse.jface.text.BadLocationException;
@@ -66,9 +65,9 @@ public class ArrayStringKeysStrategy extends AbstractCompletionStrategy {
CompletionRequestor requestor = arrayContext.getCompletionRequestor();
String prefix = arrayContext.getPrefix();
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(arrayContext.getSourceModule());
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
try {
- ArrayKeyFinder finder = new ArrayKeyFinder(prefix, arrayContext.getOffset());
+ ArrayKeyFinder finder = new ArrayKeyFinder(prefix, getCompanion().getOffset());
moduleDeclaration.traverse(finder);
Set<String> names = finder.getNames();
int extraObject = ProposalExtraInfo.DEFAULT;
@@ -78,7 +77,7 @@ public class ArrayStringKeysStrategy extends AbstractCompletionStrategy {
for (String name : names) {
if (!requestor.isContextInformationMode()) {
- reporter.reportField(new FakeField((ModelElement) arrayContext.getSourceModule(), name, 0, 0), "", //$NON-NLS-1$
+ reporter.reportField(new FakeField((ModelElement) getCompanion().getSourceModule(), name, 0, 0), "", //$NON-NLS-1$
replaceRange, false, 0, extraObject);
}
@@ -102,7 +101,8 @@ public class ArrayStringKeysStrategy extends AbstractCompletionStrategy {
}
if (variable.startsWith(prefix)) {
if (!requestor.isContextInformationMode() || variable.length() == prefix.length()) {
- reporter.reportField(new FakeField((ModelElement) context.getSourceModule(), variable, 0, 0), "", //$NON-NLS-1$
+ reporter.reportField(new FakeField((ModelElement) getCompanion().getSourceModule(), variable, 0, 0),
+ "", //$NON-NLS-1$
replaceRange, false);
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/BuiltinArrayKeysStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/BuiltinArrayKeysStrategy.java
index 6c8784dda..46ee587f0 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/BuiltinArrayKeysStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/BuiltinArrayKeysStrategy.java
@@ -122,7 +122,7 @@ public class BuiltinArrayKeysStrategy extends AbstractCompletionStrategy {
}
}
- PHPVersion phpVersion = arrayContext.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
reportVariables(reporter, arrayContext, PHPVariables.getVariables(phpVersion), prefix, true, extraObject);
}
}
@@ -142,7 +142,8 @@ public class BuiltinArrayKeysStrategy extends AbstractCompletionStrategy {
}
if (variable.startsWith(prefix)) {
if (!requestor.isContextInformationMode() || variable.length() == prefix.length()) {
- reporter.reportField(new FakeField((ModelElement) context.getSourceModule(), variable, 0, 0), "", //$NON-NLS-1$
+ reporter.reportField(new FakeField((ModelElement) getCompanion().getSourceModule(), variable, 0, 0),
+ "", //$NON-NLS-1$
replaceRange, false, 0, extraObject);
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CatchTypeStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CatchTypeStrategy.java
index 34e6e1350..210c4465f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CatchTypeStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CatchTypeStrategy.java
@@ -44,7 +44,7 @@ public class CatchTypeStrategy extends TypesStrategy {
@Override
public String getSuffix(AbstractCompletionContext abstractContext) {
- return isInsertMode() && abstractContext.hasSpaceAtPosition(abstractContext.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
+ return isInsertMode() && abstractContext.hasSpaceAtPosition(getCompanion().getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassDeclarationKeywordsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassDeclarationKeywordsStrategy.java
index c73773bb5..eea3b5b79 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassDeclarationKeywordsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassDeclarationKeywordsStrategy.java
@@ -70,6 +70,6 @@ public class ClassDeclarationKeywordsStrategy extends AbstractCompletionStrategy
}
public String getSuffix(AbstractCompletionContext abstractContext) {
- return isInsertMode() && abstractContext.hasSpaceAtPosition(abstractContext.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
+ return isInsertMode() && abstractContext.hasSpaceAtPosition(getCompanion().getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
}
}
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 b5408ea56..53fc59d70 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
@@ -24,12 +24,13 @@ import org.eclipse.dltk.core.*;
import org.eclipse.dltk.internal.core.ModelElement;
import org.eclipse.dltk.internal.core.hierarchy.FakeType;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionReporter;
+import org.eclipse.php.core.codeassist.ICompletionScope.Type;
import org.eclipse.php.core.codeassist.IElementFilter;
import org.eclipse.php.internal.core.Logger;
import org.eclipse.php.internal.core.PHPCorePlugin;
-import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.internal.core.codeassist.contexts.ClassMemberContext;
import org.eclipse.php.internal.core.codeassist.contexts.ClassMemberContext.Trigger;
import org.eclipse.php.internal.core.codeassist.contexts.ClassStaticMemberContext;
@@ -70,12 +71,11 @@ public class ClassFieldsStrategy extends ClassMembersStrategy {
ISourceRange replaceRange = getReplacementRange(concreteContext);
List<IField> result = new LinkedList<>();
-
+ boolean inUseTrait = getCompanion().getScope().findParent(Type.TRAIT_USE) != null;
for (IType type : concreteContext.getLhsTypes()) {
try {
ITypeHierarchy hierarchy = getCompanion().getSuperTypeHierarchy(type, null);
IField[] fields = null;
-
if (concreteContext instanceof ClassStaticMemberContext
&& concreteContext.getTriggerType() == Trigger.CLASS
&& ((ClassStaticMemberContext) concreteContext).isParent()) {
@@ -92,7 +92,7 @@ public class ClassFieldsStrategy extends ClassMembersStrategy {
}
for (IField field : removeOverriddenElements(Arrays.asList(fields))) {
- if (concreteContext.isInUseTraitStatement()) {
+ if (inUseTrait) {
result.add(field);
} else if (!isFiltered(field, type, concreteContext)) {
result.add(field);
@@ -103,18 +103,17 @@ public class ClassFieldsStrategy extends ClassMembersStrategy {
}
}
if (concreteContext instanceof ClassStaticMemberContext && concreteContext.getTriggerType() == Trigger.CLASS
- && !concreteContext.isInUseTraitStatement()
- && PHPVersion.PHP5_4.isLessThan(concreteContext.getPHPVersion())
+ && !inUseTrait && PHPVersion.PHP5_4.isLessThan(getCompanion().getPHPVersion())
&& (CLASS_KEYWORD.startsWith(prefix.toLowerCase()) || CLASS_KEYWORD.equals(prefix.toLowerCase()))) {
try {
- ITextRegion phpToken = concreteContext.getPHPScriptRegion()
- .getPHPToken(concreteContext.getPHPToken().getStart() - 1);
+ ITextRegion phpToken = getCompanion().getPHPScriptRegion()
+ .getPHPToken(getCompanion().getPHPToken().getStart() - 1);
if (PHPRegionTypes.PHP_PAAMAYIM_NEKUDOTAYIM.equals(phpToken.getType())) {
- phpToken = concreteContext.getPHPToken(phpToken.getStart() - 1);
+ phpToken = getCompanion().getPHPToken(phpToken.getStart() - 1);
}
if (isStaticCall(phpToken.getType())) {
- result.add(new FakeField(new FakeType((ModelElement) concreteContext.getSourceModule(), STD_CLASS),
+ result.add(new FakeField(new FakeType((ModelElement) getCompanion().getSourceModule(), STD_CLASS),
CLASS_KEYWORD, Modifiers.AccConstant | Modifiers.AccPublic));
}
} catch (BadLocationException e) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassInstantiationStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassInstantiationStrategy.java
index f1fcf448d..3d4d556ce 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassInstantiationStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassInstantiationStrategy.java
@@ -45,7 +45,7 @@ public class ClassInstantiationStrategy extends AbstractClassInstantiationStrate
addSelf(completionContext, reporter);
// for anonymous class (PHP 7)
- if (completionContext.getPHPVersion().isGreaterThan(PHPVersion.PHP5_6)) {
+ if (getCompanion().getPHPVersion().isGreaterThan(PHPVersion.PHP5_6)) {
String prefix = completionContext.getPrefix();
ISourceRange replaceRange = getReplacementRangeForMember(completionContext);
if (CLASS_KEYWORD.startsWith(prefix) && prefix.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) == -1) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMembersStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMembersStrategy.java
index 19b95caa2..87be0cef1 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMembersStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassMembersStrategy.java
@@ -19,12 +19,12 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.dltk.ast.Modifiers;
import org.eclipse.dltk.core.*;
import org.eclipse.dltk.core.index2.search.ISearchEngine.MatchRule;
+import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.IElementFilter;
import org.eclipse.php.core.compiler.PHPFlags;
import org.eclipse.php.internal.core.PHPCoreConstants;
import org.eclipse.php.internal.core.PHPCorePlugin;
-import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.internal.core.codeassist.contexts.ClassMemberContext;
import org.eclipse.php.internal.core.codeassist.contexts.ClassMemberContext.Trigger;
import org.eclipse.php.internal.core.codeassist.contexts.ClassObjMemberContext;
@@ -58,7 +58,8 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
}
protected boolean showStaticMembers(ClassMemberContext context) {
- return context.getTriggerType() == Trigger.CLASS || context.getPHPVersion().isGreaterThan(PHPVersion.PHP5);
+ return context.getTriggerType() == Trigger.CLASS
+ || getCompanion().getPHPVersion().isGreaterThan(PHPVersion.PHP5);
}
protected boolean showNonStaticMembers(ClassMemberContext context) {
@@ -128,7 +129,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
if (PHPFlags.isConstant(member.getFlags())) {
if (context.getTriggerType() == Trigger.CLASS) {
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- && !isTraitMember(context.getPHPVersion(), type, member))) {
+ && !isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isParent(context)) { // is Parent
return true; // 1:1
} else if (isSelfKeyword(context)) {
@@ -162,7 +163,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
if (context.getTriggerType() == Trigger.CLASS && !isFunctionParameterContext) {
/* check 5 */
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- || isTraitMember(context.getPHPVersion(), type, member))) {
+ || isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isParent(context)) { // is Parent
return true; // 1:1
} else if (isSelfKeyword(context)) {
@@ -188,7 +189,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
} else if (context.getTriggerType() == Trigger.OBJECT) {
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- || isTraitMember(context.getPHPVersion(), type, member))) {
+ || isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isThisKeyWord(context) && showStrictOptions()) {
return false; // 1:5
} else if (isIndirectThis(context)) {
@@ -218,7 +219,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
} else if (member instanceof IMethod) {
if (context.getTriggerType() == Trigger.CLASS && !isFunctionParameterContext) {
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- || isTraitMember(context.getPHPVersion(), type, member))) {
+ || isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isParent(context)) {
return true; // 5:1
} else if (isSelfCall(context)) {
@@ -261,7 +262,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
}
} else if (context.getTriggerType() == Trigger.OBJECT) {
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- || isTraitMember(context.getPHPVersion(), type, member))) {
+ || isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isThisKeyWord(context)) {
return false; // 5:5
} else if (isIndirectThis(context)) {
@@ -303,7 +304,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
return true; // 9:1 - 12:4
} else if (context.getTriggerType() == Trigger.OBJECT) {
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- || isTraitMember(context.getPHPVersion(), type, member))) {
+ || isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isThisKeyWord(context)) {
return false; // 9:5
} else if (isIndirectThis(context)) {
@@ -333,7 +334,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
} else if (member instanceof IMethod) {
if (context.getTriggerType() == Trigger.CLASS && !isFunctionParameterContext) {
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- || isTraitMember(context.getPHPVersion(), type, member))) {
+ || isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isParent(context)) {
return true; // 13:1
} else if (isSelfKeyword(context)) {
@@ -376,7 +377,7 @@ public abstract class ClassMembersStrategy extends AbstractCompletionStrategy {
}
} else if (context.getTriggerType() == Trigger.OBJECT) {
if (PHPFlags.isPrivate(flags) && (member.getDeclaringType().equals(type)
- || isTraitMember(context.getPHPVersion(), type, member))) {
+ || isTraitMember(getCompanion().getPHPVersion(), type, member))) {
if (isThisKeyWord(context)) {
return false; // 13:5
} else if (isIndirectThis(context)) {
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 8742fb402..70ac960d9 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
@@ -22,6 +22,7 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionReporter;
+import org.eclipse.php.core.codeassist.ICompletionScope.Type;
import org.eclipse.php.core.codeassist.IElementFilter;
import org.eclipse.php.internal.core.PHPCorePlugin;
import org.eclipse.php.internal.core.codeassist.ProposalExtraInfo;
@@ -68,17 +69,18 @@ public class ClassMethodsStrategy extends ClassMembersStrategy {
replaceRange = getReplacementRangeWithBraces(concreteContext);
}
- PHPVersion phpVersion = concreteContext.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
Set<String> magicMethods = new HashSet<>();
magicMethods.addAll(Arrays.asList(PHPMagicMethods.getMethods(phpVersion)));
boolean exactName = requestor.isContextInformationMode();
// for methodName(|),we need set exactName to true
- if (!exactName && concreteContext.getOffset() - 1 >= 0
- && concreteContext.getDocument().getChar(concreteContext.getOffset() - 1) == '(') {
+ if (!exactName && getCompanion().getOffset() - 1 >= 0
+ && getCompanion().getDocument().getChar(getCompanion().getOffset() - 1) == '(') {
exactName = true;
}
List<IMethod> result = new LinkedList<>();
+ boolean inUseTrait = getCompanion().getScope().findParent(Type.TRAIT_USE) != null;
for (IType type : concreteContext.getLhsTypes()) {
try {
ITypeHierarchy hierarchy = getCompanion().getSuperTypeHierarchy(type, null);
@@ -90,7 +92,7 @@ public class ClassMethodsStrategy extends ClassMembersStrategy {
boolean inConstructor = isInConstructor(type, type.getMethods(), concreteContext);
for (IMethod method : removeOverriddenElements(Arrays.asList(methods))) {
- if (concreteContext.isInUseTraitStatement()) {
+ if (inUseTrait) {
// result.add(method);
reporter.reportMethod(method, "", //$NON-NLS-1$
replaceRange, ProposalExtraInfo.METHOD_ONLY | ProposalExtraInfo.FULL_NAME);
@@ -120,7 +122,7 @@ public class ClassMethodsStrategy extends ClassMembersStrategy {
IMethod method = methods[i];
if (PHPModelUtils.isConstructor(method) && method.getDeclaringType().equals(type)) {
ISourceRange constructorRange = method.getSourceRange();
- if (concreteContext.getOffset() > constructorRange.getOffset() && concreteContext
+ if (getCompanion().getOffset() > constructorRange.getOffset() && getCompanion()
.getOffset() < constructorRange.getOffset() + constructorRange.getLength()) {
return true;
}
@@ -167,8 +169,8 @@ public class ClassMethodsStrategy extends ClassMembersStrategy {
public String getSuffix(AbstractCompletionContext abstractContext) throws BadLocationException {
// look for method bracket or end of line
- IDocument document = abstractContext.getDocument();
- int offset = abstractContext.getOffset();
+ IDocument document = getCompanion().getDocument();
+ int offset = getCompanion().getOffset();
while (document.getLength() > offset) {
char ch = document.getChar(offset);
if (ch == '(') {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassPropertiesStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassPropertiesStrategy.java
index 15c7093f4..f6cb851ae 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassPropertiesStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ClassPropertiesStrategy.java
@@ -49,10 +49,10 @@ public class ClassPropertiesStrategy extends AbstractCompletionStrategy {
AbstractCompletionContext abstractContext = (AbstractCompletionContext) getContext();
CompletionRequestor requestor = abstractContext.getCompletionRequestor();
- int offset = abstractContext.getOffset();
+ int offset = abstractContext.getCompanion().getOffset();
// find class properties
- ISourceModule sourceModule = abstractContext.getSourceModule();
+ ISourceModule sourceModule = abstractContext.getCompanion().getSourceModule();
ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule, null);
List<PHPFieldDeclaration> declarations = ASTUtils.findClassPropertiesAfterPHPdoc(moduleDeclaration, offset);
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 1018d9019..8741ecb48 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
@@ -23,6 +23,7 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionContextResolver;
+import org.eclipse.php.core.codeassist.ICompletionScope.Type;
import org.eclipse.php.core.codeassist.ICompletionStrategy;
import org.eclipse.php.core.codeassist.ICompletionStrategyFactory;
import org.eclipse.php.internal.core.PHPCorePlugin;
@@ -137,8 +138,10 @@ public class CompletionStrategyFactory implements ICompletionStrategyFactory {
return new ICompletionStrategy[] { new MethodNameStrategy(context) };
}
- if (contextClass == ClassStatementContext.class) {
- if (((AbstractCompletionContext) context).isInUseTraitStatement()) {
+ if (contextClass == TypeStatementContext.class) {
+ boolean inUseTrait = ((AbstractCompletionContext) context).getCompanion().getScope()
+ .findParent(Type.TRAIT_USE) != null;
+ if (inUseTrait) {
int type = ((AbstractCompletionContext) context).getUseTraitStatementContext();
if (type == AbstractCompletionContext.TRAIT_NAME) {
return new ICompletionStrategy[] { new InUseTraitStrategy(context) };
@@ -147,7 +150,7 @@ public class CompletionStrategyFactory implements ICompletionStrategyFactory {
} else {
return new ICompletionStrategy[] {};
}
- } else if (((ClassStatementContext) context).isAssignment()) {
+ } else if (((TypeStatementContext) context).isAssignment()) {
return new ICompletionStrategy[] { new ClassKeywordsStrategy(context), new ConstantsStrategy(context),
new TypesStrategy(context) };
} else {
@@ -184,7 +187,9 @@ public class CompletionStrategyFactory implements ICompletionStrategyFactory {
// new ClassMethodsStrategy(context) };
// }
if (contextClass == ClassStaticMemberContext.class || contextClass == ClassObjMemberContext.class) {
- if (((AbstractCompletionContext) context).isInUseTraitStatement()) {
+ boolean inUseTrait = ((AbstractCompletionContext) context).getCompanion().getScope()
+ .findParent(Type.TRAIT_USE) != null;
+ if (inUseTrait) {
int type = ((AbstractCompletionContext) context).getUseTraitStatementContext();
if (type == AbstractCompletionContext.TRAIT_NAME) {
return new ICompletionStrategy[] { new InUseTraitStrategy(context) };
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ConstantsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ConstantsStrategy.java
index 8d96f9920..798bf9f8f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ConstantsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ConstantsStrategy.java
@@ -86,11 +86,11 @@ public class ConstantsStrategy extends ElementsStrategy {
matchRule = MatchRule.EXACT;
}
- ISourceModule sourceModule = abstractContext.getSourceModule();
+ ISourceModule sourceModule = getCompanion().getSourceModule();
IType enclosingType = null;
try {
- IModelElement enclosingElement = sourceModule.getElementAt(abstractContext.getOffset());
+ IModelElement enclosingElement = sourceModule.getElementAt(getCompanion().getOffset());
if (enclosingElement != null && enclosingElement instanceof IType) {
enclosingType = (IType) enclosingElement;
@@ -104,7 +104,7 @@ public class ConstantsStrategy extends ElementsStrategy {
IModelElement[] enclosingTypeConstants = null;
if (enclosingType != null && nsUseGroupPrefix != null
- && isStartOfStatement(prefix, abstractContext, abstractContext.getOffset())) {
+ && isStartOfStatement(prefix, abstractContext, getCompanion().getOffset())) {
// See the case of testClassStatement1.pdtt and
// testClassStatement2.pdtt
scope = SearchEngine.createSearchScope(enclosingType);
@@ -143,7 +143,7 @@ public class ConstantsStrategy extends ElementsStrategy {
ISourceRange replacementRange = getReplacementRange(abstractContext);
ISourceRange memberReplacementRange = getReplacementRangeForMember(abstractContext);
boolean isAbsoluteField = abstractContext.isAbsoluteName() || abstractContext.isAbsolute();
- String namespace = abstractContext.getCurrentNamespace();
+ String namespace = getCompanion().getCurrentNamespace();
for (IModelElement constant : enclosingTypeConstants) {
IField field = (IField) constant;
if (nsUseGroupPrefix != null) {
@@ -171,8 +171,8 @@ public class ConstantsStrategy extends ElementsStrategy {
IModuleSource module = reporter.getModule();
org.eclipse.dltk.core.ISourceModule sourceModule = (org.eclipse.dltk.core.ISourceModule) module
.getModelElement();
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
- final int offset = abstractContext.getOffset();
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
+ final int offset = getCompanion().getOffset();
IType namespace = PHPModelUtils.getCurrentNamespace(sourceModule, offset);
final Map<String, UsePart> result = PHPModelUtils.getAliasToNSMap(prefix, moduleDeclaration, offset, namespace,
@@ -210,7 +210,7 @@ public class ConstantsStrategy extends ElementsStrategy {
}
private boolean isStartOfStatement(String prefix, AbstractCompletionContext abstractContext, int offset) {
- IDocument doc = abstractContext.getDocument();
+ IDocument doc = getCompanion().getDocument();
try {
int pos = offset - prefix.length() - 1;
char previousChar = doc.getChar(pos);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ElementsCompositeStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ElementsCompositeStrategy.java
index 0a10b8355..86d0bd231 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ElementsCompositeStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ElementsCompositeStrategy.java
@@ -16,6 +16,7 @@ package org.eclipse.php.internal.core.codeassist.strategies;
import java.util.ArrayList;
import java.util.Collection;
+import org.eclipse.php.core.codeassist.CompletionCompanion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionReporter;
import org.eclipse.php.core.codeassist.ICompletionStrategy;
@@ -39,6 +40,7 @@ public class ElementsCompositeStrategy extends AbstractCompletionStrategy {
if (includeKeywords) {
strategies.add(new GlobalKeywordsStrategy(context));
}
+
}
@Override
@@ -47,4 +49,12 @@ public class ElementsCompositeStrategy extends AbstractCompletionStrategy {
strategy.apply(reporter);
}
}
+
+ @Override
+ public void init(CompletionCompanion companion) {
+ super.init(companion);
+ for (ICompletionStrategy strategy : strategies) {
+ strategy.init(companion);
+ }
+ }
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ExceptionClassInstantiationStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ExceptionClassInstantiationStrategy.java
index 143032cb4..d5be7d8b5 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ExceptionClassInstantiationStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/ExceptionClassInstantiationStrategy.java
@@ -43,7 +43,7 @@ public class ExceptionClassInstantiationStrategy extends AbstractClassInstantiat
}
List<IType> result = new LinkedList<>();
ITypeHierarchy typeHierarchy;
- ISourceModule sourceModule = context.getSourceModule();
+ ISourceModule sourceModule = getCompanion().getSourceModule();
IScriptProject scriptProject = sourceModule.getScriptProject();
try {
if (scriptProject != null) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionArgumentsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionArgumentsStrategy.java
index f0c6a3531..7a8f0688a 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionArgumentsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionArgumentsStrategy.java
@@ -22,7 +22,6 @@ import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.core.CompletionRequestor;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.dltk.core.ISourceRange;
-import org.eclipse.dltk.core.SourceParserUtil;
import org.eclipse.dltk.internal.core.ModelElement;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.php.core.codeassist.ICompletionContext;
@@ -54,11 +53,11 @@ public class FunctionArgumentsStrategy extends AbstractCompletionStrategy {
AbstractCompletionContext abstractContext = (AbstractCompletionContext) getContext();
CompletionRequestor requestor = abstractContext.getCompletionRequestor();
- int offset = abstractContext.getOffset();
+ int offset = getCompanion().getOffset();
// find function arguments
- ISourceModule sourceModule = abstractContext.getSourceModule();
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule, null);
+ ISourceModule sourceModule = getCompanion().getSourceModule();
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
Declaration declaration = ASTUtils.findDeclarationAfterPHPdoc(moduleDeclaration, offset);
if (declaration instanceof MethodDeclaration) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterKeywordTypeStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterKeywordTypeStrategy.java
index 2aed01d9c..0f737243f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterKeywordTypeStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterKeywordTypeStrategy.java
@@ -61,7 +61,8 @@ public class FunctionParameterKeywordTypeStrategy extends KeywordsStrategy {
try {
int flags = context.getEnclosingType().getFlags();
if (!PHPFlags.isNamespace(flags)) {
- String pref = PHPVersion.PHP5_4.isLessThan(context.getPHPVersion()) ? prefix.toLowerCase() : prefix;
+ String pref = PHPVersion.PHP5_4.isLessThan(getCompanion().getPHPVersion()) ? prefix.toLowerCase()
+ : prefix;
for (String keyword : KEYWORDS) {
if (keyword.startsWith(pref)) {
@@ -74,7 +75,7 @@ public class FunctionParameterKeywordTypeStrategy extends KeywordsStrategy {
}
}
- PHPVersion phpVersion = context.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
for (SimpleProposal proposal : SimpleProposal.BASIC_TYPES) {
if (proposal.isValidPrefix(prefix, phpVersion)) {
reporter.reportKeyword(proposal.getProposal(), suffix, replaceRange);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterTypeStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterTypeStrategy.java
index cac984d2e..9aec526e3 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterTypeStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionParameterTypeStrategy.java
@@ -40,7 +40,7 @@ public class FunctionParameterTypeStrategy extends TypesStrategy {
@Override
public String getSuffix(AbstractCompletionContext abstractContext) {
- return isInsertMode() && abstractContext.hasSpaceAtPosition(abstractContext.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
+ return isInsertMode() && abstractContext.hasSpaceAtPosition(getCompanion().getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionReturnTypeStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionReturnTypeStrategy.java
index a763da8aa..3ac50f2a0 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionReturnTypeStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionReturnTypeStrategy.java
@@ -46,7 +46,7 @@ public class FunctionReturnTypeStrategy extends TypesStrategy {
String prefix = context.getPrefix();
String suffix = ""; //$NON-NLS-1$
ISourceRange replaceRange = getReplacementRange(context);
- PHPVersion phpVersion = context.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
for (SimpleProposal proposal : TYPES) {
if (proposal.isValidPrefix(prefix, phpVersion)) {
reporter.reportKeyword(proposal.getProposal(), suffix, replaceRange);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionsStrategy.java
index 998ffdb88..99210e9e6 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/FunctionsStrategy.java
@@ -98,7 +98,7 @@ public class FunctionsStrategy extends ElementsStrategy {
ISourceRange memberReplacementRange = getReplacementRangeForMember(abstractContext);
boolean isAbsoluteMethod = abstractContext.isAbsoluteName() || abstractContext.isAbsolute();
String suffix = getSuffix(abstractContext);
- String namespace = abstractContext.getCurrentNamespace();
+ String namespace = getCompanion().getCurrentNamespace();
for (IMethod method : functions) {
if (nsUseGroupPrefix != null) {
reporter.reportMethod(method, nsUseGroupPrefix, suffix, memberReplacementRange, extraInfo,
@@ -126,8 +126,8 @@ public class FunctionsStrategy extends ElementsStrategy {
IModuleSource module = reporter.getModule();
org.eclipse.dltk.core.ISourceModule sourceModule = (org.eclipse.dltk.core.ISourceModule) module
.getModelElement();
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
- final int offset = abstractContext.getOffset();
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
+ final int offset = getCompanion().getOffset();
IType namespace = PHPModelUtils.getCurrentNamespace(sourceModule, offset);
final Map<String, UsePart> result = PHPModelUtils.getAliasToNSMap(prefix, moduleDeclaration, offset, namespace,
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GotoStatementStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GotoStatementStrategy.java
index 30fb68257..a45197ae4 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GotoStatementStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GotoStatementStrategy.java
@@ -22,7 +22,6 @@ import org.eclipse.dltk.ast.declarations.MethodDeclaration;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.ast.declarations.TypeDeclaration;
import org.eclipse.dltk.core.ISourceRange;
-import org.eclipse.dltk.core.SourceParserUtil;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionReporter;
@@ -56,7 +55,7 @@ public class GotoStatementStrategy extends ElementsStrategy {
return;
}
try {
- ModuleDeclaration rootNode = SourceParserUtil.getModuleDeclaration(gotoStatementContext.getSourceModule());
+ ModuleDeclaration rootNode = getCompanion().getModuleDeclaration();
ASTNode node;
if (gotoStatementContext.getCurrentElement() != null) {
node = PHPModelUtils.getNodeByElement(rootNode, gotoStatementContext.getCurrentElement());
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
index 15c713338..5e614c165 100644
--- 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
@@ -15,10 +15,10 @@ package org.eclipse.php.internal.core.codeassist.strategies;
import org.eclipse.dltk.core.ISourceRange;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionReporter;
import org.eclipse.php.core.codeassist.IElementFilter;
-import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext;
import org.eclipse.php.internal.core.language.keywords.PHPKeywords.KeywordData;
@@ -65,7 +65,7 @@ public class InUseTraitKeywordStrategy extends KeywordsStrategy {
// }
// }
- PHPVersion phpVersion = context.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
if (phpVersion.isGreaterThan(PHPVersion.PHP5_3)) {
for (String keyword : KEYWORDS) {
if (keyword.startsWith(prefix)) {
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
index c146c7b42..6cc3a1473 100644
--- 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
@@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.php.internal.core.codeassist.strategies;
+import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
@@ -20,21 +22,32 @@ import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.dltk.core.ISourceRange;
import org.eclipse.dltk.core.IType;
-import org.eclipse.dltk.core.SourceParserUtil;
import org.eclipse.dltk.ti.types.IEvaluatedType;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionReporter;
import org.eclipse.php.core.codeassist.IElementFilter;
import org.eclipse.php.internal.core.codeassist.ProposalExtraInfo;
import org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext;
+import org.eclipse.php.internal.core.documentModel.parser.PHPRegionContext;
+import org.eclipse.php.internal.core.documentModel.parser.regions.IPHPScriptRegion;
+import org.eclipse.php.internal.core.documentModel.parser.regions.PHPRegionTypes;
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;
+import org.eclipse.php.internal.core.util.text.PHPTextSequenceUtilities;
+import org.eclipse.php.internal.core.util.text.TextSequence;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
/**
* This strategy completes builtin array keys, like in _SERVER.
*
+ * body only
+ *
* @author michael
*/
public class InUseTraitStrategy extends AbstractCompletionStrategy {
@@ -47,6 +60,85 @@ public class InUseTraitStrategy extends AbstractCompletionStrategy {
super(context);
}
+ private List<String> getUseTypes() {
+ List<String> useTypes = new LinkedList<>();
+ if (getCompanion().getPHPVersion().isLessThan(PHPVersion.PHP5_4)) {
+ return useTypes;
+ }
+ IStructuredDocumentRegion sdRegion = getCompanion().getStructuredDocumentRegion();
+ int documentOffset = getCompanion().getOffset();
+ if (documentOffset == sdRegion.getEndOffset()) {
+ documentOffset -= 1;
+ }
+ ITextRegion tRegion = sdRegion.getRegionAtCharacterOffset(documentOffset);
+
+ ITextRegionCollection container = sdRegion;
+
+ if (tRegion instanceof ITextRegionContainer) {
+ container = (ITextRegionContainer) tRegion;
+ tRegion = container.getRegionAtCharacterOffset(getCompanion().getOffset());
+ }
+ 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(getCompanion().getOffset() - startOffset - 1);
+ }
+ // If statement start is at the beginning of the PHP script
+ // region:
+ while (true) {
+ if (startTokenRegion.getStart() == 0) {
+ return useTypes;
+ }
+ 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 = PHPTextSequenceUtilities.getStatement(
+ startOffset + startTokenRegion.getStart() - 1,
+ getCompanion().getStructuredDocumentRegion(), true);
+ startTokenRegion = phpScriptRegion
+ .getPHPToken(startTokenRegion.getStart() - statementText1.length());
+ if (startTokenRegion.getType() == PHPRegionTypes.PHP_USE) {
+ String[] types = statementText1.toString().trim().substring(3).trim().split(","); //$NON-NLS-1$
+ useTypes = new ArrayList<>();
+ for (String type : types) {
+ useTypes.add(type.trim());
+ }
+ return useTypes;
+ } else {
+ return useTypes;
+ }
+ } else if (startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_CLOSE) {
+ return useTypes;
+ }
+
+ startTokenRegion = phpScriptRegion.getPHPToken(startTokenRegion.getStart() - 1);
+ }
+
+ } catch (BadLocationException e) {
+ }
+ }
+
+ return useTypes;
+
+ }
+
@Override
public void apply(ICompletionReporter reporter) throws BadLocationException {
ICompletionContext context = getContext();
@@ -55,11 +147,12 @@ public class InUseTraitStrategy extends AbstractCompletionStrategy {
}
AbstractCompletionContext abstractContext = (AbstractCompletionContext) context;
- int offset = abstractContext.getOffset();
- ISourceModule sourceModule = abstractContext.getSourceModule();
- List<String> useTypes = abstractContext.getUseTypes();
+
+ int offset = getCompanion().getOffset();
+ ISourceModule sourceModule = getCompanion().getSourceModule();
+ List<String> useTypes = getUseTypes();
String prefix = abstractContext.getPrefix();
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule, null);
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
FileContext fileContext = new FileContext(sourceModule, moduleDeclaration, offset);
ISourceRange replacementRange = getReplacementRange(abstractContext);
for (String useType : useTypes) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/IncludeStatementStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/IncludeStatementStrategy.java
index 0b905d187..d46206850 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/IncludeStatementStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/IncludeStatementStrategy.java
@@ -60,7 +60,7 @@ public class IncludeStatementStrategy extends AbstractCompletionStrategy {
String prefix = includeContext.getPrefix();
ISourceRange replaceRange = getReplacementRange(includeContext);
- final ISourceModule sourceModule = includeContext.getSourceModule();
+ final ISourceModule sourceModule = getCompanion().getSourceModule();
if (sourceModule == null || sourceModule.getScriptProject() == null) {
if (DLTKCore.DEBUG_COMPLETION) {
System.out.println("Unable to locate source module or project"); //$NON-NLS-1$
@@ -295,7 +295,7 @@ public class IncludeStatementStrategy extends AbstractCompletionStrategy {
}
if (resource.getType() == IResource.FILE) {
if (PHPToolkitUtil.isPHPFile((IFile) resource)
- && !modelElement.equals(((IncludeStatementContext) context).getSourceModule())) {
+ && !modelElement.equals(getCompanion().getSourceModule())) {
reporter.reportResource(modelElement, rel, getSuffix(modelElement), replaceRange);
}
} else {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InterfaceDeclarationKeywordsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InterfaceDeclarationKeywordsStrategy.java
index e7d2c4736..bd157955d 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InterfaceDeclarationKeywordsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/InterfaceDeclarationKeywordsStrategy.java
@@ -60,6 +60,6 @@ public class InterfaceDeclarationKeywordsStrategy extends AbstractCompletionStra
}
public String getSuffix(AbstractCompletionContext abstractContext) {
- return isInsertMode() && abstractContext.hasSpaceAtPosition(abstractContext.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
+ return isInsertMode() && abstractContext.hasSpaceAtPosition(getCompanion().getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/KeywordsStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/KeywordsStrategy.java
index 96dcbf243..ac3ffc1fc 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/KeywordsStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/KeywordsStrategy.java
@@ -47,7 +47,7 @@ public abstract class KeywordsStrategy extends ElementsStrategy {
ICompletionContext context = getContext();
AbstractCompletionContext concreteContext = (AbstractCompletionContext) context;
- ISourceModule sourceModule = concreteContext.getSourceModule();
+ ISourceModule sourceModule = getCompanion().getSourceModule();
String prefix = concreteContext.getPrefix();
ISourceRange replaceRange = getReplacementRange(concreteContext);
Collection<KeywordData> keywordsList = PHPKeywords.getInstance(sourceModule.getScriptProject().getProject())
@@ -69,12 +69,12 @@ public abstract class KeywordsStrategy extends ElementsStrategy {
AbstractCompletionContext context = (AbstractCompletionContext) getContext();
int offset;
if (isInsertMode()) {
- offset = context.getOffset();
+ offset = getCompanion().getOffset();
} else {
offset = replaceRange.getOffset() + replaceRange.getLength();
}
try {
- String realSuffix = context.getDocument().get(offset, suffix.length());
+ String realSuffix = getCompanion().getDocument().get(offset, suffix.length());
if (suffix.equals(realSuffix)) {
// return empty suffix if exists in target document
return StringUtils.EMPTY;
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategy.java
index a807ea0b7..ff57ed733 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategy.java
@@ -77,7 +77,7 @@ public class LocalMethodVariablesStrategy extends ElementsStrategy {
}
} else {
if (enclosingMethod.getParent() instanceof IField
- && concreteContext.getPHPVersion().isGreaterThan(PHPVersion.PHP5_3)) {
+ && getCompanion().getPHPVersion().isGreaterThan(PHPVersion.PHP5_3)) {
IMethod method = (IMethod) enclosingMethod.getParent().getAncestor(IModelElement.METHOD);
if (method != null) {
declaringType = method.getDeclaringType();
@@ -96,12 +96,12 @@ public class LocalMethodVariablesStrategy extends ElementsStrategy {
ICompletionReporter.RELEVANCE_ADJUST, null);
}
- PHPVersion phpVersion = concreteContext.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
for (String variable : PHPVariables.getVariables(phpVersion, PHPVariables.SUPER_GLOBAL)) {
if (variable.startsWith(prefix)) {
if (!requestor.isContextInformationMode() || variable.length() == prefix.length()) {
- reporter.reportField(
- new FakeField((ModelElement) concreteContext.getSourceModule(), variable, 0, 0), "", //$NON-NLS-1$
+ reporter.reportField(new FakeField((ModelElement) getCompanion().getSourceModule(), variable, 0, 0),
+ "", //$NON-NLS-1$
replaceRange, false, -ICompletionReporter.RELEVANCE_ADJUST, null);
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategyForArray.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategyForArray.java
index ba56f0823..72efb3ce4 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategyForArray.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodVariablesStrategyForArray.java
@@ -45,7 +45,7 @@ public class LocalMethodVariablesStrategyForArray extends AbstractCompletionStra
CompletionRequestor requestor = arrayContext.getCompletionRequestor();
IModelElement enclosingElement;
try {
- enclosingElement = arrayContext.getSourceModule().getElementAt(arrayContext.getOffset());
+ enclosingElement = getCompanion().getSourceModule().getElementAt(getCompanion().getOffset());
while (enclosingElement instanceof IField) {
enclosingElement = enclosingElement.getParent();
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java
index 97e009dcd..9cf367ff3 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java
@@ -16,11 +16,10 @@ package org.eclipse.php.internal.core.codeassist.strategies;
import org.eclipse.dltk.core.IType;
import org.eclipse.dltk.core.ITypeHierarchy;
import org.eclipse.dltk.core.ModelException;
+import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.IElementFilter;
import org.eclipse.php.core.compiler.PHPFlags;
-import org.eclipse.php.core.PHPVersion;
-import org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext;
import org.eclipse.php.internal.core.codeassist.contexts.GlobalMethodStatementContext;
import org.eclipse.php.internal.core.language.keywords.PHPKeywords;
import org.eclipse.php.internal.core.language.keywords.PHPKeywords.KeywordData;
@@ -83,7 +82,7 @@ public class MethodKeywordStrategy extends KeywordsStrategy {
protected boolean isParent(KeywordData keyword) {
String name = keyword.name;
- if (PHPVersion.PHP5_4.isLessThan(((AbstractCompletionContext) getContext()).getPHPVersion())) {
+ if (PHPVersion.PHP5_4.isLessThan(getCompanion().getPHPVersion())) {
name = name.toLowerCase();
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodNameStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodNameStrategy.java
index c13c4defa..a16b131ab 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodNameStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodNameStrategy.java
@@ -91,7 +91,7 @@ public class MethodNameStrategy extends AbstractCompletionStrategy {
PHPCorePlugin.log(e);
}
- PHPVersion phpVersion = concreteContext.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
// Add magic methods:
Set<String> functions = new TreeSet<>();
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocParamVariableStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocParamVariableStrategy.java
index 304f5c59d..4916f11d2 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocParamVariableStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocParamVariableStrategy.java
@@ -47,6 +47,7 @@ public class PHPDocParamVariableStrategy extends FunctionArgumentsStrategy {
super.apply(reporter);
} else {
final PHPDocReturnTypeStrategy returnStrategy = new PHPDocReturnTypeStrategy(context);
+ returnStrategy.init(getCompanion());
returnStrategy.apply(reporter);
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocVarVariableStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocVarVariableStrategy.java
index 8f104b241..f08546971 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocVarVariableStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PHPDocVarVariableStrategy.java
@@ -45,6 +45,7 @@ public class PHPDocVarVariableStrategy extends ClassPropertiesStrategy {
super.apply(reporter);
} else {
final PHPDocReturnTypeStrategy returnStrategy = new PHPDocReturnTypeStrategy(context);
+ returnStrategy.init(getCompanion());
returnStrategy.apply(reporter);
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/TypesStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/TypesStrategy.java
index 561aa07fd..24cee789d 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/TypesStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/TypesStrategy.java
@@ -21,7 +21,6 @@ import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
-import org.eclipse.dltk.compiler.env.IModuleSource;
import org.eclipse.dltk.core.*;
import org.eclipse.dltk.core.index2.search.ISearchEngine.MatchRule;
import org.eclipse.dltk.core.search.IDLTKSearchScope;
@@ -110,7 +109,7 @@ public class TypesStrategy extends ElementsStrategy {
extraInfo |= ProposalExtraInfo.NO_INSERT_USE;
}
- String namespace = abstractContext.getCurrentNamespace();
+ String namespace = getCompanion().getCurrentNamespace();
for (IType type : types) {
try {
int flags = type.getFlags();
@@ -158,23 +157,20 @@ public class TypesStrategy extends ElementsStrategy {
}
if (prefix.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) < 0) {
- IModuleSource module = reporter.getModule();
- org.eclipse.dltk.core.ISourceModule sourceModule = (org.eclipse.dltk.core.ISourceModule) module
- .getModelElement();
- ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
- final int offset = abstractContext.getOffset();
- IType namespace = PHPModelUtils.getCurrentNamespace(sourceModule, offset);
+ ModuleDeclaration moduleDeclaration = getCompanion().getModuleDeclaration();
+ final int offset = getCompanion().getOffset();
+ IType namespace = PHPModelUtils.getCurrentNamespace(getCompanion().getSourceModule(), offset);
final Map<String, UsePart> result = PHPModelUtils.getAliasToNSMap(prefix, moduleDeclaration, offset,
namespace, exactMatch);
- reportAlias(reporter, suffix, abstractContext, module, result);
+ reportAlias(reporter, suffix, abstractContext, getCompanion().getSourceModule(), result);
}
}
}
protected void reportAliasForNS(ICompletionReporter reporter, String suffix,
- AbstractCompletionContext abstractContext, IModuleSource module, final Map<String, UsePart> result)
+ AbstractCompletionContext abstractContext, ISourceModule module, final Map<String, UsePart> result)
throws BadLocationException {
ISourceRange replacementRange = getReplacementRange(abstractContext);
IDLTKSearchScope scope = createSearchScope();
@@ -191,7 +187,7 @@ public class TypesStrategy extends ElementsStrategy {
}
protected void reportAlias(ICompletionReporter reporter, String suffix, AbstractCompletionContext abstractContext,
- IModuleSource module, final Map<String, UsePart> result) throws BadLocationException {
+ ISourceModule module, final Map<String, UsePart> result) throws BadLocationException {
ISourceRange replacementRange = getReplacementRange(abstractContext);
String prefix = abstractContext.getPrefix();
IDLTKSearchScope scope = createSearchScope();
@@ -237,7 +233,7 @@ public class TypesStrategy extends ElementsStrategy {
}
}
- protected void reportAlias(ICompletionReporter reporter, IDLTKSearchScope scope, IModuleSource module,
+ protected void reportAlias(ICompletionReporter reporter, IDLTKSearchScope scope, ISourceModule module,
ISourceRange replacementRange, IType type, String fullName, String alias, String suffix) {
reporter.reportType(new AliasType((ModelElement) type, fullName, alias), suffix, replacementRange,
getExtraInfo());
@@ -272,8 +268,8 @@ public class TypesStrategy extends ElementsStrategy {
String altNamespacePrefix = null;
if (namespaceName != null) {
sb.append(namespaceName).append(NamespaceReference.NAMESPACE_SEPARATOR);
- } else if (!isAbsoluteType && context.getCurrentNamespace() != null && useCurrentNamespace) {
- altNamespacePrefix = new StringBuilder().append(context.getCurrentNamespace())
+ } else if (!isAbsoluteType && getCompanion().getCurrentNamespace() != null && useCurrentNamespace) {
+ altNamespacePrefix = new StringBuilder().append(getCompanion().getCurrentNamespace())
.append(NamespaceReference.NAMESPACE_SEPARATOR).append(memberName).toString();
}
String namespacePrefix = sb.append(memberName).toString();
@@ -333,7 +329,8 @@ public class TypesStrategy extends ElementsStrategy {
// get the class data for "self". In case of null, the self
// function will not be added
- IType selfClassData = CodeAssistUtils.getSelfClassData(context.getSourceModule(), context.getOffset());
+ IType selfClassData = CodeAssistUtils.getSelfClassData(getCompanion().getSourceModule(),
+ getCompanion().getOffset());
if (selfClassData != null) {
try {
IMethod ctor = null;
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseFunctionStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseFunctionStrategy.java
index 3e0dd3ba3..15c22f8df 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseFunctionStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseFunctionStrategy.java
@@ -49,7 +49,7 @@ public class UseFunctionStrategy extends FunctionsStrategy {
@Override
public String getSuffix(AbstractCompletionContext abstractContext) {
- return isInsertMode() && abstractContext.hasSpaceAtPosition(abstractContext.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
+ return isInsertMode() && abstractContext.hasSpaceAtPosition(getCompanion().getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseNameStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseNameStrategy.java
index 4aa98f2e0..46a241405 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseNameStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/UseNameStrategy.java
@@ -79,7 +79,7 @@ public class UseNameStrategy extends TypesStrategy {
@Override
public String getSuffix(AbstractCompletionContext abstractContext) {
- return isInsertMode() && abstractContext.hasSpaceAtPosition(abstractContext.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
+ return isInsertMode() && abstractContext.hasSpaceAtPosition(getCompanion().getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/VariablesStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/VariablesStrategy.java
index fc219f0d3..aab777a71 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/VariablesStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/VariablesStrategy.java
@@ -87,7 +87,7 @@ public class VariablesStrategy extends ElementsStrategy {
} else if (showVarsFromOtherFiles(PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_REFERENCED_FILES)) {
// FIXME why we can't get $myGlobalVar from php
// code:list($myGlobalVar) = 0;
- IDLTKSearchScope scope = createSearchScopeWithReferencedFiles(abstractContext.getSourceModule());
+ IDLTKSearchScope scope = createSearchScopeWithReferencedFiles(getCompanion().getSourceModule());
fields = PHPModelAccess.getDefault().findFileFields(prefix, matchRule, Modifiers.AccGlobal,
Modifiers.AccConstant, scope, null);
}
@@ -97,7 +97,7 @@ public class VariablesStrategy extends ElementsStrategy {
result.addAll(Arrays.asList(fields));
}
- fields = PHPModelUtils.getFileFields(abstractContext.getSourceModule(), prefix, false, null);
+ fields = PHPModelUtils.getFileFields(getCompanion().getSourceModule(), prefix, false, null);
if (fields != null) {
result.addAll(Arrays.asList(fields));
}
@@ -109,12 +109,12 @@ public class VariablesStrategy extends ElementsStrategy {
}
if (showPhpVariables) {
- PHPVersion phpVersion = abstractContext.getPHPVersion();
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
for (String variable : PHPVariables.getVariables(phpVersion)) {
if (variable.startsWith(prefix)) {
if (!requestor.isContextInformationMode() || variable.length() == prefix.length()) {
reporter.reportField(
- new FakeField((ModelElement) abstractContext.getSourceModule(), variable, 0, 0), "", //$NON-NLS-1$
+ new FakeField((ModelElement) getCompanion().getSourceModule(), variable, 0, 0), "", //$NON-NLS-1$
replaceRange, false);
}
}
@@ -157,7 +157,7 @@ public class VariablesStrategy extends ElementsStrategy {
AbstractCompletionContext abstractContext = (AbstractCompletionContext) context;
try {
if (StringUtils.isBlank(abstractContext.getPrefix())) {
- ISourceModule sourceModule = ((AbstractCompletionContext) context).getSourceModule();
+ ISourceModule sourceModule = getCompanion().getSourceModule();
return SearchEngine.createSearchScope(sourceModule);
}
} catch (BadLocationException e) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java
index 4180e009e..09f186aaf 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java
@@ -542,87 +542,101 @@ public final class PHPHeuristicScanner implements Symbols {
switch (s.length()) {
case 2:
- if ("if".equals(s)) {
+ if ("if".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenIF;
}
- if ("do".equals(s)) {
+ if ("do".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenDO;
}
break;
case 3:
- if ("for".equals(s)) {
+ if ("for".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenFOR;
}
- if ("try".equals(s)) {
+ if ("try".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenTRY;
}
- if ("new".equals(s)) {
+ if ("new".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenNEW;
}
break;
case 4:
- if ("case".equals(s)) {
+ if ("case".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenCASE;
}
- if ("else".equals(s)) {
+ if ("else".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenELSE;
}
- if ("enum".equals(s)) {
- return TokenENUM;
- }
- if ("goto".equals(s)) {
+ if ("goto".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenGOTO;
}
break;
case 5:
- if ("break".equals(s)) {
+
+ if ("break".equalsIgnoreCase(s)) { //$NON-NLS-1$
return TokenBREAK;
}
- if ("catch".equals(s)) {
+ if ("catch".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenCATCH;
}
- if ("class".equals(s)) {
+ if ("class".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenCLASS;
}
- if ("while".equals(s)) {
+ if ("while".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenWHILE;
}
- if ("array".equals(s)) {
+ if ("array".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenARRAY;
}
+ if ("trait".equalsIgnoreCase(s)) {// $NON-NLS-1$
+ return TokenTRAIT;
+ }
+ if ("endif".equalsIgnoreCase(s)) {// $NON-NLS-1$
+ return TokenENDIF;
+ }
break;
case 6:
- if ("return".equals(s)) {
+ if ("return".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenRETURN;
}
- if ("static".equals(s)) {
+ if ("static".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenSTATIC;
}
- if ("switch".equals(s)) {
+ if ("switch".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenSWITCH;
}
+ if ("elseif".equalsIgnoreCase(s)) {//$NON-NLS-1$
+ return TokenELSEIF;
+ }
break;
case 7:
- if ("default".equals(s)) {
+ if ("default".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenDEFAULT;
}
- if ("finally".equals(s)) {
+ if ("finally".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenFINALLY;
}
- if ("foreach".equals(s)) {
+ if ("foreach".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenFOR;
}
+ if ("endfor".equals(s)) { // $NON-NLS-1$
+ return TokenENDFOR;
+ }
+ break;
+ case 8:
+ if ("endwhile".equalsIgnoreCase(s)) {//$NON-NLS-1$
+ return TokenENDWHILE;
+ }
break;
case 9:
- if ("interface".equals(s)) {
+ if ("interface".equalsIgnoreCase(s)) {//$NON-NLS-1$
return TokenINTERFACE;
}
- break;
- case 12:
- if ("synchronized".equals(s)) {
- return TokenSYNCHRONIZED;
+ if ("endswitch".equalsIgnoreCase(s)) {//$NON-NLS-1$
+ return TokenENDWITCH;
}
break;
+
}
return TokenIDENT;
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/Symbols.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/Symbols.java
index d8a8f3bf2..9a0d7f436 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/Symbols.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/Symbols.java
@@ -50,13 +50,19 @@ public interface Symbols {
int TokenSTATIC = 1019;
int TokenSWITCH = 1020;
int TokenFINALLY = 1021;
- int TokenSYNCHRONIZED = 1022;
+ // int TokenSYNCHRONIZED = 1022;
int TokenGOTO = 1023;
int TokenDEFAULT = 1024;
int TokenNEW = 1025;
int TokenCLASS = 1026;
int TokenINTERFACE = 1027;
- int TokenENUM = 1028;
+ // int TokenENUM = 1028;
int TokenARRAY = 1029;
+ int TokenTRAIT = 1030;
+ int TokenENDIF = 1031;
+ int TokenENDFOR = 1032;
+ int TokenENDWHILE = 1033;
+ int TokenENDWITCH = 1034;
+ int TokenELSEIF = 1035;
int TokenIDENT = 2000;
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/PHPPairMatcher.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/PHPPairMatcher.java
index 908350d44..53d2bf6c8 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/PHPPairMatcher.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/PHPPairMatcher.java
@@ -237,8 +237,7 @@ public final class PHPPairMatcher implements ICharacterPairMatcher {
: document.get(prevTokenOffset, offset - prevTokenOffset).trim();
if (prevToken == Symbols.TokenLBRACE || prevToken == Symbols.TokenRBRACE
- || prevToken == Symbols.TokenSEMICOLON || prevToken == Symbols.TokenSYNCHRONIZED
- || prevToken == Symbols.TokenSTATIC
+ || prevToken == Symbols.TokenSEMICOLON || prevToken == Symbols.TokenSTATIC
|| (prevToken == Symbols.TokenIDENT && isTypeParameterIntroducer(previous))
|| prevToken == Symbols.TokenEOF) {
return true;
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java
index 0c010a08f..26c12bdfd 100644
--- a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java
@@ -15,6 +15,7 @@
package org.eclipse.php.core.tests;
import org.eclipse.php.core.tests.codeassist.CodeAssistTests;
+import org.eclipse.php.core.tests.codeassist.scope.CodeAssistScopeTests;
import org.eclipse.php.core.tests.compiler_ast.parser.CompilerParserTests;
import org.eclipse.php.core.tests.compiler_ast.parser.FindUseStatementByAliasTests;
import org.eclipse.php.core.tests.compiler_ast.parser.FindUseStatementByNamespaceTests;
@@ -53,10 +54,10 @@ import org.junit.runners.Suite;
DomParserTests.class, CompilerParserTests.class, FindUseStatementByAliasTests.class,
FindUseStatementByNamespaceTests.class, GetUseStatementsByTests.class, TraitUseStatementVisitorTests.class,
TypeDeclarationVisitorTests.class, ErrorReportingTests.class, ASTRewriteTests.Suite.class,
- ASTMatcherTests.class, CommentMapperTests.class, StaticScalarExpressionsTests.class, CodeAssistTests.class,
- SelectionEngineTests.class, ModelStructureTests.class, TypeInferenceTests.class, FileNetworkTests.class,
- PHPDocParserTests.class, PHPDocAwareDeclarationTests.class, IncludePathManagerTests.class, BindingTests.class,
- PHPModelUtilsTests.class,
+ ASTMatcherTests.class, CommentMapperTests.class, StaticScalarExpressionsTests.class, CodeAssistScopeTests.class,
+ CodeAssistTests.class, SelectionEngineTests.class, ModelStructureTests.class, TypeInferenceTests.class,
+ FileNetworkTests.class, PHPDocParserTests.class, PHPDocAwareDeclarationTests.class,
+ IncludePathManagerTests.class, BindingTests.class, PHPModelUtilsTests.class,
// Document tests:
DocumentLexerTests.class, PHPPartitionerTests.class,
// Phar files
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/TestUtils.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/TestUtils.java
index 50a5fcd2b..e02501dd0 100644
--- a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/TestUtils.java
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/TestUtils.java
@@ -26,9 +26,14 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.ModelException;
import org.eclipse.dltk.core.search.indexing.AbstractJob;
import org.eclipse.dltk.core.search.indexing.IndexManager;
+import org.eclipse.dltk.internal.core.DefaultWorkingCopyOwner;
import org.eclipse.dltk.internal.core.ModelManager;
+import org.eclipse.dltk.internal.core.search.ProjectIndexerManager;
import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.libfolders.LibraryFolderManager;
import org.eclipse.php.core.project.ProjectOptions;
@@ -78,8 +83,8 @@ public final class TestUtils {
@Override
protected void run() throws CoreException, IOException {
/*
- * Check if there were some new index requests added to the queue in the
- * meantime, if so go back to the end of the queue.
+ * Check if there were some new index requests added to the queue in
+ * the meantime, if so go back to the end of the queue.
*/
if (indexManager.awaitingJobsCount() > 1) {
noWaitSignalThread.interrupt();
@@ -92,8 +97,8 @@ public final class TestUtils {
// Interrupt "wait for indexer" thread (no sleeping dude...).
noWaitSignalThread.interrupt();
/*
- * Requests queue is empty, we can assume that indexer has finished so release
- * semaphore to move on with processing.
+ * Requests queue is empty, we can assume that indexer has finished
+ * so release semaphore to move on with processing.
*/
waitForIndexerSemaphore.release();
}
@@ -431,4 +436,13 @@ public final class TestUtils {
LibraryFolderManager.getInstance().suspendAllDetection(true);
}
+ public static void indexFile(IFile file) {
+ ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(file);
+ try {
+ sourceModule.reconcile(true, DefaultWorkingCopyOwner.PRIMARY, null);
+ } catch (ModelException e) {
+ }
+ ProjectIndexerManager.reconciled(sourceModule);
+ }
+
}
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/CodeAssistTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/CodeAssistTests.java
index 336537b7e..39521770a 100644
--- a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/CodeAssistTests.java
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/CodeAssistTests.java
@@ -37,6 +37,7 @@ import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.tests.PdttFile;
import org.eclipse.php.core.tests.TestSuiteWatcher;
import org.eclipse.php.core.tests.TestUtils;
+import org.eclipse.php.core.tests.TestUtils.ColliderType;
import org.eclipse.php.core.tests.codeassist.CodeAssistPdttFile.ExpectedProposal;
import org.eclipse.php.core.tests.runner.PDTTList;
import org.eclipse.php.core.tests.runner.PDTTList.AfterList;
@@ -48,6 +49,7 @@ import org.eclipse.php.internal.core.codeassist.IPHPCompletionRequestor;
import org.eclipse.php.internal.core.documentModel.loader.PHPDocumentLoader;
import org.eclipse.php.internal.core.typeinference.FakeConstructor;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.junit.After;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TestWatcher;
@@ -157,11 +159,13 @@ public class CodeAssistTests {
public void setUpSuite() throws Exception {
project = TestUtils.createProject("CodeAssistTests_" + version.toString());
TestUtils.setProjectPHPVersion(project, version);
+ TestUtils.enableColliders(ColliderType.AUTO_BUILD);
}
@AfterList
public void tearDownSuite() throws Exception {
TestUtils.deleteProject(project);
+ TestUtils.disableColliders(ColliderType.AUTO_BUILD);
}
@Test
@@ -171,10 +175,10 @@ public class CodeAssistTests {
final int offset = createFiles(pdttFile);
CompletionProposal[] proposals = getProposals(DLTKCore.createSourceModuleFrom(testFile), offset);
compareProposals(proposals, pdttFile);
- deleteFiles();
}
- private void deleteFiles() {
+ @After
+ public void deleteFiles() {
if (testFile != null) {
TestUtils.deleteFile(testFile);
}
@@ -209,11 +213,14 @@ public class CodeAssistTests {
String fileName = Paths.get(pdttFile.getFileName()).getFileName().toString();
fileName = fileName.substring(0, fileName.indexOf('.'));
testFile = TestUtils.createFile(project, fileName + ".php", data);
+ TestUtils.indexFile(testFile);
+
this.otherFiles = new ArrayList<>(otherFiles.length);
int i = 0;
for (String otherFileContent : otherFiles) {
IFile tmp = TestUtils.createFile(project, String.format("test%s.php", i), otherFileContent);
this.otherFiles.add(i, tmp);
+ TestUtils.indexFile(tmp);
i++;
}
TestUtils.waitForIndexer();
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopePdttFile.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopePdttFile.java
new file mode 100644
index 000000000..44da4ed2a
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopePdttFile.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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
+ * Dawid Pakuła - Assist Scope Tests
+ *******************************************************************************/
+package org.eclipse.php.core.tests.codeassist.scope;
+
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.php.core.codeassist.ICompletionScope;
+import org.eclipse.php.core.tests.PdttFile;
+
+/**
+ * This is an extension of {@link PdttFile} that parses the --EXPECT-- section
+ * into expected proposals list. The format of this section must be as follows:
+ *
+ * <pre>
+ * TRAIT(3,4)
+ * NAMESPACE(1,9)
+ * FILE(0,10)
+ * </pre>
+ */
+public class CodeAssistScopePdttFile extends PdttFile {
+
+ static public class ExpectedScope {
+ public ICompletionScope.Type type;
+ public int offset;
+ public int length;
+ public String name = null;
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ICompletionScope) {
+ ICompletionScope scope = (ICompletionScope) obj;
+ if (scope.getType() != type || scope.getLength() != length || scope.getOffset() != offset) {
+ return false;
+ }
+ String objName = scope.getName();
+ if (name == null && objName != null) {
+ return false;
+ } else if (name != null && !name.equals(objName)) {
+ return false;
+ }
+
+ return true;
+ }
+ return super.equals(obj);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(type.name()).append('(').append(offset).append(',').append(length);
+ if (name != null) {
+ sb.append(',').append(name);
+ }
+ return sb.append(')').toString();
+ }
+ }
+
+ private ExpectedScope[] expectedScopes;
+
+ public CodeAssistScopePdttFile(String fileName) throws Exception {
+ super(fileName);
+ }
+
+ public ExpectedScope[] getExpectedScopes() {
+ return expectedScopes;
+ }
+
+ @Override
+ protected void parse(InputStream stream, String charsetName) throws Exception {
+ super.parse(stream, null);
+
+ List<ExpectedScope> expectedScopes = new LinkedList<>();
+ String[] lines = getExpected().split("\n");
+ for (String line : lines) {
+ int i = line.indexOf('(');
+ int j = line.indexOf(')');
+ if (i == -1 || j == -1) { // wrong format
+ continue;
+ }
+ ExpectedScope proposal = new ExpectedScope();
+ proposal.type = ICompletionScope.Type.valueOf(line.substring(0, i));
+ String[] nums = line.substring(i + 1, j).split(",", 3);
+ if (nums.length != 2 && nums.length != 3) {
+ throw new Exception("Invalid sope arguments!");
+ }
+ proposal.offset = Integer.valueOf(nums[0]);
+ proposal.length = Integer.valueOf(nums[1]);
+ if (nums.length == 3) {
+ proposal.name = nums[2];
+ }
+ expectedScopes.add(proposal);
+ }
+ this.expectedScopes = expectedScopes.toArray(new ExpectedScope[expectedScopes.size()]);
+ }
+
+}
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopeTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopeTests.java
new file mode 100644
index 000000000..2e7e3ddd9
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/codeassist/scope/CodeAssistScopeTests.java
@@ -0,0 +1,271 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2018 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
+ * Dawid Pakuła - Assist Scope Tests
+ *******************************************************************************/
+package org.eclipse.php.core.tests.codeassist.scope;
+
+import static org.junit.Assert.fail;
+
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.compiler.env.IModuleSource;
+import org.eclipse.dltk.core.CompletionProposal;
+import org.eclipse.dltk.core.CompletionRequestor;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.ModelException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.php.core.PHPVersion;
+import org.eclipse.php.core.codeassist.CompletionCompanion;
+import org.eclipse.php.core.codeassist.ICompletionScope;
+import org.eclipse.php.core.project.ProjectOptions;
+import org.eclipse.php.core.tests.PdttFile;
+import org.eclipse.php.core.tests.TestSuiteWatcher;
+import org.eclipse.php.core.tests.TestUtils;
+import org.eclipse.php.core.tests.TestUtils.ColliderType;
+import org.eclipse.php.core.tests.codeassist.scope.CodeAssistScopePdttFile.ExpectedScope;
+import org.eclipse.php.core.tests.runner.PDTTList;
+import org.eclipse.php.core.tests.runner.PDTTList.AfterList;
+import org.eclipse.php.core.tests.runner.PDTTList.BeforeList;
+import org.eclipse.php.core.tests.runner.PDTTList.Parameters;
+import org.eclipse.php.internal.core.codeassist.IPHPCompletionRequestor;
+import org.eclipse.php.internal.core.documentModel.loader.PHPDocumentLoader;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.junit.After;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.RunWith;
+
+@SuppressWarnings("all")
+@RunWith(PDTTList.class)
+public class CodeAssistScopeTests {
+
+ @ClassRule
+ public static TestWatcher watcher = new TestSuiteWatcher();
+
+ private static class TestCompletionRequestor extends CompletionRequestor implements IPHPCompletionRequestor {
+
+ private IStructuredDocument document;
+ private int offset;
+
+ public TestCompletionRequestor(IStructuredDocument document, int offset) {
+ this.document = document;
+ this.offset = offset;
+ }
+
+ @Override
+ public IDocument getDocument() {
+ return document;
+ }
+
+ @Override
+ public boolean isExplicit() {
+ return true;
+ }
+
+ @Override
+ public int getOffset() {
+ return offset;
+ }
+
+ @Override
+ public void setOffset(int offset) {
+ this.offset = offset;
+ }
+
+ @Override
+ public boolean filter(int flag) {
+ return false;
+ }
+
+ @Override
+ public void addFlag(int flag) {
+ }
+
+ @Override
+ public void accept(CompletionProposal proposal) {
+
+ }
+
+ }
+
+ @Parameters
+ public static final Map<PHPVersion, String[]> TESTS = new LinkedHashMap<>();
+ public static final String DEFAULT_CURSOR = "|";
+
+ static {
+ TESTS.put(PHPVersion.PHP5, new String[] { "/workspace/codeassist_scope/php5" });
+ TESTS.put(PHPVersion.PHP5_3,
+ new String[] { "/workspace/codeassist_scope/php5", "/workspace/codeassist_scope/php53" });
+ TESTS.put(PHPVersion.PHP5_4, new String[] { "/workspace/codeassist_scope/php5",
+ "/workspace/codeassist_scope/php53", "/workspace/codeassist_scope/php54" });
+ TESTS.put(PHPVersion.PHP5_5,
+ new String[] { "/workspace/codeassist_scope/php5", "/workspace/codeassist_scope/php53",
+ "/workspace/codeassist_scope/php54", "/workspace/codeassist_scope/php55" });
+ TESTS.put(PHPVersion.PHP5_6,
+ new String[] { "/workspace/codeassist_scope/php5", "/workspace/codeassist_scope/php53",
+ "/workspace/codeassist_scope/php54", "/workspace/codeassist_scope/php55",
+ "/workspace/codeassist_scope/php56" });
+ TESTS.put(PHPVersion.PHP7_0,
+ new String[] { "/workspace/codeassist_scope/php5", "/workspace/codeassist_scope/php53",
+ "/workspace/codeassist_scope/php54", "/workspace/codeassist_scope/php55",
+ "/workspace/codeassist_scope/php56", "/workspace/codeassist_scope/php7" });
+ TESTS.put(PHPVersion.PHP7_1,
+ new String[] { "/workspace/codeassist_scope/php5", "/workspace/codeassist_scope/php53",
+ "/workspace/codeassist_scope/php54", "/workspace/codeassist_scope/php55",
+ "/workspace/codeassist_scope/php56", "/workspace/codeassist_scope/php7",
+ "/workspace/codeassist_scope/php71" });
+ TESTS.put(PHPVersion.PHP7_2,
+ new String[] { "/workspace/codeassist_scope/php5", "/workspace/codeassist_scope/php53",
+ "/workspace/codeassist_scope/php54", "/workspace/codeassist_scope/php55",
+ "/workspace/codeassist_scope/php56", "/workspace/codeassist_scope/php7",
+ "/workspace/codeassist_scope/php71", "/workspace/codeassist_scope/php72" });
+ };
+
+ private IProject project;
+ private IFile testFile;
+ private List<IFile> otherFiles = null;
+ private PHPVersion version;
+
+ public CodeAssistScopeTests(PHPVersion version, String[] fileNames) {
+ this.version = version;
+ }
+
+ @BeforeList
+ public void setUpSuite() throws Exception {
+ TestUtils.disableColliders(ColliderType.ALL);
+ project = TestUtils.createProject("CodeAssistScopeTests_" + version.toString());
+ ProjectOptions.setPHPVersion(version, project);
+ }
+
+ @AfterList
+ public void tearDownSuite() throws Exception {
+ TestUtils.deleteProject(project);
+ TestUtils.enableColliders(ColliderType.ALL);
+ }
+
+ @Test
+ public void assist(final String fileName) throws Exception {
+ final CodeAssistScopePdttFile pdttFile = new CodeAssistScopePdttFile(fileName);
+ pdttFile.applyPreferences();
+
+ final int offset = createFiles(pdttFile);
+
+ ICompletionScope[] scopes = getScopes(DLTKCore.createSourceModuleFrom(testFile), offset);
+ compareScopes(scopes, pdttFile);
+ }
+
+ private ICompletionScope[] getScopes(ISourceModule sourceModule, int offset) throws ModelException {
+ IStructuredDocument document = (IStructuredDocument) new PHPDocumentLoader().createNewStructuredDocument();
+ String content = new String(sourceModule.getSourceAsCharArray());
+ document.set(content);
+
+ final List<ICompletionScope> scopes = new LinkedList<>();
+ CompletionCompanion companion = new CompletionCompanion(new TestCompletionRequestor(document, offset),
+ (IModuleSource) sourceModule, offset);
+
+ ICompletionScope scope = companion.getScope();
+ do {
+ scopes.add(scope);
+ scope = scope.getParent();
+ } while (scope != null);
+
+ return scopes.toArray(new ICompletionScope[scopes.size()]);
+ }
+
+ private void compareScopes(ICompletionScope[] proposals, CodeAssistScopePdttFile pdttFile) throws Exception {
+ ExpectedScope[] expectedProposals = pdttFile.getExpectedScopes();
+ boolean proposalsEqual = true;
+ if (proposals.length == expectedProposals.length) {
+ int pos = 0;
+ for (ICompletionScope proposal : proposals) {
+ ExpectedScope compare = expectedProposals[pos++];
+
+ if (!compare.equals(proposal)) {
+ proposalsEqual = false;
+ break;
+ }
+ }
+
+ } else {
+ proposalsEqual = false;
+ }
+ if (!proposalsEqual) {
+ StringBuilder errorBuf = new StringBuilder();
+ errorBuf.append("\nEXPECTED COMPLETIONS LIST:\n-----------------------------\n");
+ errorBuf.append(pdttFile.getExpected());
+ errorBuf.append("\nACTUAL COMPLETIONS LIST:\n-----------------------------\n");
+ for (ICompletionScope p : proposals) {
+ errorBuf.append(p.toString()).append('\n');
+ }
+ fail(errorBuf.toString());
+ }
+ }
+
+ @After
+ public void deleteFiles() {
+ if (testFile != null) {
+ TestUtils.deleteFile(testFile);
+ }
+ if (otherFiles != null) {
+ for (IFile file : otherFiles) {
+ if (file != null)
+ TestUtils.deleteFile(file);
+ }
+ }
+ }
+
+ /**
+ * Creates test file with the specified content and calculates the offset at
+ * OFFSET_CHAR. Offset character itself is stripped off.
+ *
+ * @param data
+ * File data
+ * @return offset where's the offset character set.
+ * @throws Exception
+ */
+ private int createFiles(PdttFile pdttFile) throws Exception {
+ final String cursor = getCursor(pdttFile) != null ? getCursor(pdttFile) : DEFAULT_CURSOR;
+ String data = pdttFile.getFile();
+ String[] otherFiles = pdttFile.getOtherFiles();
+ int offset = data.lastIndexOf(cursor);
+ if (offset == -1) {
+ throw new IllegalArgumentException("Offset character is not set");
+ }
+ // Replace the offset character
+ data = data.substring(0, offset) + data.substring(offset + 1);
+ String fileName = Paths.get(pdttFile.getFileName()).getFileName().toString();
+ fileName = fileName.substring(0, fileName.indexOf('.'));
+ testFile = TestUtils.createFile(project, fileName + ".php", data);
+ this.otherFiles = new ArrayList<>(otherFiles.length);
+ int i = 0;
+ for (String otherFileContent : otherFiles) {
+ IFile tmp = TestUtils.createFile(project, String.format("test%s.php", i), otherFileContent);
+ this.otherFiles.add(i, tmp);
+ i++;
+ }
+ // TestUtils.waitForIndexer();
+ return offset;
+ }
+
+ private String getCursor(PdttFile pdttFile) {
+ Map<String, String> config = pdttFile.getConfig();
+ return config.get("cursor");
+ }
+}
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/alternate01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/alternate01.pdtt
new file mode 100644
index 000000000..6f822dba5
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/alternate01.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+Simple file
+--FILE--
+<?php if (true) : | ?>
+<?php endif; ?>
+--EXPECT--
+BLOCK(16,22)
+IF(6,32)
+FILE(0,38)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile01.pdtt
new file mode 100644
index 000000000..61043111a
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile01.pdtt
@@ -0,0 +1,17 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+class MyName {
+ |
+}
+?>
+
+--EXPECT--
+BLOCK(57,8)
+CLASS(44,21,MyName)
+FILE(0,70) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile02.pdtt
new file mode 100644
index 000000000..673ad8210
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile02.pdtt
@@ -0,0 +1,18 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+class MyName {
+ var $x = '|';
+}
+?>
+
+--EXPECT--
+FIELD(63,12)
+BLOCK(57,20)
+CLASS(44,33,MyName)
+FILE(0,82) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile03.pdtt
new file mode 100644
index 000000000..4ef2ecb68
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile03.pdtt
@@ -0,0 +1,18 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+class MyName {
+ protected |$x = '';
+}
+?>
+
+--EXPECT--
+FIELD(63,18)
+BLOCK(57,26)
+CLASS(44,39,MyName)
+FILE(0,88) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile04.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile04.pdtt
new file mode 100644
index 000000000..c8025581b
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile04.pdtt
@@ -0,0 +1,18 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+class MyName {
+ const XXX = '|';
+}
+?>
+
+--EXPECT--
+CONST(63,15)
+BLOCK(57,23)
+CLASS(44,36,MyName)
+FILE(0,85) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile05.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile05.pdtt
new file mode 100644
index 000000000..0eea3e3b9
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile05.pdtt
@@ -0,0 +1,21 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+class MyName {
+ public static function test() {
+ |
+ }
+}
+?>
+
+--EXPECT--
+BLOCK(93,16)
+FUNCTION(63,46,test)
+BLOCK(57,54)
+CLASS(44,67,MyName)
+FILE(0,116) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile06.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile06.pdtt
new file mode 100644
index 000000000..804bae04b
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/classFile06.pdtt
@@ -0,0 +1,21 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+abstract class MyName extends Something {
+ public static function test() {
+ |
+ }
+}
+?>
+
+--EXPECT--
+BLOCK(120,16)
+FUNCTION(90,46,test)
+BLOCK(84,54)
+CLASS(44,94,MyName)
+FILE(0,143) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment01.pdtt
new file mode 100644
index 000000000..5b4c7aff4
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment01.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+Comment
+--FILE--
+<?php
+// on| line
+?>
+
+--EXPECT--
+COMMENT(9,9)
+FILE(0,22) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment02.pdtt
new file mode 100644
index 000000000..5d9c127ff
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment02.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+Comment
+--FILE--
+<?php
+/*|
+* multi line
+*/
+?>
+
+--EXPECT--
+COMMENT(7,18)
+FILE(0,30)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment03.pdtt
new file mode 100644
index 000000000..7ef8954a4
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment03.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+Comment
+--FILE--
+<?php
+/*
+* |multi line
+*/
+?>
+
+--EXPECT--
+COMMENT(7,18)
+FILE(0,30) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment04.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment04.pdtt
new file mode 100644
index 000000000..9326cc218
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment04.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+Comment
+--FILE--
+<?php
+/*
+* multi line
+*|/
+?>
+
+--EXPECT--
+COMMENT(7,18)
+FILE(0,30) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment05.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment05.pdtt
new file mode 100644
index 000000000..1ed7b5df6
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment05.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+Comment
+--FILE--
+<?php
+/**
+* multi line
+*|/
+?>
+
+--EXPECT--
+PHPDOC(7,19)
+FILE(0,31) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment06.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment06.pdtt
new file mode 100644
index 000000000..8fd57e6fa
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment06.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+Comment
+--FILE--
+<?php
+/**
+* @param |x
+*|/
+?>
+
+--EXPECT--
+PHPDOC(7,18)
+FILE(0,30) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment07.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment07.pdtt
new file mode 100644
index 000000000..f0f34321d
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/comment07.pdtt
@@ -0,0 +1,13 @@
+--TEST--
+Comment
+--FILE--
+<?php
+/**
+* @param x|
+* Do something
+*|/
+?>
+
+--EXPECT--
+PHPDOC(7,33)
+FILE(0,45) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control01.pdtt
new file mode 100644
index 000000000..0e5280323
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control01.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+
+--FILE--
+<?php
+if (true) {
+ |
+}
+?>
+--EXPECT--
+BLOCK(16,8)
+IF(6,18)
+FILE(0,28) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control02.pdtt
new file mode 100644
index 000000000..9c48ad758
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control02.pdtt
@@ -0,0 +1,11 @@
+--TEST--
+
+--FILE--
+<?php
+if (true)
+ |;
+?>
+--EXPECT--
+BLOCK(10,12)
+IF(6,16)
+FILE(0,26) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control03.pdtt
new file mode 100644
index 000000000..07c598d70
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control03.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+if (true)
+ ;
+|
+?>
+--EXPECT--
+FILE(0,27) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control04.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control04.pdtt
new file mode 100644
index 000000000..761962c93
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control04.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+
+--FILE--
+<?php
+if (true)
+ for($s; |) {
+
+ }
+
+?>
+--EXPECT--
+HEAD(24,6)
+FOR(21,26)
+BLOCK(21,26)
+IF(6,41)
+FILE(0,52) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control05.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control05.pdtt
new file mode 100644
index 000000000..33757a079
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control05.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+
+--FILE--
+<?php
+if (true)
+ for($s; $i; $k) {
+
+ }
+|
+?>
+--EXPECT--
+FILE(0,58) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control06.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control06.pdtt
new file mode 100644
index 000000000..27cc14920
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control06.pdtt
@@ -0,0 +1,17 @@
+--TEST--
+
+--FILE--
+<?php
+function Test() {
+ do {
+ |
+ } while(true);
+}
+
+?>
+--EXPECT--
+BLOCK(31,16)
+DOWHILE(28,32)
+BLOCK(22,40)
+FUNCTION(6,56,Test)
+FILE(0,67) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control07.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control07.pdtt
new file mode 100644
index 000000000..58eb5bdd1
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control07.pdtt
@@ -0,0 +1,17 @@
+--TEST--
+
+--FILE--
+<?php
+function Test() {
+ do {
+
+ } while(tr|ue);
+}
+
+?>
+--EXPECT--
+HEAD(53,6)
+DOWHILE(28,32)
+BLOCK(22,40)
+FUNCTION(6,56,Test)
+FILE(0,67) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control08.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control08.pdtt
new file mode 100644
index 000000000..4d40200f8
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control08.pdtt
@@ -0,0 +1,36 @@
+--TEST--
+
+--FILE--
+<?php
+class Foo {
+ function Test() {
+ do {
+ while((true)) {
+ for ($i; $i; $i) {
+ if (true)
+ switch ($e) {
+ case '':
+ break|;
+ }
+ }
+ }
+ } while(true);
+ }
+}
+?>
+--EXPECT--
+BLOCK(182,103)
+SWITCH(170,115)
+BLOCK(170,115)
+IF(136,149)
+BLOCK(114,189)
+FOR(97,206)
+BLOCK(79,238)
+WHILE(65,252)
+BLOCK(51,276)
+DOWHILE(48,292)
+BLOCK(38,308)
+FUNCTION(22,324,Test)
+BLOCK(16,332)
+CLASS(6,342,Foo)
+FILE(0,352) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control09.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control09.pdtt
new file mode 100644
index 000000000..0e5857980
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/control09.pdtt
@@ -0,0 +1,37 @@
+--TEST--
+
+--FILE--
+<?php
+class Foo {
+ function Test() {
+ do {
+ while((true)):
+ for ($i; $i; $i):
+ if (true):
+ switch ($e):
+ case '':
+ break|;
+ endswitch;
+ endif;
+ endfor;
+ endwhile;
+ } while(true);
+ }
+}
+?>
+--EXPECT--
+BLOCK(180,111)
+SWITCH(169,122)
+BLOCK(143,175)
+IF(134,184)
+BLOCK(112,230)
+FOR(96,246)
+BLOCK(78,286)
+WHILE(65,299)
+BLOCK(51,324)
+DOWHILE(48,340)
+BLOCK(38,356)
+FUNCTION(22,372,Test)
+BLOCK(16,380)
+CLASS(6,390,Foo)
+FILE(0,400) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions01.pdtt
new file mode 100644
index 000000000..875d4e570
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions01.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Comment
+--FILE--
+<?php
+try {
+ |
+} catch(Exception $e) {
+
+}
+
+--EXPECT--
+BLOCK(11,8)
+TRY(7,12)
+FILE(0,50) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions02.pdtt
new file mode 100644
index 000000000..c60634d32
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions02.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Comment
+--FILE--
+<?php
+try {
+
+} catch(Exception $e|) {
+
+}
+
+--EXPECT--
+HEAD(25,14)
+CATCH(20,28)
+FILE(0,50) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions03.pdtt
new file mode 100644
index 000000000..169b2203d
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/exceptions03.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Comment
+--FILE--
+<?php
+try {
+
+} catch(Exception $e) {
+ |
+}
+
+--EXPECT--
+BLOCK(40,8)
+CATCH(20,28)
+FILE(0,50) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function01.pdtt
new file mode 100644
index 000000000..6955a0ca2
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function01.pdtt
@@ -0,0 +1,13 @@
+--TEST--
+
+--FILE--
+<?php
+function my_func(|) {
+
+}
+?>
+
+--EXPECT--
+HEAD(23,2)
+FUNCTION(7,27,my_func)
+FILE(0,39) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function02.pdtt
new file mode 100644
index 000000000..bd5c8ca68
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function02.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+
+--FILE--
+<?php
+function my_|func() {
+
+}
+?>
+
+--EXPECT--
+FUNCTION(7,27,my_func)
+FILE(0,39) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function03.pdtt
new file mode 100644
index 000000000..d12ebac61
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function03.pdtt
@@ -0,0 +1,13 @@
+--TEST--
+
+--FILE--
+<?php
+function my_func() {
+ |
+}
+?>
+
+--EXPECT--
+BLOCK(26,8)
+FUNCTION(7,27,my_func)
+FILE(0,39)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function04.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function04.pdtt
new file mode 100644
index 000000000..ca51bf26b
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/function04.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+
+--FILE--
+<?php
+function |my_func() {
+
+}
+?>
+
+--EXPECT--
+FUNCTION(7,27,my_func)
+FILE(0,39) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface01.pdtt
new file mode 100644
index 000000000..01d495db0
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface01.pdtt
@@ -0,0 +1,19 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+interface MyName {
+ const CC = '';
+ public function |func();
+}
+?>
+
+--EXPECT--
+FUNCTION(86,23,func)
+BLOCK(61,50)
+INTERFACE(44,67,MyName)
+FILE(0,116) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface02.pdtt
new file mode 100644
index 000000000..b9bd13f84
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface02.pdtt
@@ -0,0 +1,20 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+interface MyName {
+ const CC = '';
+ public function func(|);
+}
+?>
+
+--EXPECT--
+HEAD(106,2)
+FUNCTION(86,23,func)
+BLOCK(61,50)
+INTERFACE(44,67,MyName)
+FILE(0,116) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface03.pdtt
new file mode 100644
index 000000000..961aa50b0
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/interface03.pdtt
@@ -0,0 +1,19 @@
+--TEST--
+Description
+--FILE--
+<?php
+// ignore me
+?>
+<html></html>
+<?php
+interface MyName {
+ const CC = '|';
+ public function func();
+}
+?>
+
+--EXPECT--
+CONST(67,14)
+BLOCK(61,50)
+INTERFACE(44,67,MyName)
+FILE(0,116) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile01.pdtt
new file mode 100644
index 000000000..ff4092770
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile01.pdtt
@@ -0,0 +1,6 @@
+--TEST--
+File without PHP Code
+--FILE--
+My file |
+--EXPECT--
+FILE(0,9) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile02.pdtt
new file mode 100644
index 000000000..af5bab663
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php5/simpleFile02.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+Simple file
+--FILE--
+<?php
+do_some|
+?>
+
+--EXPECT--
+FILE(0,19) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure01.pdtt
new file mode 100644
index 000000000..f93e040bc
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure01.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+
+--FILE--
+<?php
+$x = function(|) {
+
+};
+
+--EXPECT--
+HEAD(20,2)
+FUNCTION(12,19)
+FILE(0,34) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure02.pdtt
new file mode 100644
index 000000000..9642e4806
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure02.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+
+--FILE--
+<?php
+$x = function() {
+ |
+};
+
+--EXPECT--
+BLOCK(23,8)
+FUNCTION(12,19)
+FILE(0,34) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure03.pdtt
new file mode 100644
index 000000000..79c6ba5cf
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/closure03.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+
+--FILE--
+<?php
+$x = function() {
+ $nested = function() {
+ |
+ };
+};
+
+--EXPECT--
+BLOCK(50,16)
+FUNCTION(39,27)
+BLOCK(23,46)
+FUNCTION(12,57)
+FILE(0,72) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace01.pdtt
new file mode 100644
index 000000000..e7c51c062
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace01.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+
+--FILE--
+<?php
+namespace Foo\Bar;
+
+|
+
+--EXPECT--
+BLOCK(25,4)
+NAMESPACE(7,22,Foo\Bar)
+FILE(0,29) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace02.pdtt
new file mode 100644
index 000000000..7072ee6cf
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace02.pdtt
@@ -0,0 +1,11 @@
+--TEST--
+
+--FILE--
+<?php
+namespace Foo\Bar {
+ |
+}
+--EXPECT--
+BLOCK(25,8)
+NAMESPACE(7,26,Foo\Bar)
+FILE(0,34) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace03.pdtt
new file mode 100644
index 000000000..614421218
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace03.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+namespace |Foo\Bar;
+
+
+--EXPECT--
+NAMESPACE(7,21,Foo\Bar)
+FILE(0,28) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace04.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace04.pdtt
new file mode 100644
index 000000000..86a710900
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace04.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+
+--FILE--
+<?php
+namespace Foo\Bar {
+
+}
+namespace Second\Bar {
+ |
+}
+
+
+--EXPECT--
+BLOCK(55,8)
+NAMESPACE(34,29,Second\Bar)
+FILE(0,66) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace05.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace05.pdtt
new file mode 100644
index 000000000..f825f984f
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace05.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+
+--FILE--
+<?php
+namespace Foo\Bar {
+
+}
+namespace Second\Bar {
+
+}
+|
+
+--EXPECT--
+FILE(0,66) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace06.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace06.pdtt
new file mode 100644
index 000000000..037169596
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace06.pdtt
@@ -0,0 +1,11 @@
+--TEST--
+Global
+--FILE--
+<?php
+namespace {
+ |
+}
+--EXPECT--
+BLOCK(18,8)
+NAMESPACE(7,19)
+FILE(0,27) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace07.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace07.pdtt
new file mode 100644
index 000000000..3904d2b9e
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace07.pdtt
@@ -0,0 +1,12 @@
+--TEST--
+Global
+--FILE--
+<?php
+namespace {
+ use Somet|hing\About;
+}
+--EXPECT--
+USE(24,20)
+BLOCK(18,28)
+NAMESPACE(7,39)
+FILE(0,47) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace08.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace08.pdtt
new file mode 100644
index 000000000..8c496f58f
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/namespace08.pdtt
@@ -0,0 +1,15 @@
+--TEST--
+Global
+--FILE--
+<?php
+namespace NS;
+function AAA() {}
+class AAA {}
+const AAA = 5;
+$AAA = "";
+
+namespace\|
+--EXPECT--
+BLOCK(20,70)
+NAMESPACE(7,83,NS)
+FILE(0,90) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait01.pdtt
new file mode 100644
index 000000000..ccf5b1e55
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait01.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+
+--FILE--
+<?php
+trait Foo {
+ public function name() {
+ |
+ }
+}
+
+--EXPECT--
+BLOCK(46,16)
+FUNCTION(23,39,name)
+BLOCK(17,47)
+TRAIT(7,57,Foo)
+FILE(0,66) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait02.pdtt
new file mode 100644
index 000000000..a36c7afe4
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait02.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+
+--FILE--
+<?php
+trait FOO {
+ public $x = '|';
+ public function name() {
+
+ }
+}
+
+--EXPECT--
+FIELD(23,15)
+BLOCK(17,67)
+TRAIT(7,77,FOO)
+FILE(0,86) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait03.pdtt
new file mode 100644
index 000000000..b113bd8a5
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait03.pdtt
@@ -0,0 +1,20 @@
+--TEST--
+
+--FILE--
+<?php
+trait Foo {
+ public $x = '';
+ public function name() {
+
+ }
+}
+
+class Bar {
+ use Other, Fo|o;
+}
+
+--EXPECT--
+TRAIT_USE(102,15)
+BLOCK(96,23)
+CLASS(86,33,Bar)
+FILE(0,121) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait04.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait04.pdtt
new file mode 100644
index 000000000..8a7a5b0dc
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/trait04.pdtt
@@ -0,0 +1,24 @@
+--TEST--
+
+--FILE--
+<?php
+trait Foo {
+ public $x = '';
+ public function name() {
+
+ }
+}
+
+class Bar {
+ use Foo, Other {
+ Foo::a as b;
+ Other::c inste|adof Foo;
+ }
+}
+
+--EXPECT--
+TRAIT_PRECEDENCE(117,60)
+TRAIT_USE(102,75)
+BLOCK(96,83)
+CLASS(86,93,Bar)
+FILE(0,181) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/use01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/use01.pdtt
new file mode 100644
index 000000000..d4473c0d5
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php53/use01.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+Global
+--FILE--
+<?php
+use Somet|hing\About;
+
+--EXPECT--
+USE(7,20)
+FILE(0,29) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/classConst.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/classConst.pdtt
new file mode 100644
index 000000000..45c358c05
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/classConst.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+Global
+--FILE--
+<?php
+
+echo \Something::cla|ss;
+
+--EXPECT--
+FILE(0,33) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/exceptions01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/exceptions01.pdtt
new file mode 100644
index 000000000..bfecd07ad
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php55/exceptions01.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+Comment
+--FILE--
+<?php
+try {
+
+} catch(Exception $e) {
+
+} finally {
+ |
+}
+
+--EXPECT--
+BLOCK(57,8)
+FINALLY(49,16)
+FILE(0,67) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use01.pdtt
new file mode 100644
index 000000000..94044dd2e
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use01.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+
+--FILE--
+<?php
+use function fu|nc;
+
+--EXPECT--
+USE_FUNCTION(7,18)
+FILE(0,27) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use02.pdtt
new file mode 100644
index 000000000..02c76ff62
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use02.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+
+--FILE--
+<?php
+use | function func;
+
+--EXPECT--
+USE_FUNCTION(7,19)
+FILE(0,28) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use03.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use03.pdtt
new file mode 100644
index 000000000..0b2344db6
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use03.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+
+--FILE--
+<?php
+use | const XX;
+
+--EXPECT--
+USE_CONST(7,14)
+FILE(0,23) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use04.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use04.pdtt
new file mode 100644
index 000000000..8c3468785
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use04.pdtt
@@ -0,0 +1,9 @@
+--TEST--
+
+--FILE--
+<?php
+use const XX|X;
+
+--EXPECT--
+USE_CONST(7,14)
+FILE(0,23) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use05.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use05.pdtt
new file mode 100644
index 000000000..705134f16
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use05.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+use Something\{After,|Me};
+
+--EXPECT--
+USE_GROUP(21,10)
+USE(7,24)
+FILE(0,34) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use06.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use06.pdtt
new file mode 100644
index 000000000..62f93888a
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use06.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+use Item as Another, With\{Me|};
+
+--EXPECT--
+USE_GROUP(33,4)
+USE(7,30)
+FILE(0,40) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use07.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use07.pdtt
new file mode 100644
index 000000000..4de372922
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use07.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+use Item as Another, With\{const XXX, function Me|};
+
+--EXPECT--
+USE_GROUP(33,24)
+USE(7,50)
+FILE(0,60) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use08.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use08.pdtt
new file mode 100644
index 000000000..2a2172f61
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use08.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+use Item as Another, With\{function XXX, const Me|};
+
+--EXPECT--
+USE_GROUP(33,24)
+USE(7,50)
+FILE(0,60) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use09.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use09.pdtt
new file mode 100644
index 000000000..589841708
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use09.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+use function Item{More|};
+
+--EXPECT--
+USE_GROUP(24,6)
+USE_FUNCTION(7,24)
+FILE(0,33) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use10.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use10.pdtt
new file mode 100644
index 000000000..357e94152
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist_scope/php7/use10.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+
+--FILE--
+<?php
+use const Item{More|};
+
+--EXPECT--
+USE_GROUP(21,6)
+USE_CONST(7,21)
+FILE(0,30) \ No newline at end of file

Back to the top