Search in sources :

Example 16 with XImportDeclaration

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

the class RewritableImportSection method addImport.

public boolean addImport(JvmDeclaredType type) {
    if (plainImports.containsKey(type.getSimpleName()) || !needsImport(type))
        return false;
    Maps2.putIntoListMap(type.getSimpleName(), type, plainImports);
    XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration();
    importDeclaration.setImportedType(type);
    addedImportDeclarations.add(importDeclaration);
    return true;
}
Also used : XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 17 with XImportDeclaration

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

the class XbaseLocationInFileProvider method getLocationOfCrossReference.

@Override
protected ITextRegion getLocationOfCrossReference(EObject owner, EReference reference, int indexInList, boolean isSignificant) {
    if (owner instanceof XMemberFeatureCall && reference == XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE && ((XMemberFeatureCall) owner).isTypeLiteral()) {
        List<INode> featureNodes = NodeModelUtils.findNodesForFeature(owner, reference);
        ITextRegion result = ITextRegion.EMPTY_REGION;
        if (!featureNodes.isEmpty()) {
            INode featureNode = featureNodes.get(0);
            result = result.merge(toZeroBasedRegion(featureNode.getTextRegionWithLineInformation()));
            List<INode> targetNodes = NodeModelUtils.findNodesForFeature(owner, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET);
            if (!targetNodes.isEmpty()) {
                INode targetNode = targetNodes.get(0);
                result = result.merge(toZeroBasedRegion(targetNode.getTextRegionWithLineInformation()));
            }
            return result;
        }
    }
    if (isSignificant && owner instanceof XImportDeclaration && reference == XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE) {
        List<INode> nodes = NodeModelUtils.findNodesForFeature(owner, reference);
        if (!nodes.isEmpty()) {
            INode qualifierNode = nodes.get(0);
            ITextRegion result = ITextRegion.EMPTY_REGION;
            INode pending = null;
            String delimiter = qualifiedNameInStaticImportValueConverter.getStringNamespaceDelimiter();
            for (INode node : qualifierNode.getLeafNodes()) {
                if (!isHidden(node)) {
                    int length = node.getLength();
                    if (length != 0) {
                        if (pending != null) {
                            result.merge(toZeroBasedRegion(pending.getTextRegionWithLineInformation()));
                            pending = null;
                        }
                        if (delimiter.equals(node.getText())) {
                            pending = node;
                        } else {
                            result = result.merge(toZeroBasedRegion(node.getTextRegionWithLineInformation()));
                        }
                    }
                }
            }
            return result;
        }
    }
    return super.getLocationOfCrossReference(owner, reference, indexInList, isSignificant);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) ITextRegion(org.eclipse.xtext.util.ITextRegion) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 18 with XImportDeclaration

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

the class XImportSectionNamespaceScopeProvider method getImportedNamespaceResolvers.

protected List<ImportNormalizer> getImportedNamespaceResolvers(XImportSection importSection, boolean ignoreCase) {
    List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
    List<ImportNormalizer> result = Lists.newArrayListWithExpectedSize(importDeclarations.size());
    for (XImportDeclaration imp : importDeclarations) {
        if (!imp.isStatic()) {
            String value = imp.getImportedNamespace();
            if (value == null)
                value = imp.getImportedTypeName();
            ImportNormalizer resolver = createImportedNamespaceResolver(value, ignoreCase);
            if (resolver != null)
                result.add(resolver);
        }
    }
    return result;
}
Also used : ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 19 with XImportDeclaration

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

the class XbaseBatchScopeProvider method newSession.

@Override
public IFeatureScopeSession newSession(Resource context) {
    List<JvmType> literalClasses = implicitlyImportedFeatures.getStaticImportClasses(context);
    List<JvmType> extensionClasses = implicitlyImportedFeatures.getExtensionClasses(context);
    IFeatureScopeSession result = rootSession.addTypesToStaticScope(literalClasses, extensionClasses);
    if (context.getContents().isEmpty() || !(context instanceof XtextResource))
        return result;
    final XImportSection importSection = importsConfig.getImportSection((XtextResource) context);
    if (importSection != null) {
        result = result.addImports(new ITypeImporter.Client() {

            @Override
            public void doAddImports(ITypeImporter importer) {
                List<XImportDeclaration> imports = importSection.getImportDeclarations();
                for (XImportDeclaration _import : imports) {
                    if (_import.isStatic()) {
                        if (_import.isWildcard()) {
                            if (_import.isExtension()) {
                                importer.importStaticExtension(_import.getImportedType(), false);
                            } else {
                                importer.importStatic(_import.getImportedType());
                            }
                        } else {
                            if (_import.isExtension()) {
                                importer.importStaticExtension(_import.getImportedType(), _import.getMemberName(), false);
                            } else {
                                importer.importStatic(_import.getImportedType(), _import.getMemberName());
                            }
                        }
                    }
                }
            }
        });
    }
    return result;
}
Also used : XImportSection(org.eclipse.xtext.xtype.XImportSection) XtextResource(org.eclipse.xtext.resource.XtextResource) JvmType(org.eclipse.xtext.common.types.JvmType) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 20 with XImportDeclaration

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

the class ModelExtensionsTest method testXtendImport.

@Test
public void testXtendImport() throws Exception {
    XImportDeclaration xtendImport = xtypeFactory.createXImportDeclaration();
    assertFalse(xtendImport.isWildcard());
    assertNull(xtendImport.getImportedTypeName());
    xtendImport.setImportedNamespace("");
    assertFalse(xtendImport.isWildcard());
    assertEquals("", xtendImport.getImportedTypeName());
    xtendImport.setImportedNamespace("java.lang.Collections.*");
    assertTrue(xtendImport.isWildcard());
    assertEquals("java.lang.Collections", xtendImport.getImportedTypeName());
}
Also used : XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration) Test(org.junit.Test)

Aggregations

XImportDeclaration (org.eclipse.xtext.xtype.XImportDeclaration)34 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 XImportSection (org.eclipse.xtext.xtype.XImportSection)8 JvmType (org.eclipse.xtext.common.types.JvmType)6 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)6 Test (org.junit.Test)6 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)5 EObject (org.eclipse.emf.ecore.EObject)4 EPackage (org.eclipse.emf.ecore.EPackage)4 Action (org.eclipse.xtext.Action)4 Parameter (org.eclipse.xtext.Parameter)4 ParserRule (org.eclipse.xtext.ParserRule)4 JvmLowerBound (org.eclipse.xtext.common.types.JvmLowerBound)4 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)4 ITextRegion (org.eclipse.xtext.util.ITextRegion)4 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)4 XClosure (org.eclipse.xtext.xbase.XClosure)4 XFunctionTypeRef (org.eclipse.xtext.xtype.XFunctionTypeRef)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)3 List (java.util.List)2