Java Code Examples for org.eclipse.xtext.xtype.XImportDeclaration#getImportedNamespace()

The following examples show how to use org.eclipse.xtext.xtype.XImportDeclaration#getImportedNamespace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RewritableImportSection.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void appendImport(StringBuilder builder, XImportDeclaration newImportDeclaration) {
	builder.append("import ");
	if (newImportDeclaration.isStatic()) {
		builder.append("static ");
		if (newImportDeclaration.isExtension()) {
			builder.append("extension ");
		}
	}
	String qualifiedTypeName = newImportDeclaration.getImportedNamespace();
	if (newImportDeclaration.getImportedType() != null) {
		qualifiedTypeName = serializeType(newImportDeclaration.getImportedType());
	}
	String escapedTypeName = nameValueConverter.toString(qualifiedTypeName);
	builder.append(escapedTypeName);
	if (newImportDeclaration.isStatic()) {
		builder.append(".");
		if (newImportDeclaration.isWildcard()) {
			builder.append("*");
		} else {
			builder.append(newImportDeclaration.getMemberName());
		}
	}
	builder.append(lineSeparator);
}
 
Example 2
Source File: JavaTypeQuickfixes.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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());
			}
		}
	}
}
 
Example 3
Source File: XImportSectionNamespaceScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: CheckLabelProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A label for imports. Is missing in xbase super class, but present in XtendLabelProvider.
 * 
 * @param context
 *          the import
 * @return its label.
 */
@Override
public String text(final XImportDeclaration context) {
  String namespace = context.getImportedNamespace();
  if (namespace != null) {
    return namespace;
  }
  return context.getImportedTypeName();
}
 
Example 5
Source File: XtendImportedNamespaceScopeProvider.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
private AbstractScope getImportScope(XImportSection importSection, AbstractScope parent, RecordingTypeScope typeScope) {
	if (importSection == null)
		return parent;
	List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
	if (importDeclarations.isEmpty()) {
		return parent;
	}
	List<ImportNormalizer> wildcardImports = null;
	List<JvmType> concreteImports = null;
	List<QualifiedName> importedNames = null;
	boolean hasLegacyImport = false;
	for(XImportDeclaration importDeclaration: importDeclarations) {
		if (!importDeclaration.isStatic()) {
			if (importDeclaration.isWildcard()) {
				if (wildcardImports == null) {
					wildcardImports = Lists.newArrayListWithCapacity(4);
				}
				String importedNamespace = importDeclaration.getImportedNamespace();
				importedNamespace = importedNamespace.substring(0, importedNamespace.length() - 2);
				QualifiedName qualifiedImportedNamespace = qualifiedNameConverter.toQualifiedName(importedNamespace);
				wildcardImports.add(AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(qualifiedImportedNamespace, true, false));
			} else {
				JvmDeclaredType importedType = importDeclaration.getImportedType();
				if (importedType != null && !importedType.eIsProxy()) {
					if (concreteImports == null || importedNames == null /* to make JDT happy */) {
						concreteImports = Lists.newArrayListWithCapacity(10);
						importedNames = Lists.newArrayListWithCapacity(10);
					}
					concreteImports.add(importedType);
					if (importedType.eContainer() instanceof JvmDeclaredType) {
						String importSyntax = getImportsConfiguration().getLegacyImportSyntax(importDeclaration);
						if (importSyntax != null) {
							hasLegacyImport = true;
							importedNames.add(getQualifiedNameConverter().toQualifiedName(importSyntax));
						} else
							importedNames.add(null);
					} else {
						importedNames.add(null);
					}
				}
			}
		}
	}
	return getImportScope(wildcardImports, concreteImports, hasLegacyImport ? importedNames : null, parent, typeScope);
}