summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakosyakov2013-07-10 09:30:10 (EDT)
committer akosyakov2013-07-10 10:51:57 (EDT)
commitcd05c55c1aca1ff7e62d80549c50d7d10d1173df (patch)
treef39912cf08bf2c369dcdd82cb07bac903a341872
parent942bb2c5df2450a87a29625f7f196f57747e5176 (diff)
downloadorg.eclipse.xtext-cd05c55c1aca1ff7e62d80549c50d7d10d1173df.zip
org.eclipse.xtext-cd05c55c1aca1ff7e62d80549c50d7d10d1173df.tar.gz
org.eclipse.xtext-cd05c55c1aca1ff7e62d80549c50d7d10d1173df.tar.bz2
[411474]: add ability to assign a static fieldrefs/changes/43/14443/2
Change-Id: I7781ffb7d17a0a0566228c3012e771557527f23f Signed-off-by: akosyakov <anton.kosyakov@itemis.de>
-rw-r--r--plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/FeatureLinkingCandidate.java27
-rw-r--r--tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/FeatureCallValidationTest.java35
2 files changed, 58 insertions, 4 deletions
diff --git a/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/FeatureLinkingCandidate.java b/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/FeatureLinkingCandidate.java
index 528d990..dbb4745 100644
--- a/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/FeatureLinkingCandidate.java
+++ b/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/typesystem/internal/FeatureLinkingCandidate.java
@@ -201,7 +201,7 @@ public class FeatureLinkingCandidate extends AbstractPendingLinkingCandidate<XAb
}
protected boolean isInvalidStaticSyntax() {
- boolean result = isStatic() && !isExtension() && (isInstanceAccessSyntax() && !isStaticWithDeclaringType());
+ boolean result = isStatic() && !isExtension() && (isSimpleAssignment() && !isStaticWithDeclaringType());
if (result)
return true;
return false;
@@ -212,9 +212,24 @@ public class FeatureLinkingCandidate extends AbstractPendingLinkingCandidate<XAb
if (featureCall instanceof XMemberFeatureCall) {
return ((XMemberFeatureCall) featureCall).isStaticWithDeclaringType();
}
+ if (featureCall instanceof XAssignment) {
+ return isStaticWithDeclaringType((XAssignment) featureCall);
+ }
return false;
}
+ protected boolean isStaticWithDeclaringType(XAssignment assignment) {
+ return assignment.isExplicitStatic() || isImplicitlyStatic(assignment);
+ }
+
+ protected boolean isImplicitlyStatic(XAssignment assignment) {
+ return assignment.isStatic() && isTypeLiteral(assignment.getAssignable());
+ }
+
+ protected boolean isTypeLiteral(XExpression expression) {
+ return expression instanceof XAbstractFeatureCall && ((XAbstractFeatureCall) expression).isTypeLiteral();
+ }
+
protected boolean isExplicitOperationCallOrBuilderSyntax() {
XAbstractFeatureCall featureCall = getFeatureCall();
if (featureCall instanceof XBinaryOperation || featureCall instanceof XAssignment) {
@@ -255,16 +270,20 @@ public class FeatureLinkingCandidate extends AbstractPendingLinkingCandidate<XAb
return false;
}
- protected boolean isInstanceAccessSyntax() {
+ protected boolean isSimpleAssignment() {
if (getImplicitReceiverType() != null)
return true;
XAbstractFeatureCall featureCall = getFeatureCall();
if (featureCall instanceof XAssignment) {
- return ((XAssignment) featureCall).getAssignable() != null;
+ return isSimpleAssignment((XAssignment) featureCall);
}
return featureCall instanceof XMemberFeatureCall;
}
-
+
+ protected boolean isSimpleAssignment(XAssignment assignment) {
+ return assignment.getAssignable() != null;
+ }
+
protected List<XExpression> createArgumentList(XExpression head, List<XExpression> tail) {
// TODO investigate in optimized List impls like HEAD, syntacticArguments
List<XExpression> result = Lists.newArrayListWithExpectedSize(tail.size() + 1);
diff --git a/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/FeatureCallValidationTest.java b/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/FeatureCallValidationTest.java
index 767855e..6490d37 100644
--- a/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/FeatureCallValidationTest.java
+++ b/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/validation/FeatureCallValidationTest.java
@@ -307,6 +307,22 @@ public class FeatureCallValidationTest extends AbstractXtendTestCase {
XtendClass clazz = clazz("class X { static String foo def static meth() { foo = '' } }");
helper.assertNoErrors(clazz);
}
+
+ @Test public void testXAssignmentField5() throws Exception {
+ XtendClass clazz = clazz("class X { static String foo def meth() { X::foo = '' } }");
+ helper.assertNoErrors(clazz);
+ }
+
+ @Test public void testXAssignmentField6() throws Exception {
+ XtendClass clazz = clazz("class X { static String foo def meth() { X.foo = '' } }");
+ helper.assertNoErrors(clazz);
+ }
+
+ @Test public void testXAssignmentField7() throws Exception {
+ XtendClass clazz = clazz("class X { static String foo def meth() { (new X).foo = '' } }");
+ helper.assertError(clazz, XbasePackage.Literals.XASSIGNMENT,
+ org.eclipse.xtext.xbase.validation.IssueCodes.INSTANCE_ACCESS_TO_STATIC_MEMBER);
+ }
@Test public void testXFeatureCallOperation1() throws Exception {
XtendClass clazz = clazz("class X { def setFoo(String x) {} def meth() { setFoo('') } }");
@@ -375,6 +391,25 @@ public class FeatureCallValidationTest extends AbstractXtendTestCase {
helper.assertNoErrors(clazz);
}
+ @Test
+ public void testXAssignmentOperation5() throws Exception {
+ XtendClass clazz = clazz("class X { def static setFoo(String x) {} def meth() { X::foo = '' } }");
+ helper.assertNoErrors(clazz);
+ }
+
+ @Test
+ public void testXAssignmentOperation6() throws Exception {
+ XtendClass clazz = clazz("class X { def static setFoo(String x) {} def meth() { X.foo = '' } }");
+ helper.assertNoErrors(clazz);
+ }
+
+ @Test
+ public void testXAssignmentOperation7() throws Exception {
+ XtendClass clazz = clazz("class X { def static setFoo(String x) {} def meth() { (new X).foo = '' } }");
+ helper.assertError(clazz, XbasePackage.Literals.XASSIGNMENT,
+ org.eclipse.xtext.xbase.validation.IssueCodes.INSTANCE_ACCESS_TO_STATIC_MEMBER);
+ }
+
@Test public void testXMemberFeatureCallImportedMemberExtension1() throws Exception {
XtendClass clazz = clazz("class X { extension test.ExtensionMethods def meth() { 'foo'.instanceExtension } }");
helper.assertNoErrors(clazz);