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

The following examples show how to use org.eclipse.xtext.xtype.XImportDeclaration#getImportedTypeName() . 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
private boolean hasStaticImport(String typeName, String memberName, boolean extension) {
	for (String string : implicitlyImportedPackages) {
		if (typeName.startsWith(string)) {
			return typeName.substring(string.length()).lastIndexOf('.') == 0;
		}
	}
	Map<JvmDeclaredType, Set<String>> imports = staticImports;
	if (extension) {
		imports = staticExtensionImports;
	}
	for (JvmDeclaredType type : imports.keySet()) {
		if (typeName.equals(type.getIdentifier())) {
			Set<String> members = imports.get(type);
			return members != null && ((members.contains(memberName) || members.contains(null)));
		}
	}
	for (XImportDeclaration importDeclr : addedImportDeclarations) {
		String identifier = importDeclr.getImportedTypeName();
		if (importDeclr.isStatic() && typeName.equals(identifier)) {
			if (Objects.equal(importDeclr.getMemberName(), memberName) || importDeclr.isWildcard() || "*".equals(importDeclr.getMemberName())) {
				return true;
			}
		}
	}
	return false;
}
 
Example 2
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 3
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 4
Source File: ConstantExpressionsInterpreter.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * looks up the static final fields which are accessible in unqualified form for the given expression.
 * That essentially includes static imports and the fields declared in the containing types
 */
protected Map<String, JvmIdentifiableElement> findVisibleFeatures(final XExpression expression) {
  HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
  {
    Resource _eResource = expression.eResource();
    final Resource res = _eResource;
    boolean _matched = false;
    if (res instanceof StorageAwareResource) {
      boolean _isLoadedFromStorage = ((StorageAwareResource)res).isLoadedFromStorage();
      if (_isLoadedFromStorage) {
        _matched=true;
        return CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
      }
    }
    JvmDeclaredType _switchResult_1 = null;
    JvmIdentifiableElement _nearestLogicalContainer = this.containerProvider.getNearestLogicalContainer(expression);
    final JvmIdentifiableElement cont = _nearestLogicalContainer;
    boolean _matched_1 = false;
    if (cont instanceof JvmGenericType) {
      _matched_1=true;
      _switchResult_1 = ((JvmGenericType)cont);
    }
    if (!_matched_1) {
      if (cont instanceof JvmMember) {
        _matched_1=true;
        _switchResult_1 = ((JvmMember)cont).getDeclaringType();
      }
    }
    final JvmDeclaredType container = _switchResult_1;
    Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("visibleFeaturesForAnnotationValues", container);
    final Provider<HashMap<String, JvmIdentifiableElement>> _function = () -> {
      final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
      Resource _eResource_1 = expression.eResource();
      final XImportSection section = this.importSectionLocator.getImportSection(((XtextResource) _eResource_1));
      if ((section != null)) {
        EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
        for (final XImportDeclaration imp : _importDeclarations) {
          boolean _isStatic = imp.isStatic();
          if (_isStatic) {
            final String importedTypeName = imp.getImportedTypeName();
            if ((importedTypeName != null)) {
              final JvmType type = this.findTypeByName(imp, importedTypeName);
              boolean _matched_2 = false;
              if (type instanceof JvmGenericType) {
                _matched_2=true;
                this.collectAllVisibleFields(((JvmDeclaredType)type), result);
              }
              if (!_matched_2) {
                if (type instanceof JvmEnumerationType) {
                  _matched_2=true;
                  EList<JvmEnumerationLiteral> _literals = ((JvmEnumerationType)type).getLiterals();
                  for (final JvmEnumerationLiteral feature : _literals) {
                    result.put(feature.getSimpleName(), feature);
                  }
                }
              }
            }
          }
        }
      }
      this.collectAllVisibleFields(container, result);
      return result;
    };
    _xblockexpression = this.cache.<HashMap<String, JvmIdentifiableElement>>get(_mappedTo, expression.eResource(), _function);
  }
  return _xblockexpression;
}