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

The following examples show how to use org.eclipse.xtext.xtype.XImportDeclaration#isStatic() . 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
public RewritableImportSection(XtextResource resource, IImportsConfiguration importsConfiguration, XImportSection originalImportSection,
		String lineSeparator, ImportSectionRegionUtil regionUtil, IValueConverter<String> nameConverter) {
	this.importsConfiguration = importsConfiguration;
	this.resource = resource;
	this.lineSeparator = lineSeparator;
	this.regionUtil = regionUtil;
	this.nameValueConverter = nameConverter;
	this.implicitlyImportedPackages = importsConfiguration.getImplicitlyImportedPackages(resource);
	this.importRegion = regionUtil.computeRegion(resource);
	if (originalImportSection != null) {
		for (XImportDeclaration originalImportDeclaration : originalImportSection.getImportDeclarations()) {
			this.originalImportDeclarations.add(originalImportDeclaration);
			JvmDeclaredType importedType = originalImportDeclaration.getImportedType();
			if (originalImportDeclaration.isStatic()) {
				String memberName = originalImportDeclaration.getMemberName();
				if (originalImportDeclaration.isExtension()) {
					Maps2.putIntoSetMap(importedType, memberName, staticExtensionImports);
				} else {
					Maps2.putIntoSetMap(importedType, memberName, staticImports);
				}
			} else if (importedType != null) {
				Maps2.putIntoListMap(importedType.getSimpleName(), importedType, plainImports);
			}
		}
	}
}
 
Example 2
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 3
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 4
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 5
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 6
Source File: RewritableImportSection.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<XImportDeclaration> findOriginalImports(JvmDeclaredType type, String memberName, Collection<XImportDeclaration> list, boolean isStatic,
		boolean isExtension) {
	List<XImportDeclaration> result = newArrayList();
	for (XImportDeclaration importDeclaration : list) {
		if (!(isStatic ^ importDeclaration.isStatic()) && !(isExtension ^ importDeclaration.isExtension()) && importDeclaration.getImportedType() == type
				&& (memberName == null || memberName.equals(importDeclaration.getMemberName()))) {
			result.add(importDeclaration);
		}
	}
	return result;
}
 
Example 7
Source File: StaticallyImportedMemberProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public Iterable<JvmFeature> findAllFeatures(XImportDeclaration it) {
	JvmDeclaredType importedType = it.getImportedType();
	if (!it.isStatic() || importedType == null) {
		return Collections.emptyList();
	}
	IVisibilityHelper visibilityHelper = getVisibilityHelper(it.eResource());
	IResolvedFeatures resolvedFeatures = resolvedFeaturesProvider.getResolvedFeatures(importedType);
	return Iterables.filter(resolvedFeatures.getAllFeatures(), (JvmFeature feature) -> {
		return feature.isStatic() && visibilityHelper.isVisible(feature)
				&& (it.getMemberName() == null || feature.getSimpleName().startsWith(it.getMemberName()));
	});
}
 
Example 8
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);
}
 
Example 9
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;
}