Search in sources :

Example 1 with ModuleElement

use of javax.lang.model.element.ModuleElement in project bazel-jdt-java-toolchain by salesforce.

the class ElementsImpl9 method getAllModuleElements.

@Override
public Set<? extends ModuleElement> getAllModuleElements() {
    LookupEnvironment lookup = _env.getLookupEnvironment();
    HashtableOfModule knownModules = lookup.knownModules;
    ModuleBinding[] modules = knownModules.valueTable;
    if (modules == null || modules.length == 0) {
        return Collections.emptySet();
    }
    Set<ModuleElement> mods = new HashSet<>(modules.length);
    for (ModuleBinding moduleBinding : modules) {
        if (moduleBinding == null)
            continue;
        ModuleElement element = (ModuleElement) _env.getFactory().newElement(moduleBinding);
        mods.add(element);
    }
    mods.add((ModuleElement) _env.getFactory().newElement(lookup.UnNamedModule));
    return mods;
}
Also used : LookupEnvironment(org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment) HashtableOfModule(org.eclipse.jdt.internal.compiler.util.HashtableOfModule) ModuleElement(javax.lang.model.element.ModuleElement) ModuleBinding(org.eclipse.jdt.internal.compiler.lookup.ModuleBinding) HashSet(java.util.HashSet)

Example 2 with ModuleElement

use of javax.lang.model.element.ModuleElement in project graal by oracle.

the class ModuleCache method getTypeElement.

static TypeElement getTypeElement(final ProcessingEnvironment processingEnv, final CharSequence typeName) {
    if (processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_9) < 0) {
        return processingEnv.getElementUtils().getTypeElement(typeName);
    }
    final Map<String, ModuleElement> moduleCache = moduleCacheCleaner.computeIfAbsent(processingEnv, new Function<ProcessingEnvironment, Map<String, ModuleElement>>() {

        @Override
        public Map<String, ModuleElement> apply(ProcessingEnvironment t) {
            return new HashMap<>();
        }
    });
    final String typeNameString = typeName.toString();
    ModuleElement moduleElement = moduleCache.get(typeNameString);
    if (moduleElement == null) {
        final TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(typeName);
        if (typeElement != null) {
            moduleElement = processingEnv.getElementUtils().getModuleOf(typeElement);
            moduleCache.put(typeNameString, moduleElement);
        }
        return typeElement;
    } else {
        return processingEnv.getElementUtils().getTypeElement(moduleElement, typeName);
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ModuleElement(javax.lang.model.element.ModuleElement) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 3 with ModuleElement

use of javax.lang.model.element.ModuleElement in project bazel-jdt-java-toolchain by salesforce.

the class ElementsImpl9 method getTypeElement.

@Override
public TypeElement getTypeElement(CharSequence name) {
    final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
    Set<? extends ModuleElement> allModuleElements = getAllModuleElements();
    for (ModuleElement moduleElement : allModuleElements) {
        TypeElement t = getTypeElement(compoundName, ((ModuleElementImpl) moduleElement).binding);
        if (t != null) {
            return t;
        }
    }
    return null;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ModuleElement(javax.lang.model.element.ModuleElement)

Aggregations

ModuleElement (javax.lang.model.element.ModuleElement)3 TypeElement (javax.lang.model.element.TypeElement)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 ProcessingEnvironment (javax.annotation.processing.ProcessingEnvironment)1 LookupEnvironment (org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment)1 ModuleBinding (org.eclipse.jdt.internal.compiler.lookup.ModuleBinding)1 HashtableOfModule (org.eclipse.jdt.internal.compiler.util.HashtableOfModule)1