Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDawid Pakuła2019-12-02 02:29:48 -0500
committerDawid Pakula2019-12-02 04:50:17 -0500
commit2287fc6ef9a7863275b4f2ac8188e80fe47f3687 (patch)
treee442da2aa24d8bbc8b05ddd6d131ea0509cbcd8e
parent57cc5d8441bda338fd4a1df642b1a05ad13d55ab (diff)
downloadorg.eclipse.pdt-2287fc6ef9a7863275b4f2ac8188e80fe47f3687.tar.gz
org.eclipse.pdt-2287fc6ef9a7863275b4f2ac8188e80fe47f3687.tar.xz
org.eclipse.pdt-2287fc6ef9a7863275b4f2ac8188e80fe47f3687.zip
Bug 551301 - PHP 7.4 property type CA
Change-Id: I2a3b30e63724b0984e498edc4c998918b49d01ab Signed-off-by: Dawid Pakuła <zulus@w3des.net>
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java3
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/CompletionStrategyFactory.java2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PropertyTypeStrategy.java68
-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/workspace/codeassist/php5/classExclusive/testClassStatement2.pdtt (renamed from tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassStatement2.pdtt)0
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php53/classExclusive/testClassStatement2.pdtt (renamed from tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassStatement2.pdtt)0
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/classExclusive/testClassStatement1.pdtt (renamed from tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testClassStatement1.pdtt)0
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/classExclusive/testClassStatement2.pdtt (renamed from tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testClassStatement2.pdtt)0
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php7/classExclusive/anonymousClass02.pdtt (renamed from tests/org.eclipse.php.core.tests/workspace/codeassist/php7/anonymousClass02.pdtt)0
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty01.pdtt11
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty02.pdtt11
11 files changed, 100 insertions, 6 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java
index ec76d1eaa..ea3377163 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/contexts/TypeStatementContext.java
@@ -64,7 +64,8 @@ public final class TypeStatementContext extends AbstractGlobalStatementContext {
if (scope.getType() == ICompletionScope.Type.FIELD || scope.getType() == ICompletionScope.Type.FUNCTION
|| scope.getType() == ICompletionScope.Type.TRAIT_USE
- || scope.getType() == ICompletionScope.Type.TRAIT_PRECEDENCE) {
+ || scope.getType() == ICompletionScope.Type.TRAIT_PRECEDENCE
+ || scope.getType() == ICompletionScope.Type.TYPE_STATEMENT) {
scope = scope.getParent();
}
if (scope.getType() != ICompletionScope.Type.BLOCK) {
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 8741ecb48..d6da9e0c6 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
@@ -154,7 +154,7 @@ public class CompletionStrategyFactory implements ICompletionStrategyFactory {
return new ICompletionStrategy[] { new ClassKeywordsStrategy(context), new ConstantsStrategy(context),
new TypesStrategy(context) };
} else {
- return new ICompletionStrategy[] { new ClassKeywordsStrategy(context),
+ return new ICompletionStrategy[] { new ClassKeywordsStrategy(context), new PropertyTypeStrategy(context)
// new ConstantsStrategy(context),
// new TypesStrategy(context)
};
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PropertyTypeStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PropertyTypeStrategy.java
new file mode 100644
index 000000000..bff62fea4
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/PropertyTypeStrategy.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2019 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * Zend Technologies
+ * Dawid Pakuła - Property type evaluator
+ *******************************************************************************/
+package org.eclipse.php.internal.core.codeassist.strategies;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+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.internal.core.codeassist.ProposalExtraInfo;
+import org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext;
+
+/**
+ * This strategy completes property return type
+ */
+public class PropertyTypeStrategy extends TypesStrategy {
+
+ private static final List<SimpleProposal> TYPES = new ArrayList<>(Arrays.asList(SimpleProposal.BASIC_TYPES));
+
+ public PropertyTypeStrategy(ICompletionContext context) {
+ super(context);
+ }
+
+ @Override
+ public void apply(ICompletionReporter reporter) throws BadLocationException {
+ AbstractCompletionContext context = (AbstractCompletionContext) getContext();
+
+ if (PHPVersion.PHP7_4.isGreaterThan(getCompanion().getPHPVersion())) {
+ return;
+ }
+ String prefix = context.getPrefix();
+ String suffix = ""; //$NON-NLS-1$
+ ISourceRange replaceRange = getReplacementRange(context);
+ PHPVersion phpVersion = getCompanion().getPHPVersion();
+ for (SimpleProposal proposal : TYPES) {
+ if (proposal.isValidPrefix(prefix, phpVersion)) {
+ reporter.reportKeyword(proposal.getProposal(), suffix, replaceRange);
+ }
+ }
+ super.apply(reporter);
+ }
+
+ @Override
+ public String getSuffix(AbstractCompletionContext abstractContext) {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ protected int getExtraInfo() {
+ return ProposalExtraInfo.TYPE_ONLY;
+ }
+}
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 95948b6ec..a6c282b71 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
@@ -127,19 +127,22 @@ public class CodeAssistTests {
TESTS.put(PHPVersion.PHP7_0,
new String[] { "/workspace/codeassist/php5", "/workspace/codeassist/php53",
"/workspace/codeassist/php54", "/workspace/codeassist/php55", "/workspace/codeassist/php56",
- "/workspace/codeassist/php7" });
+ "/workspace/codeassist/php7", "/workspace/codeassist/php7/classExclusive" });
TESTS.put(PHPVersion.PHP7_1,
new String[] { "/workspace/codeassist/php5", "/workspace/codeassist/php53",
"/workspace/codeassist/php54", "/workspace/codeassist/php55", "/workspace/codeassist/php56",
- "/workspace/codeassist/php7", "/workspace/codeassist/php71" });
+ "/workspace/codeassist/php7", "/workspace/codeassist/php7/classExclusive",
+ "/workspace/codeassist/php71" });
TESTS.put(PHPVersion.PHP7_2,
new String[] { "/workspace/codeassist/php5", "/workspace/codeassist/php53",
"/workspace/codeassist/php54", "/workspace/codeassist/php55", "/workspace/codeassist/php56",
- "/workspace/codeassist/php7", "/workspace/codeassist/php71", "/workspace/codeassist/php72" });
+ "/workspace/codeassist/php7", "/workspace/codeassist/php7/classExclusive",
+ "/workspace/codeassist/php71", "/workspace/codeassist/php72" });
TESTS.put(PHPVersion.PHP7_3,
new String[] { "/workspace/codeassist/php5", "/workspace/codeassist/php53",
"/workspace/codeassist/php54", "/workspace/codeassist/php55", "/workspace/codeassist/php56",
- "/workspace/codeassist/php7", "/workspace/codeassist/php71", "/workspace/codeassist/php72" });
+ "/workspace/codeassist/php7", "/workspace/codeassist/php7/classExclusive",
+ "/workspace/codeassist/php71", "/workspace/codeassist/php72" });
TESTS.put(PHPVersion.PHP7_4,
new String[] { "/workspace/codeassist/php5", "/workspace/codeassist/php53",
"/workspace/codeassist/php54", "/workspace/codeassist/php55", "/workspace/codeassist/php56",
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassStatement2.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/classExclusive/testClassStatement2.pdtt
index f4647335d..f4647335d 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassStatement2.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/classExclusive/testClassStatement2.pdtt
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassStatement2.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/classExclusive/testClassStatement2.pdtt
index fdcc791dc..fdcc791dc 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassStatement2.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/classExclusive/testClassStatement2.pdtt
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testClassStatement1.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/classExclusive/testClassStatement1.pdtt
index 4cdba8549..4cdba8549 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testClassStatement1.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/classExclusive/testClassStatement1.pdtt
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testClassStatement2.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/classExclusive/testClassStatement2.pdtt
index 6a79109a1..6a79109a1 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testClassStatement2.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/classExclusive/testClassStatement2.pdtt
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php7/anonymousClass02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php7/classExclusive/anonymousClass02.pdtt
index a3d2fb157..a3d2fb157 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php7/anonymousClass02.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php7/classExclusive/anonymousClass02.pdtt
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty01.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty01.pdtt
new file mode 100644
index 000000000..55b6abb58
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty01.pdtt
@@ -0,0 +1,11 @@
+--TEST--
+
+--FILE--
+<?php
+class Foo {}
+class Bar {
+ private Fo|
+}
+
+--EXPECT--
+type(Foo)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty02.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty02.pdtt
new file mode 100644
index 000000000..99336ce0e
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php74/typedProperty02.pdtt
@@ -0,0 +1,11 @@
+--TEST--
+
+--FILE--
+<?php
+class Foo {}
+class Bar {
+ private static Fo| $x;
+}
+
+--EXPECT--
+type(Foo)

Back to the top