Search in sources :

Example 1 with JvmFeature

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

the class XtypeProposalProvider method completeXImportDeclaration_MemberName.

@Override
public void completeXImportDeclaration_MemberName(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (model instanceof XImportDeclaration) {
        XImportDeclaration importDeclaration = (XImportDeclaration) model;
        for (JvmFeature feature : staticallyImportedMemberProvider.findAllFeatures(importDeclaration)) {
            Image image = getImage(feature);
            LightweightTypeReferenceFactory typeConverter = getTypeConverter(context.getResource());
            StyledString displayString = getStyledDisplayString(feature, false, 0, feature.getQualifiedName(), feature.getSimpleName(), typeConverter);
            acceptor.accept(createCompletionProposal(feature.getSimpleName(), displayString, image, context));
        }
    }
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) LightweightTypeReferenceFactory(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReferenceFactory) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 2 with JvmFeature

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

the class AbstractTypeProviderTest method testBug470767.

@Test
public void testBug470767() {
    String typeName = Bug470767.class.getName();
    JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    diagnose(type);
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
    Iterable<JvmFeature> methods = type.findAllFeaturesByName("paramIsAnnotated");
    JvmOperation method = (JvmOperation) Iterables.getOnlyElement(methods);
    JvmTypeReference paramType = method.getParameters().get(0).getParameterType();
    assertEquals("int", paramType.getSimpleName());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Resource(org.eclipse.emf.ecore.resource.Resource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) Test(org.junit.Test)

Example 3 with JvmFeature

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

the class XbaseReferenceUpdater method createReferenceUpdate.

@Override
protected void createReferenceUpdate(EObject referringElement, URI referringResourceURI, EReference reference, int indexInList, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
    if (referringElement instanceof XImportDeclaration) {
        XImportDeclaration importDeclaration = (XImportDeclaration) referringElement;
        JvmDeclaredType importedType = importDeclaration.getImportedType();
        boolean isStatic = importDeclaration.isStatic();
        boolean isExtension = importDeclaration.isExtension();
        String memberName = importDeclaration.getMemberName();
        if (newTargetElement instanceof JvmDeclaredType) {
            JvmDeclaredType type = (JvmDeclaredType) newTargetElement;
            ImportAwareUpdateAcceptor importAwareUpdateAcceptor = (ImportAwareUpdateAcceptor) updateAcceptor;
            importAwareUpdateAcceptor.removeImport(type, isStatic, isExtension, memberName);
            importAwareUpdateAcceptor.acceptImport(type, isStatic, isExtension, memberName);
            return;
        }
        if (newTargetElement instanceof JvmFeature) {
            JvmFeature feature = (JvmFeature) newTargetElement;
            String featureName = feature.getSimpleName();
            if (featureName.equals(memberName)) {
                // type rename is handled separately
                return;
            }
            ImportAwareUpdateAcceptor importAwareUpdateAcceptor = (ImportAwareUpdateAcceptor) updateAcceptor;
            if (!importAwareUpdateAcceptor.isUsed(importedType, isStatic, isExtension, memberName)) {
                importAwareUpdateAcceptor.removeImport(importedType, isStatic, isExtension, memberName);
            }
            if (importAwareUpdateAcceptor.isConflicted(importedType, isStatic, isExtension, featureName)) {
                JvmDeclaredType parentType = importedType;
                while (parentType != null && !importAwareUpdateAcceptor.getImportSection().hasImportedType(parentType) && !importAwareUpdateAcceptor.acceptImport(parentType, false, false, null)) {
                    parentType = parentType.getDeclaringType();
                }
            } else {
                importAwareUpdateAcceptor.acceptImport(importedType, isStatic, isExtension, featureName);
            }
            return;
        }
    }
    if (referringElement instanceof XAbstractFeatureCall) {
        if (newTargetElement instanceof JvmDeclaredType) {
            XAbstractFeatureCall featureCall = (XAbstractFeatureCall) referringElement;
            JvmIdentifiableElement feature = featureCall.getFeature();
            if (isStaticExtensionFeatureCall(referringElement, reference, feature)) {
                return;
            }
            if (isStaticFeatureCall(referringElement, reference, feature)) {
                return;
            }
        }
    }
    if (!(referringElement instanceof XFeatureCall && newTargetElement instanceof JvmConstructor)) {
        // skip constructor calls like this() or super()
        super.createReferenceUpdate(referringElement, referringResourceURI, reference, indexInList, newTargetElement, updateAcceptor);
    }
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 4 with JvmFeature

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

the class AbstractMultiModeOutlineTreeProvider method createQualifier.

private String createQualifier(JvmMember jvmMember) {
    String qualifier = null;
    if (jvmMember instanceof JvmFeature) {
        JvmDeclaredType declaringType = jvmMember.getDeclaringType();
        qualifier = getPackageFreeNameForType(declaringType);
    } else if (jvmMember instanceof JvmDeclaredType) {
        if (jvmMember.eContainer() instanceof JvmDeclaredType) {
            qualifier = getPackageFreeNameForType((JvmDeclaredType) jvmMember.eContainer());
        } else {
            JvmDeclaredType jvmDeclaredType = (JvmDeclaredType) jvmMember;
            if (StringUtils.isEmpty(jvmDeclaredType.getPackageName())) {
                qualifier = "(default package)";
            } else {
                qualifier = jvmDeclaredType.getPackageName();
            }
        }
    }
    return qualifier;
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) StyledString(org.eclipse.jface.viewers.StyledString)

Example 5 with JvmFeature

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

the class AbstractMultiModeOutlineTreeProvider method createNodeForFeature.

protected XtendFeatureNode createNodeForFeature(IOutlineNode parentNode, final JvmDeclaredType inferredType, EObject featureElement, int inheritanceDepth) {
    boolean synthetic = false;
    if (featureElement instanceof JvmFeature) {
        synthetic = typeExtensions.isSynthetic((JvmIdentifiableElement) featureElement);
    }
    Object text = computeDecoratedText(featureElement, inheritanceDepth);
    ImageDescriptor image = getImageDescriptor(featureElement);
    if (isShowInherited()) {
        return getOutlineNodeFactory().createXtendFeatureNode(parentNode, featureElement, image, text, true, synthetic, inheritanceDepth);
    }
    return getOutlineNodeFactory().createXtendFeatureNode(parentNode, featureElement, image, text, true, synthetic, inheritanceDepth);
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) EObject(org.eclipse.emf.ecore.EObject) JavaElementImageDescriptor(org.eclipse.jdt.ui.JavaElementImageDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Aggregations

JvmFeature (org.eclipse.xtext.common.types.JvmFeature)12 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 EObject (org.eclipse.emf.ecore.EObject)4 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)3 XImportDeclaration (org.eclipse.xtext.xtype.XImportDeclaration)3 StyledString (org.eclipse.jface.viewers.StyledString)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 JvmMember (org.eclipse.xtext.common.types.JvmMember)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 LinkedList (java.util.LinkedList)1 EList (org.eclipse.emf.common.util.EList)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 JavaElementImageDescriptor (org.eclipse.jdt.ui.JavaElementImageDescriptor)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 Region (org.eclipse.jface.text.Region)1 Image (org.eclipse.swt.graphics.Image)1 CreateExtensionInfo (org.eclipse.xtend.core.xtend.CreateExtensionInfo)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1