Search in sources :

Example 96 with XtendTypeDeclaration

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 97 with XtendTypeDeclaration

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));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 98 with XtendTypeDeclaration

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XAnnotationElementValuePair(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 99 with XtendTypeDeclaration

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);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 100 with XtendTypeDeclaration

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) LoggingTester(org.eclipse.xtext.testing.logging.LoggingTester) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)134 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)98 Test (org.junit.Test)91 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)77 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)34 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)12 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8