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;
}
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);
}
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;
}
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;
}
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());
}
Aggregations