Search in sources :

Example 1 with XImportDeclaration

use of org.eclipse.xtext.xtype.XImportDeclaration 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 XImportDeclaration

use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-eclipse by eclipse.

the class XbaseHyperLinkHelper method createHyperlinksTo.

@Override
protected void createHyperlinksTo(XtextResource resource, INode node, EObject target, IHyperlinkAcceptor acceptor) {
    EObject semanticObj = NodeModelUtils.findActualSemanticObjectFor(node);
    if (semanticObj instanceof XImportDeclaration) {
        if (((XImportDeclaration) semanticObj).isStatic()) {
            final ITextRegion textRegion = this.locationInFileProvider.getSignificantTextRegion(semanticObj, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, 0);
            int _offset = textRegion.getOffset();
            int _length = textRegion.getLength();
            final Region region = new Region(_offset, _length);
            this.createHyperlinksTo(resource, region, target, acceptor);
        }
    } else if (semanticObj instanceof XAbstractFeatureCall) {
        if (target instanceof JvmType) {
            XAbstractFeatureCall casted = (XAbstractFeatureCall) semanticObj;
            while (casted.isPackageFragment()) {
                casted = (XAbstractFeatureCall) casted.eContainer();
            }
            if (casted.isTypeLiteral()) {
                ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(casted);
                Region jfaceRegion = new Region(textRegion.getOffset(), textRegion.getLength());
                createHyperlinksTo(resource, jfaceRegion, target, acceptor);
                return;
            }
        }
    }
    super.createHyperlinksTo(resource, node, target, acceptor);
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) JvmType(org.eclipse.xtext.common.types.JvmType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 3 with XImportDeclaration

use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-eclipse by eclipse.

the class JavaTypeQuickfixes method parseImportSection.

protected void parseImportSection(XImportSection importSection, IAcceptor<String> visiblePackages, IAcceptor<String> importedTypes) {
    for (XImportDeclaration importDeclaration : importSection.getImportDeclarations()) {
        if (!importDeclaration.isStatic()) {
            if (importDeclaration.getImportedNamespace() != null) {
                String importedAsString = importDeclaration.getImportedNamespace();
                if (importDeclaration.isWildcard()) {
                    importedAsString = importedAsString.substring(0, importedAsString.length() - 2);
                    visiblePackages.accept(importedAsString);
                } else {
                    importedTypes.accept(importedAsString);
                }
            } else {
                importedTypes.accept(importDeclaration.getImportedTypeName());
            }
        }
    }
}
Also used : XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 4 with XImportDeclaration

use of org.eclipse.xtext.xtype.XImportDeclaration 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 5 with XImportDeclaration

use of org.eclipse.xtext.xtype.XImportDeclaration in project xtext-xtend by eclipse.

the class ParserTest method testImport_02.

@Test
public void testImport_02() throws Exception {
    XImportDeclaration importDeclaration = importDeclaration("import java . util . /*comment*/ List");
    assertNotNull(importDeclaration);
    assertEquals("java.util.List", importDeclaration.getImportedTypeName());
    assertFalse(importDeclaration.isWildcard());
    assertFalse(importDeclaration.isStatic());
    assertFalse(importDeclaration.isExtension());
}
Also used : XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration) Test(org.junit.Test)

Aggregations

XImportDeclaration (org.eclipse.xtext.xtype.XImportDeclaration)15 Test (org.junit.Test)6 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 EObject (org.eclipse.emf.ecore.EObject)3 JvmFeature (org.eclipse.xtext.common.types.JvmFeature)3 JvmType (org.eclipse.xtext.common.types.JvmType)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 Region (org.eclipse.jface.text.Region)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)2 XImportSection (org.eclipse.xtext.xtype.XImportSection)2 Provider (com.google.inject.Provider)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 EClass (org.eclipse.emf.ecore.EClass)1