Search in sources :

Example 46 with QuickfixTestBuilder

use of org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder in project xtext-xtend by eclipse.

the class QuickfixTest method missingOverride.

@Test
public void missingOverride() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo implements Comparable<Foo> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def comp|areTo(Foo o) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    QuickfixTestBuilder _assertResolutionLabels = this.builder.create("Foo.xtend", _builder).assertIssueCodes(org.eclipse.xtend.core.validation.IssueCodes.MISSING_OVERRIDE).assertResolutionLabels("Change \'def\' to \'override\'");
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Foo implements Comparable<Foo> {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("override compareTo(Foo o) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("1");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _assertResolutionLabels.assertModelAfterQuickfix(_builder_1);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) QuickfixTestBuilder(org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder) Test(org.junit.Test)

Example 47 with QuickfixTestBuilder

use of org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder in project xtext-xtend by eclipse.

the class QuickfixTest method unhandledCheckedExceptionForJvmConstructor2.

@Test
public void unhandledCheckedExceptionForJvmConstructor2() {
    this.builder.setSeverity(IssueCodes.UNHANDLED_EXCEPTION, "error");
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("super()");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("foo|()");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() throws Exception {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    QuickfixTestBuilder _assertResolutionLabels = this.builder.create("Foo.xtend", _builder).assertIssueCodes(IssueCodes.UNHANDLED_EXCEPTION).assertResolutionLabels("Add throws declaration", "Surround with try/catch block");
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("new() throws Exception {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("super()");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("foo()");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def foo() throws Exception {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    QuickfixTestBuilder _assertModelAfterQuickfix = _assertResolutionLabels.assertModelAfterQuickfix("Add throws declaration", _builder_1);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("class Foo {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("new() {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("super()");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("try {");
    _builder_2.newLine();
    _builder_2.append("\t\t\t");
    _builder_2.append("foo()");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("} catch (Exception exc) {");
    _builder_2.newLine();
    _builder_2.append("\t\t\t");
    _builder_2.append("throw new RuntimeException(\"auto-generated try/catch\", exc)");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def foo() throws Exception {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    _assertModelAfterQuickfix.assertModelAfterQuickfix("Surround with try/catch block", _builder_2);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) QuickfixTestBuilder(org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder) Test(org.junit.Test)

Example 48 with QuickfixTestBuilder

use of org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder in project xtext-xtend by eclipse.

the class QuickfixTest method missingStaticMemberOtherClass.

@Test
public void missingStaticMemberOtherClass() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Bar {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("Foo.foo|");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    QuickfixTestBuilder _assertResolutionLabels = this.builder.create("Foo.xtend", _builder).assertFeatureCallLinkingIssue().assertResolutionLabels("Create static method \'foo()\' in \'Foo\'", "Create static method \'getFoo()\' in \'Foo\'");
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def static foo() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append(QuickfixTest.defaultBody, "\t\t");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Bar {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def bar() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("Foo.foo");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    QuickfixTestBuilder _assertModelAfterQuickfix = _assertResolutionLabels.assertModelAfterQuickfix("Create static method \'foo()\' in \'Foo\'", _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("def static getFoo() {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append(QuickfixTest.defaultBody, "\t\t");
    _builder_2.newLineIfNotEmpty();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("class Bar {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def bar() {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("Foo.foo");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    _assertModelAfterQuickfix.assertModelAfterQuickfix("Create static method \'getFoo()\' in \'Foo\'", _builder_2);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) QuickfixTestBuilder(org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder) Test(org.junit.Test)

Example 49 with QuickfixTestBuilder

use of org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder in project xtext-xtend by eclipse.

the class QuickfixTest method redundantModifiers_07.

@Test
public void redundantModifiers_07() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("f|inal val a = 1");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    QuickfixTestBuilder _assertResolutionLabels = this.builder.create("Foo.xtend", _builder).assertIssueCodes(org.eclipse.xtend.core.validation.IssueCodes.REDUNDANT_MODIFIER).assertResolutionLabels("Remove the redundant modifier.");
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("val a = 1");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _assertResolutionLabels.assertModelAfterQuickfix(_builder_1);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) QuickfixTestBuilder(org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder) Test(org.junit.Test)

Example 50 with QuickfixTestBuilder

use of org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder in project xtext-xtend by eclipse.

the class QuickfixTest method unreachableIfBlock_4.

@Test
public void unreachableIfBlock_4() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.io.IOException");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Object y");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(Object x) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (x instanceof Exception) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("1");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} else if (y instanceof Exception) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("2");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} else if (Bar.z instanceof Exception) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("1");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} else if (x instanceof IOException) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("2");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} else if (y instanceof IOExc|eption) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("2");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} else if (Bar.z instanceof IOException) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("2");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Bar {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static Object z");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    QuickfixTestBuilder _assertResolutionLabels = this.builder.create("Foo.xtend", _builder).assertIssueCodes(IssueCodes.UNREACHABLE_IF_BLOCK).assertResolutionLabels("Remove if block", "Move if block up");
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.io.IOException");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("Object y");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def foo(Object x) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("if (x instanceof Exception) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("1");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("} else if (y instanceof IOException) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("2");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("} else if (y instanceof Exception) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("2");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("} else if (Bar.z instanceof Exception) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("1");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("} else if (x instanceof IOException) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("2");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("} else if (Bar.z instanceof IOException) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("2");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Bar {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("public static Object z");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _assertResolutionLabels.assertModelAfterQuickfix("Move if block up", _builder_1);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) QuickfixTestBuilder(org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder) Test(org.junit.Test)

Aggregations

QuickfixTestBuilder (org.eclipse.xtend.ide.tests.quickfix.QuickfixTestBuilder)122 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)122 Test (org.junit.Test)122 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1