Java源码示例:org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder
示例1
@Test
public void testExtensionLocal_01() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m(int i) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val extension String s = null");
_builder.newLine();
_builder.append("\t\t");
_builder.append("i.");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposal("subSequence()").withDisplayString("subSequence(int endIndex) : CharSequence - String");
}
示例2
@Test
public void test_15() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("C.thi<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("this");
}
示例3
@Test
public void test_02() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotation MyTest {");
_builder.newLine();
_builder.append("\t");
_builder.append("static class MyInner {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor(Strings.toPlatformLineSeparator("\n\t\toverride toString() {\n\t\t\tsuper.toString()\n\t\t}\n\t\t"));
}
示例4
@Test
public void test_17() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("C::thi<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertNoProposalAtCursor("this");
}
示例5
@Test
public void test_04() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("val o = new Object() {");
_builder.newLine();
_builder.append(" \t");
_builder.append("String s");
_builder.newLine();
_builder.append(" \t");
_builder.append("toS<|>");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("override toString() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalDisplayedAtCursor("toString() - Override method from Object");
}
示例6
@Test
public void test_01() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotation MyTest {");
_builder.newLine();
_builder.append("\t");
_builder.append("static class MyInner {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("toSt<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor(Strings.toPlatformLineSeparator("\n\t\toverride toString() {\n\t\t\tsuper.toString()\n\t\t}\n\t\t"));
}
示例7
@Test
public void test_05() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import com.google.common.collect.ImmutableList");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("def static m(List<String> list, String value) {");
_builder.newLine();
_builder.append(" ");
_builder.append("ImmutableList.builder.addAll(list.<|>filter[it != value]).build");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("filter[]");
}
示例8
@Test
public void test_16() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("C.sup<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("super");
}
示例9
@Test
public void test_01() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.util.List");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("package val f1 = newArrayList(1)");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("var List<Object> f2");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("var f3 = new StringBuilde|");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertTextAtCursorPosition("|", "StringBuilder");
}
示例10
@Flaky
@Test
public void test_01() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void method(CharSequence c) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("c.toString");
_builder.newLine();
_builder.append("\t");
_builder.append("}\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertTextAtCursorPosition("toString", "toString".length(),
"!=", "!==", "+", "->", "<", "<=", "<=>", "==", "===", "=>", ">", ">=", "?:",
"toString");
}
示例11
@Test
public void test_20() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("static class C2 {");
_builder.newLine();
_builder.append(" \t");
_builder.append("def s() {}");
_builder.newLine();
_builder.append(" \t");
_builder.append("toS<|>");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("override toString() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalDisplayedAtCursor("toString() - Override method from Object");
}
示例12
@Test
public void test_16() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("static class C2 {");
_builder.newLine();
_builder.append(" \t");
_builder.append("String s");
_builder.newLine();
_builder.append(" \t");
_builder.append("toS<|>");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("override toString() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalDisplayedAtCursor("toString() - Override method from Object");
}
示例13
@Test
public void test_02() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("val o = new Object() {");
_builder.newLine();
_builder.append(" \t");
_builder.append("toS<|>");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("override toString() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalDisplayedAtCursor("toString() - Override method from Object");
}
示例14
@Test
public void test_15() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("static class C2 {");
_builder.newLine();
_builder.append(" \t");
_builder.append("String s");
_builder.newLine();
_builder.append(" \t");
_builder.append("<|>");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("override toString() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalDisplayedAtCursor("toString() - Override method from Object");
}
示例15
@Test
public void testMemberName_4() {
try {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("package org.eclipse.xtend.ide.tests.data.contentassist");
_builder.newLine();
_builder.newLine();
_builder.append("import static org.eclipse.xtend.ide.tests.data.contentassist.Foo.default");
_builder.newLine();
_builder.newLine();
_builder.append("class Bar {}");
_newBuilder.append(_builder.toString()).assertTextAtCursorPosition("default", "default".length(), "defaultStaticMethod", "defaultStaticField");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例16
@Test
public void test_06() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import com.google.common.collect.ImmutableList");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("def static m(List<? super String> list, String value) {");
_builder.newLine();
_builder.append(" ");
_builder.append("ImmutableList.builder.addAll(list.<|>filter[it != value]).build");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("filter[]");
}
示例17
@Test
public void test_19() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("static def void m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("C.thi<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertNoProposalAtCursor("this");
}
示例18
@Test
public void test_01() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import com.google.common.collect.ImmutableList");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("def static <T> m(List<? extends T> list, T value) {");
_builder.newLine();
_builder.append(" ");
_builder.append("ImmutableList.builder.addAll(list.<|>filter[it != value]).build");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("filter[]");
}
示例19
@Test
public void test_02() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import com.google.common.collect.ImmutableList");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("def static <T> m(List<T> list, T value) {");
_builder.newLine();
_builder.append(" ");
_builder.append("ImmutableList.builder.addAll(list.<|>filter[it != value]).build");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("filter[]");
}
示例20
@Test
public void test_02() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static extension C.Foo.*");
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("static class Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("static class Foo {");
_builder.newLine();
_builder.append("\t ");
_builder.append("static def sum(Bar[] bars) {");
_builder.newLine();
_builder.append("\t ");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("def doit(Iterable<Bar> myBars) {");
_builder.newLine();
_builder.append(" ");
_builder.append("myBars.sum<|>");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("sum");
}
示例21
@Test
public void testExtensionPrecendence_03() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m(java.util.List<String> s) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("s.map<|>");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("map[]").withDisplayString("map((T)=>R transformation) : List<R> - ListExtensions");
}
示例22
@Test
public void test_08() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("static def String getThingyDingy() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\'\'");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("static def void m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("C.thin<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("thingyDingy");
}
示例23
@Test
public void test_03() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.io.*");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("def static void main(String[] args) {");
_builder.newLine();
_builder.append(" ");
_builder.append("val in = new InputStream {");
_builder.newLine();
_builder.append(" ");
_builder.append("val bytes = new ByteArrayInputStream(\"\".bytes)");
_builder.newLine();
_builder.append(" ");
_builder.append("override read() throws IOException {");
_builder.newLine();
_builder.append(" ");
_builder.append("ar|gs.toString");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertTextAtCursorPosition("|", "args");
}
示例24
@Test
public void testExtensionForLoopParameter_01() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m(int it) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("for(extension String s : newArrayList) ");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposal("charAt").withDisplayString("charAt : char - String.charAt()");
}
示例25
@Test
public void testBug463053_03() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("@A(#[<|>])");
_builder.newLine();
_builder.append("\t");
_builder.append("String s3");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("annotation A {");
_builder.newLine();
_builder.append("\t");
_builder.append("E[] value");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("enum E {");
_builder.newLine();
_builder.append("\t");
_builder.append("NAME");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalAtCursor("NAME");
}
示例26
@Test
public void test_13() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def String getThingyDingy() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\'\'");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("static def void m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("C.getThin<|>");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertNoProposalAtCursor("thingyDingy");
}
示例27
@Test public void testBug276742_09b() throws Exception {
String modelAsString = "Foo {}";
ContentAssistProcessorTestBuilder builder = newBuilder();
XtextContentAssistProcessor processor = get(XtextContentAssistProcessor.class);
XtextResource resource = getResourceFromString(modelAsString);
ITextViewer viewer = builder.getSourceViewer(modelAsString, builder.getDocument(resource, modelAsString));
ContentAssistContext[] contexts = processor.getContextFactory().create(viewer, 0, resource);
assertEquals(1, contexts.length);
for (ContentAssistContext context : contexts) {
assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, context.getCurrentModel().eClass());
}
}
示例28
@Test
public void test_06() throws Exception {
ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append(" ");
_builder.append("val o = new Object() {");
_builder.newLine();
_builder.append(" \t");
_builder.append("String s");
_builder.newLine();
_builder.append(" \t");
_builder.append("toS<|>");
_builder.newLine();
_builder.append(" \t");
_builder.append("String s2");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("override toString() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_newBuilder.append(_builder.toString()).assertProposalDisplayedAtCursor("toString() - Override method from Object");
}
示例29
private ContentAssistProcessorTestBuilder doTestCompleteTypeRefSetup() throws Exception {
return newBuilder()
.appendNl("grammar org.xtext.example.MyDsl1 with org.eclipse.xtext.common.Terminals")
.appendNl("generate myDsl1 \"http://www.xtext.org/example/MyDsl1\"")
.appendNl("Model :")
.appendNl("(imports+=Import)*")
.appendNl("(elements+=Class)*;")
.appendNl("Import :")
.appendNl("'import' importURI=STRING;")
.appendNl("Class :")
.appendNl("'class' name=ID ('extends' references=[Class])?;");
}
示例30
private ContentAssistProcessorTestBuilder doTestCompleteTypeRefWithAliasSetup() throws Exception {
return newBuilder()
.appendNl("grammar org.xtext.example.MyDsl1 with org.eclipse.xtext.common.Terminals")
.appendNl("generate myDsl1 \"http://www.xtext.org/example/MyDsl1\" as myAlias")
.appendNl("Model returns myAlias::Model:")
.appendNl("(imports+=Import)*")
.appendNl("(elements+=Class)*;")
.appendNl("Import returns myAlias::Import:")
.appendNl("'import' importURI=STRING;")
.appendNl("Class returns myAlias::Class:")
.appendNl("'class' name=ID ('extends' references=[Class])?;");
}