use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method addQuickfixes.
@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
if (referenceOwner instanceof XAbstractFeatureCall) {
XAbstractFeatureCall call = (XAbstractFeatureCall) referenceOwner;
String newMemberName = (issue.getData() != null && issue.getData().length > 0) ? issue.getData()[0] : null;
if (newMemberName != null) {
if (call instanceof XMemberFeatureCall) {
if (!call.isExplicitOperationCallOrBuilderSyntax()) {
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
}
newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
} else if (call instanceof XFeatureCall) {
if (!call.isExplicitOperationCallOrBuilderSyntax()) {
if (logicalContainerProvider.getNearestLogicalContainer(call) instanceof JvmExecutable)
newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
}
newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
} else if (call instanceof XAssignment) {
newSetterQuickfix(issue, issueResolutionAcceptor, newMemberName, call);
XAssignment assigment = (XAssignment) call;
if (assigment.getAssignable() == null) {
newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
} else if (isThis(assigment)) {
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
}
}
}
if (call.isOperation()) {
JvmIdentifiableElement feature = call.getFeature();
if (feature.eIsProxy()) {
String operatorMethodName = getOperatorMethodName(call);
if (operatorMethodName != null)
newMethodQuickfixes(operatorMethodName, call, issue, issueResolutionAcceptor);
}
}
if (call instanceof XFeatureCall && call.getFeature() instanceof JvmConstructor) {
newConstructorQuickfix(issue, issueResolutionAcceptor, (XFeatureCall) call);
}
}
if (referenceOwner instanceof XConstructorCall) {
newConstructorQuickfix(issue, issueResolutionAcceptor, (XConstructorCall) referenceOwner);
}
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method addConstuctorFromSuper.
@Fix(IssueCodes.MISSING_CONSTRUCTOR)
public void addConstuctorFromSuper(final Issue issue, IssueResolutionAcceptor acceptor) {
if (issue.getData() != null) {
for (int i = 0; i < issue.getData().length; i += 2) {
final URI constructorURI = URI.createURI(issue.getData()[i]);
String javaSignature = issue.getData()[i + 1];
String xtendSignature = "new" + javaSignature.substring(javaSignature.indexOf('('));
acceptor.accept(issue, "Add constructor " + xtendSignature, "Add constructor " + xtendSignature, "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
XtendClass clazz = (XtendClass) element;
JvmGenericType inferredType = associations.getInferredType(clazz);
ResolvedFeatures features = overrideHelper.getResolvedFeatures(inferredType);
ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) clazz.eResource(), insertionOffsets.getNewConstructorInsertOffset(null, clazz), 0, new OptionalParameters() {
{
ensureEmptyLinesAround = true;
baseIndentationLevel = 1;
}
});
EObject constructor = clazz.eResource().getResourceSet().getEObject(constructorURI, true);
if (constructor instanceof JvmConstructor) {
superMemberImplementor.appendConstructorFromSuper(clazz, new ResolvedConstructor((JvmConstructor) constructor, features.getType()), appendable);
}
appendable.commitChanges();
}
});
}
}
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class SuperMemberImplementorTest method checkImplementConstructor.
protected void checkImplementConstructor(final String firstParamType, String implementCode) {
StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
JvmConstructor constructor = Iterables.find(superClass.getDeclaredConstructors(), new Predicate<JvmConstructor>() {
@Override
public boolean apply(JvmConstructor c) {
if (firstParamType == null)
return c.getParameters().isEmpty();
if (c.getParameters().size() >= 1) {
return firstParamType.equals(c.getParameters().get(0).getParameterType().getSimpleName());
}
return false;
}
});
LightweightTypeReference contextType = getContextType();
ResolvedConstructor resolvedConstructor = new ResolvedConstructor(constructor, contextType);
implementor.appendConstructorFromSuper(xtendClass, resolvedConstructor, appendable);
String code = appendable.toString();
if (!equalsIgnoreWhitespace(implementCode, code))
assertEquals(implementCode, code);
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class FindReferencesTest method testFindReferencesToAnonymousExplicitSuperConstructor.
@Test
public void testFindReferencesToAnonymousExplicitSuperConstructor() throws Exception {
XtendClass classFoo = (XtendClass) testHelper.xtendFile("Foo", "class Foo { new() {} }").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((XtendConstructor) classFoo.getMembers().get(0));
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.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class JvmModelTests method testAnonymousClass_02.
@Test
public void testAnonymousClass_02() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Runnable() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override run() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
this.typeResolver.resolveTypes(operation.eResource());
Assert.assertEquals(1, operation.getLocalClasses().size());
final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
Assert.assertTrue(anonymous.isFinal());
Assert.assertFalse(anonymous.isStatic());
Assert.assertTrue(anonymous.isLocal());
Assert.assertTrue(anonymous.isAnonymous());
Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
Assert.assertEquals(2, anonymous.getSuperTypes().size());
Assert.assertEquals("java.lang.Runnable", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
Assert.assertEquals(2, anonymous.getMembers().size());
final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
Assert.assertTrue((constructor instanceof JvmConstructor));
Assert.assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
final JvmMember overriding = IterableExtensions.<JvmMember>head(anonymous.getMembers());
Assert.assertTrue((overriding instanceof JvmOperation));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations