Search in sources :

Example 6 with JvmExecutable

use of org.eclipse.xtext.common.types.JvmExecutable in project xtext-xtend by eclipse.

the class XtendHoverSerializer method computeUnsugaredExpression.

public String computeUnsugaredExpression(EObject object) {
    if (object instanceof XAbstractFeatureCall) {
        StringBuilder stringBuilder = new StringBuilder();
        XAbstractFeatureCall featureCall = (XAbstractFeatureCall) object;
        JvmIdentifiableElement feature = featureCall.getFeature();
        if (feature != null && !feature.eIsProxy()) {
            // Static extensions which are no expliciteOperationCalls
            if (featureCall instanceof XMemberFeatureCall && feature instanceof JvmOperation && !((XMemberFeatureCall) featureCall).isExplicitOperationCall()) {
                JvmOperation jvmOperation = (JvmOperation) feature;
                if (jvmOperation.isStatic()) {
                    return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, jvmOperation)).toString();
                }
            }
            // Static calls with implicit receiver or implicit first argument
            if (featureCall.getImplicitReceiver() != null || featureCall.getImplicitFirstArgument() != null) {
                if (featureCall.isStatic()) {
                    return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, (JvmMember) feature)).toString();
                }
                XExpression receiver = featureCall.getActualReceiver();
                if (receiver instanceof XMemberFeatureCall) {
                    stringBuilder.append(THIS).append(DELIMITER);
                    stringBuilder.append(((XMemberFeatureCall) receiver).getFeature().getSimpleName()).append(DELIMITER);
                } else if (receiver instanceof XAbstractFeatureCall) {
                    JvmIdentifiableElement receiverFeature = ((XAbstractFeatureCall) receiver).getFeature();
                    if (receiverFeature == feature.eContainer()) {
                        stringBuilder.append(THIS).append(DELIMITER);
                    } else {
                        stringBuilder.append(receiverFeature.getSimpleName()).append(DELIMITER);
                    }
                }
                stringBuilder.append(feature.getSimpleName());
                if (feature instanceof JvmExecutable)
                    stringBuilder.append(computeArguments(featureCall));
                return stringBuilder.toString();
            }
        }
    }
    return "";
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Example 7 with JvmExecutable

use of org.eclipse.xtext.common.types.JvmExecutable 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 8 with JvmExecutable

use of org.eclipse.xtext.common.types.JvmExecutable in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testXtendField_00.

@Test
public void testXtendField_00() throws Exception {
    XtendFile xtendFile = file("class Foo { @Inject String string }");
    JvmGenericType type = getInferredType(xtendFile);
    Iterable<JvmField> iterable = type.getDeclaredFields();
    JvmField next = iterable.iterator().next();
    assertEquals("string", next.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, next.getVisibility());
    assertEquals("java.lang.String", next.getType().getIdentifier());
    for (JvmMember member : type.getMembers()) {
        if (member instanceof JvmExecutable) {
            assertEquals(JvmVisibility.PUBLIC, member.getVisibility());
        } else {
            assertEquals(JvmVisibility.PRIVATE, member.getVisibility());
        }
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Aggregations

JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)8 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)3 JvmMember (org.eclipse.xtext.common.types.JvmMember)3 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)3 EObject (org.eclipse.emf.ecore.EObject)2 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)2 JvmField (org.eclipse.xtext.common.types.JvmField)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 Matcher (java.util.regex.Matcher)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 StyledString (org.eclipse.jface.viewers.StyledString)1 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)1 RichString (org.eclipse.xtend.core.xtend.RichString)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 XtendExecutable (org.eclipse.xtend.core.xtend.XtendExecutable)1 AbstractParameterBuilder (org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder)1 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)1