summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakosyakov2013-07-05 11:55:47 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-07-09 13:35:16 (EDT)
commitc4ba7cb50a4518b6838490bf9733fa0394f421b6 (patch)
tree691fff237cb533795e7ac09bc5c9c04b9b0e6f2b
parent8b9487920b0c8cf4192da7083c6455d3673ed04c (diff)
downloadorg.eclipse.xtext-c4ba7cb50a4518b6838490bf9733fa0394f421b6.zip
org.eclipse.xtext-c4ba7cb50a4518b6838490bf9733fa0394f421b6.tar.gz
org.eclipse.xtext-c4ba7cb50a4518b6838490bf9733fa0394f421b6.tar.bz2
[412402]: resolved - added create field proposal for an assignment withrefs/changes/21/14321/6
this Change-Id: Ia2475fda0ca259bb218e9b13de2b3ffdfe0d9cc0 Signed-off-by: akosyakov <anton.kosyakov@itemis.de>
-rw-r--r--plugins/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/quickfix/CreateMemberQuickfixes.java15
-rw-r--r--tests/org.eclipse.xtend.ide.tests/src-longrunning/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.xtend37
-rw-r--r--tests/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.java70
3 files changed, 120 insertions, 2 deletions
diff --git a/plugins/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/quickfix/CreateMemberQuickfixes.java b/plugins/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/quickfix/CreateMemberQuickfixes.java
index c2943b4..33d3695 100644
--- a/plugins/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/quickfix/CreateMemberQuickfixes.java
+++ b/plugins/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/quickfix/CreateMemberQuickfixes.java
@@ -127,9 +127,12 @@ public class CreateMemberQuickfixes implements ILinkingIssueQuickfixProvider {
} else if (call instanceof XAssignment) {
newSetterQuickfix(issue, issueResolutionAcceptor, newMemberName, call);
- if(((XAssignment) call).getAssignable() == null) {
+ XAssignment assigment = (XAssignment) call;
+ if(assigment.getAssignable() == null) {
newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
+ } else if (isThis(assigment)) {
+ newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
}
}
}
@@ -150,6 +153,16 @@ public class CreateMemberQuickfixes implements ILinkingIssueQuickfixProvider {
}
}
+ protected boolean isThis(XAssignment assigment) {
+ XExpression assignable = assigment.getAssignable();
+ if (!(assignable instanceof XAbstractFeatureCall)) {
+ return false;
+ }
+ XAbstractFeatureCall featureCall = (XAbstractFeatureCall) assignable;
+ return featureCall.getFeature() instanceof JvmDeclaredType
+ && !featureCall.isExplicitOperationCallOrBuilderSyntax() && !featureCall.isTypeLiteral();
+ }
+
protected String getAccessorMethodName(String prefix, String fieldName) {
return prefix + fieldName.substring(0,1).toUpperCase() + fieldName.substring(1);
}
diff --git a/tests/org.eclipse.xtend.ide.tests/src-longrunning/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.xtend b/tests/org.eclipse.xtend.ide.tests/src-longrunning/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.xtend
index 6a7d6d2..234b86e 100644
--- a/tests/org.eclipse.xtend.ide.tests/src-longrunning/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.xtend
+++ b/tests/org.eclipse.xtend.ide.tests/src-longrunning/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.xtend
@@ -201,6 +201,40 @@ class QuickfixTest extends AbstractXtendUITestCase {
''')
}
+ @Test
+ def void missingMemberWithAssigmentExplicitThis() {
+ create('Foo.xtend', '''
+ class Foo {
+ def foo() {
+ this.bar| = 0L
+ }
+ }
+ ''')
+ .assertResolutionLabels("Create method 'setBar(long)'", "Create field 'bar'")
+ .assertModelAfterQuickfix("Create method 'setBar(long)'", '''
+ class Foo {
+ def foo() {
+ this.bar = 0L
+ }
+
+ def setBar(long l) {
+ «defaultBody»
+ }
+
+ }
+ ''')
+ .assertModelAfterQuickfix("Create field 'bar'", '''
+ class Foo {
+
+ long bar
+
+ def foo() {
+ this.bar = 0L
+ }
+ }
+ ''')
+ }
+
@Test
def void missingMemberExplicitThis() {
create('Foo.xtend', '''
@@ -1276,6 +1310,7 @@ class QuickfixTest extends AbstractXtendUITestCase {
}
''')
- }
+ }
+
}
diff --git a/tests/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.java b/tests/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.java
index a66923d..d96a07a 100644
--- a/tests/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.java
+++ b/tests/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/quickfix/QuickfixTest.java
@@ -349,6 +349,76 @@ public class QuickfixTest extends AbstractXtendUITestCase {
}
@Test
+ public void missingMemberWithAssigmentExplicitThis() {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("class Foo {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("def foo() {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("this.bar| = 0L");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ QuickfixTestBuilder _create = this.builder.create("Foo.xtend", _builder);
+ QuickfixTestBuilder _assertResolutionLabels = _create.assertResolutionLabels("Create method \'setBar(long)\'", "Create field \'bar\'");
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("class Foo {");
+ _builder_1.newLine();
+ _builder_1.append("\t");
+ _builder_1.append("def foo() {");
+ _builder_1.newLine();
+ _builder_1.append("\t\t");
+ _builder_1.append("this.bar = 0L");
+ _builder_1.newLine();
+ _builder_1.append("\t");
+ _builder_1.append("}");
+ _builder_1.newLine();
+ _builder_1.append("\t");
+ _builder_1.newLine();
+ _builder_1.append("\t");
+ _builder_1.append("def setBar(long l) {");
+ _builder_1.newLine();
+ _builder_1.append("\t\t");
+ _builder_1.append(QuickfixTest.defaultBody, " ");
+ _builder_1.newLineIfNotEmpty();
+ _builder_1.append("\t");
+ _builder_1.append("}");
+ _builder_1.newLine();
+ _builder_1.append("\t");
+ _builder_1.newLine();
+ _builder_1.append("}");
+ _builder_1.newLine();
+ QuickfixTestBuilder _assertModelAfterQuickfix = _assertResolutionLabels.assertModelAfterQuickfix("Create method \'setBar(long)\'", _builder_1);
+ StringConcatenation _builder_2 = new StringConcatenation();
+ _builder_2.append("class Foo {");
+ _builder_2.newLine();
+ _builder_2.append("\t");
+ _builder_2.newLine();
+ _builder_2.append("\t");
+ _builder_2.append("long bar");
+ _builder_2.newLine();
+ _builder_2.append("\t");
+ _builder_2.newLine();
+ _builder_2.append("\t");
+ _builder_2.append("def foo() {");
+ _builder_2.newLine();
+ _builder_2.append("\t\t");
+ _builder_2.append("this.bar = 0L");
+ _builder_2.newLine();
+ _builder_2.append("\t");
+ _builder_2.append("}");
+ _builder_2.newLine();
+ _builder_2.append("}");
+ _builder_2.newLine();
+ _assertModelAfterQuickfix.assertModelAfterQuickfix("Create field \'bar\'", _builder_2);
+ }
+
+ @Test
public void missingMemberExplicitThis() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");