Search in sources :

Example 31 with XtendField

use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.

the class CodeStyleValidationTest method testInferedApiField05.

@Test
public void testInferedApiField05() throws Exception {
    XtendField field = field("val f = \"foo\" ");
    helper.assertNoIssue(field, XTEND_FIELD, API_TYPE_INFERENCE);
}
Also used : XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 32 with XtendField

use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.

the class UIStringsTest method testReferenceToString_4.

@Test
public void testReferenceToString_4() throws Exception {
    XtendFile file = file("class Foo { var test }");
    assertFalse(validationTestHelper.validate(file).isEmpty());
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
    XtendField field = (XtendField) clazz.getMembers().get(0);
    JvmField jvmField = associations.getJvmField(field);
    JvmTypeReference reference = jvmField.getType();
    assertNotNull(reference);
    assertNotNull(reference.getType());
    assertFalse(reference.getType().eIsProxy());
    assertNotNull(reference.eResource());
    assertEquals("Object", this.uiStrings.referenceToString(reference, "the-default-label"));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 33 with XtendField

use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.

the class FindReferencesTest method testFindReferencesToAnonymousSuperType.

@Test
public void testFindReferencesToAnonymousSuperType() throws Exception {
    XtendClass classFoo = (XtendClass) testHelper.xtendFile("Foo", "class Foo {}").getXtendTypes().get(0);
    XtendClass classBar = (XtendClass) testHelper.xtendFile("Bar", "class Bar { val foo = new Foo{} }").getXtendTypes().get(0);
    waitForBuild();
    XtendField fieldFoo = (XtendField) classBar.getMembers().get(0);
    JvmGenericType inferredTypeFoo = associations.getInferredType(classFoo);
    final MockAcceptor mockAcceptor = new MockAcceptor();
    mockAcceptor.expect(((AnonymousClass) fieldFoo.getInitialValue()).getConstructorCall(), inferredTypeFoo, XCONSTRUCTOR_CALL__CONSTRUCTOR);
    findReferencesTester.checkFindReferences(inferredTypeFoo, "Java References to Foo (/test.project/src/Foo.xtend)", mockAcceptor);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) MockAcceptor(org.eclipse.xtend.ide.tests.findrefs.FindReferencesTestUtil.MockAcceptor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 34 with XtendField

use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.

the class FindReferencesTest method testFindReferencesToAnonymousImplicitSuperConstructor.

@Test
public void testFindReferencesToAnonymousImplicitSuperConstructor() throws Exception {
    XtendClass classFoo = (XtendClass) testHelper.xtendFile("Foo", "class Foo {}").getXtendTypes().get(0);
    XtendClass classBar = (XtendClass) testHelper.xtendFile("Bar", "class Bar { val foo = new Foo{} }").getXtendTypes().get(0);
    waitForBuild();
    XtendField fieldFoo = (XtendField) classBar.getMembers().get(0);
    JvmConstructor inferredConstructor = associations.getInferredConstructor(classFoo);
    final MockAcceptor mockAcceptor = new MockAcceptor();
    mockAcceptor.expect(((AnonymousClass) fieldFoo.getInitialValue()).getConstructorCall(), inferredConstructor, XCONSTRUCTOR_CALL__CONSTRUCTOR);
    findReferencesTester.checkFindReferences(inferredConstructor, "Java References to Foo (/test.project/src/Foo.xtend)", mockAcceptor);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) MockAcceptor(org.eclipse.xtend.ide.tests.findrefs.FindReferencesTestUtil.MockAcceptor) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 35 with XtendField

use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.

the class XtendQuickfixProvider method specifyTypeExplicitly.

@Fix(IssueCodes.API_TYPE_INFERENCE)
public void specifyTypeExplicitly(Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, "Infer type", "Infer type", null, new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            EStructuralFeature featureAfterType = null;
            JvmIdentifiableElement jvmElement = null;
            if (element instanceof XtendFunction) {
                XtendFunction function = (XtendFunction) element;
                if (function.getCreateExtensionInfo() == null) {
                    featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__NAME;
                } else {
                    featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__CREATE_EXTENSION_INFO;
                }
                jvmElement = associations.getDirectlyInferredOperation((XtendFunction) element);
            } else if (element instanceof XtendField) {
                featureAfterType = XtendPackage.Literals.XTEND_FIELD__NAME;
                jvmElement = associations.getJvmField((XtendField) element);
            }
            if (jvmElement != null) {
                LightweightTypeReference type = batchTypeResolver.resolveTypes(element).getActualType(jvmElement);
                INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(element, featureAfterType), null);
                if (node == null) {
                    throw new IllegalStateException("Could not determine node for " + element);
                }
                if (type == null) {
                    throw new IllegalStateException("Could not determine type for " + element);
                }
                ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) element.eResource(), node.getOffset(), 0);
                appendable.append(type);
                appendable.append(" ");
                appendable.commitChanges();
            }
        }
    });
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) INode(org.eclipse.xtext.nodemodel.INode) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) XtendField(org.eclipse.xtend.core.xtend.XtendField) EObject(org.eclipse.emf.ecore.EObject) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

XtendField (org.eclipse.xtend.core.xtend.XtendField)71 Test (org.junit.Test)50 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)38 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)33 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)29 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)23 XExpression (org.eclipse.xtext.xbase.XExpression)23 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)14 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)12 EObject (org.eclipse.emf.ecore.EObject)8 RichString (org.eclipse.xtend.core.xtend.RichString)7 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)6 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)6 XClosure (org.eclipse.xtext.xbase.XClosure)6 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)5 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)5 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3