Search in sources :

Example 6 with XAssignment

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);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Example 7 with XAssignment

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);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Example 8 with XAssignment

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);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Example 9 with XAssignment

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);
    }
}
Also used : JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) XAssignment(org.eclipse.xtext.xbase.XAssignment)

Example 10 with XAssignment

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());
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmField(org.eclipse.xtext.common.types.JvmField) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Aggregations

XAssignment (org.eclipse.xtext.xbase.XAssignment)22 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)19 Test (org.junit.Test)19 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)4 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)3 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)2 XExpression (org.eclipse.xtext.xbase.XExpression)2 EPackage (org.eclipse.emf.ecore.EPackage)1 RichString (org.eclipse.xtend.core.xtend.RichString)1 RichStringLiteral (org.eclipse.xtend.core.xtend.RichStringLiteral)1 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)1 XtendEnum (org.eclipse.xtend.core.xtend.XtendEnum)1 XtendField (org.eclipse.xtend.core.xtend.XtendField)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 XtendFormalParameter (org.eclipse.xtend.core.xtend.XtendFormalParameter)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 XtendInterface (org.eclipse.xtend.core.xtend.XtendInterface)1