use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testAutcastExpressions.
@Test
public void testAutcastExpressions() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val CharSequence c = \"\"");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (c instanceof String) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("c.substring(1, 1)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("switch(c){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("String : c.length");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
XtendMember _head_1 = IterableExtensions.<XtendMember>head(((XtendClass) _head).getMembers());
final XtendFunction func = ((XtendFunction) _head_1);
XExpression _expression = func.getExpression();
final XBlockExpression block = ((XBlockExpression) _expression);
final XExpression dec = IterableExtensions.<XExpression>head(block.getExpressions());
Assert.assertEquals("CharSequence c", this.signatureProvider.getSignature(dec));
XExpression _get = block.getExpressions().get(1);
final XIfExpression ifexpr = ((XIfExpression) _get);
final XExpression then = ifexpr.getThen();
XExpression _head_2 = IterableExtensions.<XExpression>head(((XBlockExpression) then).getExpressions());
final XExpression target = ((XMemberFeatureCall) _head_2).getMemberCallTarget();
Assert.assertEquals("String c", this.signatureProvider.getSignature(target));
XExpression _get_1 = block.getExpressions().get(2);
final XSwitchExpression switchExpr = ((XSwitchExpression) _get_1);
XExpression _then = IterableExtensions.<XCasePart>head(switchExpr.getCases()).getThen();
final XExpression expr = ((XMemberFeatureCall) _then).getMemberCallTarget();
Assert.assertEquals("String c", this.signatureProvider.getSignature(expr));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendUnsugaredHoverTest method testBug380361_2.
@Test
public void testBug380361_2() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testpackage");
_builder.newLine();
_builder.append("import static extension testpackage.Baz.*");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("String fieldInFoo");
_builder.newLine();
_builder.append("\t");
_builder.append("extension Extension");
_builder.newLine();
_builder.append("\t");
_builder.append("def void foo(Bar it) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("fieldInBar");
_builder.newLine();
_builder.append("\t\t");
_builder.append("fieldInExtension");
_builder.newLine();
_builder.append("\t\t");
_builder.append("fieldInFoo");
_builder.newLine();
_builder.append("\t\t");
_builder.append("staticFieldInBaz");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("public String fieldInBar");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class Baz {");
_builder.newLine();
_builder.append("\t");
_builder.append("public static String staticFieldInBaz");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.testHelper.xtendFile(XtendUnsugaredHoverTest.FILEPATH, _builder.toString());
XtendMember _get = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers().get(2);
final XtendFunction function = ((XtendFunction) _get);
XExpression _expression = function.getExpression();
final XBlockExpression block = ((XBlockExpression) _expression);
final XExpression call = block.getExpressions().get(0);
final XExpression call2 = block.getExpressions().get(1);
final XExpression call3 = block.getExpressions().get(2);
final XExpression call4 = block.getExpressions().get(3);
final XtendTypeDeclaration foo = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
XtendMember _get_1 = foo.getMembers().get(1);
final XtendField extensionField = ((XtendField) _get_1);
final JvmTypeReference extensionFieldType = extensionField.getType();
Assert.assertEquals("testpackage.Extension", extensionFieldType.getIdentifier());
Assert.assertEquals("it.fieldInBar", this.serializer.computeUnsugaredExpression(call));
Assert.assertEquals("this._extension.fieldInExtension", this.serializer.computeUnsugaredExpression(call2));
Assert.assertEquals("this.fieldInFoo", this.serializer.computeUnsugaredExpression(call3));
Assert.assertEquals("", this.serializer.computeUnsugaredExpression(call4));
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testAnnotationValues.
@Test
public void testAnnotationValues() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@test.Annotation(annotation2Value=@test.Annotation2(\'foo\'))");
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XAnnotationElementValuePair pair = IterableExtensions.<XAnnotationElementValuePair>head(IterableExtensions.<XAnnotation>head(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getAnnotations()).getElementValuePairs());
Object _evaluate = this.interpreter.evaluate(pair.getValue(), pair.getElement().getReturnType());
final XAnnotation anno = ((XAnnotation) _evaluate);
Assert.assertEquals("test.Annotation2", anno.getAnnotationType().getIdentifier());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class ProblemSupportTests method testErrorOnSource.
@Test
public void testErrorOnSource() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("String foo = \'foo\'");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
it.getProblemSupport().addError(IterableExtensions.head(it.getSourceTypeDeclarations()), "error on source");
Assert.assertEquals("error on source", IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors()).getMessage());
Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors());
Assert.assertEquals(IterableExtensions.<XtendTypeDeclaration>head(it.getXtendFile().getXtendTypes()), ((EObjectDiagnosticImpl) _head).getProblematicObject());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class Bug464760Test method testBug464760.
@Test
public void testBug464760() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void myMethod() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\"foo\".myExtension");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("def void myExtension(/*will be deleted programmatically*/Object notype) {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Resource _resource = this.resourceHelper.resource(_builder);
final XtextResource resource = ((XtextResource) _resource);
EObject _rootASTElement = resource.getParseResult().getRootASTElement();
final XtendFile xtendFile = ((XtendFile) _rootASTElement);
XtendMember _get = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers().get(1);
XtendParameter _head = IterableExtensions.<XtendParameter>head(((XtendFunction) _get).getParameters());
_head.setParameterType(null);
final Runnable _function = () -> {
EcoreUtil.resolveAll(resource);
};
final LoggingTester.LogCapture loggings = LoggingTester.captureLogging(Level.ERROR, BatchLinkableResource.class, _function);
loggings.assertNoLogEntries();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations