use of org.eclipse.xtext.xbase.XAssignment in project xtext-xtend by eclipse.
the class AssignmentLinkingTest method testBug447982_04.
@Test
public void testBug447982_04() throws Exception {
XtendClass clazz = clazz("class C {\n" + " def static m() {\n" + " x = 1\n" + " } \n" + " static int x\n" + " def static setX(int x) {}\n" + "}");
XAssignment assignment = getLastAssignment(clazz);
assertLinksTo("C.x", TypesPackage.Literals.JVM_FIELD, assignment);
}
use of org.eclipse.xtext.xbase.XAssignment in project xtext-xtend by eclipse.
the class AssignmentLinkingTest method testSugaredAssignment_onThis.
@Test
public void testSugaredAssignment_onThis() throws Exception {
XtendClass clazz = clazz("class SomeClass {\n" + " def void method() {\n" + " string = 'foo'\n" + " }" + " def setString(String aString) {}\n" + "}");
XAssignment assignment = getLastAssignment(clazz);
assertLinksTo("SomeClass.setString(java.lang.String)", assignment);
assertImplicitReceiver("SomeClass", assignment);
}
use of org.eclipse.xtext.xbase.XAssignment in project xtext-xtend by eclipse.
the class AssignmentLinkingTest method testSugaredAssignment_onThis_withIt.
@Test
public void testSugaredAssignment_onThis_withIt() throws Exception {
XtendClass clazz = clazz("class SomeClass {\n" + " def void method(String it) {\n" + " value = 'foo'\n" + " }\n" + " def void setValue(String receiver, String value) {}" + "}");
XAssignment assignment = getLastAssignment(clazz);
assertLinksTo("SomeClass.setValue(java.lang.String,java.lang.String)", assignment);
assertImplicitReceiver("SomeClass", assignment);
}
use of org.eclipse.xtext.xbase.XAssignment 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.xbase.XAssignment in project xtext-xtend by eclipse.
the class LinkingTest method testDeclaredConstructor_01.
@Test
public void testDeclaredConstructor_01() throws Exception {
XtendClass clazz = clazz("class Foo { " + " int i" + " new(int i) { this.i = i }" + "}");
assertEquals(2, clazz.getMembers().size());
XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
XAssignment assignment = (XAssignment) ((XBlockExpression) constructor.getExpression()).getExpressions().get(0);
JvmField field = (JvmField) assignment.getFeature();
assertEquals("i", field.getSimpleName());
XFeatureCall target = (XFeatureCall) assignment.getAssignable();
JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
assertEquals("Foo", identifiableElement.getSimpleName());
XFeatureCall value = (XFeatureCall) assignment.getValue();
JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
assertEquals("i", parameter.getSimpleName());
}
Aggregations