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);
}
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"));
}
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);
}
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);
}
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();
}
}
});
}
Aggregations