Search in sources :

Example 1 with PRIVATE

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

the class ExportsGenerator method initializeEagerCaches.

private static Map<CacheKey, List<CacheExpression>> initializeEagerCaches(Map<String, ExportMessageData> messages) {
    final ExportMessageData acceptsMessage = messages.get(ACCEPTS);
    final Map<CacheKey, List<CacheExpression>> eagerCaches = new LinkedHashMap<>();
    if (acceptsMessage != null && acceptsMessage.getSpecializedNode() != null) {
        int specializationCount = 0;
        for (SpecializationData s : acceptsMessage.getSpecializedNode().getSpecializations()) {
            if (!s.isReachable() || !s.isSpecialized()) {
                continue;
            }
            specializationCount++;
            for (CacheExpression cache : s.getCaches()) {
                if (isEagerInitialize(acceptsMessage, cache)) {
                    eagerCaches.computeIfAbsent(new CacheKey(cache), (b) -> new ArrayList<>()).add(cache);
                }
            }
        }
        if (specializationCount > 1) {
            Iterator<List<CacheExpression>> iterator = eagerCaches.values().iterator();
            while (iterator.hasNext()) {
                List<CacheExpression> caches = iterator.next();
                if (caches.size() != specializationCount) {
                    // if a cache is not contained on all specializations
                    // do not initialize it eagerly. Probably a pretty rare case
                    // for accepts exports.
                    iterator.remove();
                }
            }
        }
    }
    Set<String> eagerSharedGroups = new HashSet<>();
    for (List<CacheExpression> caches : eagerCaches.values()) {
        for (CacheExpression cache : caches) {
            if (cache.isMergedLibrary()) {
                // merged libraries are handled elsewhere
                continue;
            }
            cache.setEagerInitialize(true);
            if (cache.getSharedGroup() != null) {
                eagerSharedGroups.add(cache.getSharedGroup());
            }
        }
    }
    if (eagerSharedGroups.size() > 0) {
        for (ExportMessageData message : messages.values()) {
            if (message.getSpecializedNode() != null) {
                for (SpecializationData specialization : message.getSpecializedNode().getSpecializations()) {
                    if (!specialization.isReachable()) {
                        continue;
                    }
                    for (CacheExpression cache : specialization.getCaches()) {
                        if (cache.getSharedGroup() != null && eagerSharedGroups.contains(cache.getSharedGroup())) {
                            cache.setEagerInitialize(true);
                        }
                    }
                }
            }
        }
    }
    return eagerCaches;
}
Also used : Arrays(java.util.Arrays) Modifier(javax.lang.model.element.Modifier) TypeElement(javax.lang.model.element.TypeElement) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) DSLExpressionReducer(com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionReducer) CodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror) FINAL(javax.lang.model.element.Modifier.FINAL) Map(java.util.Map) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) NodeData(com.oracle.truffle.dsl.processor.model.NodeData) StaticConstants(com.oracle.truffle.dsl.processor.generator.StaticConstants) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) Collection(java.util.Collection) Set(java.util.Set) GeneratorMode(com.oracle.truffle.dsl.processor.generator.FlatNodeGenFactory.GeneratorMode) Element(javax.lang.model.element.Element) Objects(java.util.Objects) List(java.util.List) Entry(java.util.Map.Entry) DSLExpression(com.oracle.truffle.dsl.processor.expression.DSLExpression) Binary(com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) CodeTypeElementFactory(com.oracle.truffle.dsl.processor.generator.CodeTypeElementFactory) VariableElement(javax.lang.model.element.VariableElement) HashMap(java.util.HashMap) GeneratorUtils.createClass(com.oracle.truffle.dsl.processor.generator.GeneratorUtils.createClass) ArrayList(java.util.ArrayList) DSLExpressionGenerator(com.oracle.truffle.dsl.processor.generator.DSLExpressionGenerator) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) FlatNodeGenFactory(com.oracle.truffle.dsl.processor.generator.FlatNodeGenFactory) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression) DeclaredType(javax.lang.model.type.DeclaredType) GeneratorUtils(com.oracle.truffle.dsl.processor.generator.GeneratorUtils) ElementFilter(javax.lang.model.util.ElementFilter) LinkedHashSet(java.util.LinkedHashSet) Variable(com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable) ElementUtils(com.oracle.truffle.dsl.processor.java.ElementUtils) CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) PRIVATE(javax.lang.model.element.Modifier.PRIVATE) Iterator(java.util.Iterator) ElementKind(javax.lang.model.element.ElementKind) Call(com.oracle.truffle.dsl.processor.expression.DSLExpression.Call) AnnotationProcessor(com.oracle.truffle.dsl.processor.AnnotationProcessor) PUBLIC(javax.lang.model.element.Modifier.PUBLIC) ExecutableElement(javax.lang.model.element.ExecutableElement) ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) CodeNames(com.oracle.truffle.dsl.processor.java.model.CodeNames) STATIC(javax.lang.model.element.Modifier.STATIC) PROTECTED(javax.lang.model.element.Modifier.PROTECTED) TypeMirror(javax.lang.model.type.TypeMirror) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) ElementUtils.modifiers(com.oracle.truffle.dsl.processor.java.ElementUtils.modifiers) Negate(com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate) Collections(java.util.Collections) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) ArrayList(java.util.ArrayList) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with PRIVATE

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

the class FlatNodeGenFactory method generateAOT.

private void generateAOT(CodeTypeElement clazz) {
    TypeMirror aotProviderType = new GeneratedTypeMirror(ElementUtils.getPackageName(types.GenerateAOT_Provider), "GenerateAOT.Provider");
    clazz.getImplements().add(aotProviderType);
    CodeExecutableElement prepare = clazz.add(CodeExecutableElement.cloneNoAnnotations(ElementUtils.findMethod(types.GenerateAOT_Provider, "prepareForAOT")));
    prepare.renameArguments("language", "root");
    GeneratorUtils.addOverride(prepare);
    prepare.getModifiers().remove(ABSTRACT);
    CodeTreeBuilder builder = prepare.createBuilder();
    List<SpecializationData> filteredSpecializations = new ArrayList<>();
    for (NodeData currentNode : sharingNodes) {
        for (SpecializationData s : calculateReachableSpecializations(currentNode)) {
            if (s.getMethod() == null || !s.isPrepareForAOT()) {
                continue;
            }
            filteredSpecializations.add(s);
        }
    }
    FrameState frameState = FrameState.load(this, NodeExecutionMode.SLOW_PATH, prepare);
    frameState.setBoolean(AOT_STATE, true);
    Map<StateBitSet, List<SpecializationData>> stateGroup = new LinkedHashMap<>();
    Set<TypeGuard> implicitCasts = new LinkedHashSet<>();
    for (SpecializationData specialization : filteredSpecializations) {
        for (StateBitSet set : allMultiState.getSets()) {
            if (set.contains(AOT_PREPARED)) {
                // make sure we have an entry for a state bitset
                // without any specialization but only with the AOT bit set
                stateGroup.computeIfAbsent(set, (s) -> new ArrayList<>());
            }
            if (set.contains(specialization)) {
                stateGroup.computeIfAbsent(set, (s) -> new ArrayList<>()).add(specialization);
                break;
            }
        }
        int index = 0;
        for (Parameter p : specialization.getSignatureParameters()) {
            TypeMirror targetType = p.getType();
            Collection<TypeMirror> sourceTypes = node.getTypeSystem().lookupSourceTypes(targetType);
            if (sourceTypes.size() > 1) {
                implicitCasts.add(new TypeGuard(targetType, index));
            }
            index++;
        }
    }
    builder.startAssert();
    builder.string("!isAdoptable() || ");
    builder.string("(").cast(context.getType(ReentrantLock.class), CodeTreeBuilder.singleString("getLock()"));
    builder.string(").isHeldByCurrentThread()");
    builder.string(" : ").doubleQuote("During prepare AST lock must be held.");
    builder.end();
    builder.tree(multiState.createLoad(frameState, AOT_PREPARED));
    builder.tree(multiState.createLoad(frameState, filteredSpecializations.toArray()));
    for (StateBitSet set : multiState.getSets()) {
        if (set.contains(AOT_PREPARED)) {
            builder.startIf();
            builder.tree(set.createContains(frameState, AOT_PREPARED));
            builder.end().startBlock();
            builder.returnDefault();
            builder.end();
            break;
        }
    }
    List<Object> bulkStateSet = new ArrayList<>();
    Set<String> languagesChecked = new HashSet<>();
    for (SpecializationData specialization : filteredSpecializations) {
        // we need to copy otherwise local variables of caches may conflict.
        FrameState innerFrameState = frameState.copy();
        SpecializationGroup specializationGroup = SpecializationGroup.create(Arrays.asList(specialization));
        for (CacheExpression cache : specialization.getCaches()) {
            if (!cache.isAlwaysInitialized()) {
                continue;
            }
            setCacheInitialized(innerFrameState, specialization, cache, true);
        }
        List<IfTriple> tripples = new ArrayList<>();
        for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
            tripples.addAll(createAssumptionSlowPathTriples(innerFrameState, specializationGroup, assumption));
        }
        /*
             * We don't need to materialize assumption conditions.
             */
        for (IfTriple triple : tripples) {
            triple.condition = null;
        }
        // compute guards that can be materialized
        List<GuardExpression> usedGuards = new ArrayList<>();
        for (GuardExpression guard : specialization.getGuards()) {
            if (guardNeedsStateBit(specialization, guard)) {
                bulkStateSet.add(guard);
            }
            if (specialization.isDynamicParameterBound(guard.getExpression(), true)) {
                if (!specialization.isOnlyLanguageReferencesBound(guard.getExpression())) {
                    /*
                         * Guards with only language references can be executed.
                         */
                    continue;
                }
            }
            usedGuards.add(guard);
        }
        for (CacheExpression cache : specialization.getCaches()) {
            if (!cache.isAlwaysInitialized()) {
                continue;
            }
            if (cache.isCachedLanguage()) {
                boolean needsLocal = false;
                for (GuardExpression guard : usedGuards) {
                    if (specialization.isExpressionBindsCache(guard.getExpression(), cache)) {
                        needsLocal = true;
                        break;
                    }
                }
                if (!needsLocal) {
                    for (CacheExpression otherCache : specialization.getCaches()) {
                        if (cache == otherCache) {
                            continue;
                        }
                        if (specialization.isExpressionBindsCache(otherCache.getDefaultExpression(), cache)) {
                            needsLocal = true;
                            break;
                        }
                    }
                }
                TypeMirror languageType = cache.getLanguageType();
                boolean needsCheck = false;
                if (!usedGuards.isEmpty()) {
                    needsCheck = languagesChecked.add(ElementUtils.getTypeId(languageType));
                }
                CodeTreeBuilder b = builder.create();
                if (needsCheck) {
                    b.startIf().string("language == null || language.getClass() != ").typeLiteral(languageType).end().startBlock();
                    b.startStatement().startStaticCall(types.CompilerDirectives, "transferToInterpreterAndInvalidate").end().end();
                    b.startThrow().startStaticCall(types.CompilerDirectives, "shouldNotReachHere");
                    b.startStaticCall(context.getType(String.class), "format");
                    b.doubleQuote(String.format("Specialization '%s' in node class '%s' is enabled for AOT generation. " + "The specialization declares a @%s for language class %s but was prepared for AOT with language class '%%s'. " + "Match the language used in the language reference or exclude the specialization from AOT generation with @%s.%s to resolve this problem.", getReadableSignature(specialization.getMethod()), getQualifiedName(specialization.getNode().getTemplateType()), getSimpleName(types.CachedLanguage), getQualifiedName(cache.getLanguageType()), getSimpleName(types.GenerateAOT), getSimpleName(types.GenerateAOT_Exclude)));
                    b.string("language != null ? language.getClass().getName() : \"null\"");
                    b.end();
                    // static call, throw,
                    b.end().end();
                    // if block
                    b.end();
                }
                if (needsLocal) {
                    b.startStatement();
                    b.type(languageType);
                    b.string(" ", createCacheLocalName(specialization, cache));
                    b.string(" = ").maybeCast(types.TruffleLanguage, cache.getLanguageType(), "language");
                    // statement
                    b.end();
                }
                tripples.add(new IfTriple(b.build(), null, null));
            }
        }
        for (GuardExpression guard : usedGuards) {
            Set<CacheExpression> caches = specialization.getBoundCaches(guard.getExpression(), true);
            tripples.addAll(initializeCaches(innerFrameState, NodeExecutionMode.SLOW_PATH, specializationGroup, caches, true, false));
            tripples.add(createMethodGuardCheck(innerFrameState, specialization, guard, NodeExecutionMode.SLOW_PATH));
        }
        BlockState state = IfTriple.materialize(builder, tripples, false);
        builder.tree(createSpecialize(builder, innerFrameState, specializationGroup, specialization, true));
        for (CacheExpression cache : specialization.getCaches()) {
            if (cache.isAlwaysInitialized()) {
                continue;
            }
            /*
                 * Libraries might not be AOT preparable. E.g. if a cached library was created from
                 * a final field of the current language. In such a case we should just not call
                 * prepareForAOT.
                 *
                 * Specializable nodes are always known to be preparable if they reach the code
                 * generator.
                 */
            boolean cachedLibrary = cache.isCachedLibrary();
            if (cachedLibrary) {
                builder.startIf().tree(createCacheReference(innerFrameState, specialization, cache)).instanceOf(aotProviderType).end().startBlock();
            }
            if (NodeCodeGenerator.isSpecializedNode(cache.getParameter().getType()) || cachedLibrary) {
                builder.startAssert().startStaticCall(types.NodeUtil, "assertRecursion");
                builder.tree(createCacheReference(innerFrameState, specialization, cache));
                /*
                     * We allow a single recursion level only for AOT preparation. It is important
                     * that we only assert recursion for @Cached fields as regular AST children can
                     * be recursive arbitrarily deep.
                     *
                     * We might need to increase this limit in the future if it triggers to eagerly.
                     */
                builder.string("1");
                builder.end().end();
                builder.startStatement();
                builder.string("(");
                builder.cast(aotProviderType);
                builder.tree(createCacheReference(innerFrameState, specialization, cache));
                builder.string(")");
                builder.string(".prepareForAOT(language, root)");
                builder.end();
            }
            if (cachedLibrary) {
                builder.end();
            }
        }
        if (usedGuards.isEmpty()) {
            bulkStateSet.add(specialization);
        } else {
            builder.tree(multiState.createSet(innerFrameState, new SpecializationData[] { specialization }, true, false));
        }
        builder.end(state.blockCount);
    }
    List<Object> allElements = new ArrayList<>();
    allElements.add(AOT_PREPARED);
    allElements.addAll(bulkStateSet);
    allElements.addAll(implicitCasts);
    builder.tree(multiState.createSet(frameState, allElements.toArray(), true, true));
    if (!needsAOTReset()) {
        return;
    }
    CodeExecutableElement reset = clazz.add(new CodeExecutableElement(modifiers(PRIVATE), context.getType(void.class), "resetAOT_"));
    frameState = FrameState.load(this, NodeExecutionMode.FAST_PATH, reset);
    reset.getModifiers().remove(ABSTRACT);
    builder = reset.createBuilder();
    for (StateBitSet set : multiState.all) {
        if (set.contains(AOT_PREPARED)) {
            builder.tree(set.createLoad(frameState));
            builder.startIf();
            builder.tree(set.createNotContains(frameState, AOT_PREPARED));
            builder.end().startBlock();
            builder.returnDefault();
            builder.end();
        }
        break;
    }
    for (SpecializationData specialization : filteredSpecializations) {
        List<CacheExpression> resetCaches = new ArrayList<>();
        for (CacheExpression cache : specialization.getCaches()) {
            if (cache.isAlwaysInitialized()) {
                continue;
            }
            if (types.Profile != null && ElementUtils.isAssignable(cache.getParameter().getType(), types.Profile)) {
                resetCaches.add(cache);
            }
        }
        if (resetCaches.size() > 0) {
            builder.tree(multiState.createLoadAll(frameState, specialization));
            builder.startIf().tree(multiState.createContainsAll(frameState, new Object[] { specialization })).end();
            builder.startBlock();
            for (CacheExpression cache : resetCaches) {
                builder.startStatement();
                builder.tree(createCacheReference(frameState, specialization, cache));
                builder.string(".reset()");
                builder.end();
            }
            builder.end();
        }
    }
    for (StateBitSet set : multiState.getSets()) {
        builder.tree(set.createSetZero(frameState, true));
    }
    if (requiresExclude()) {
        builder.tree(exclude.createSetZero(frameState, true));
    }
    /*
         * It is important that we reset the state first before we clear the caches for initialized
         * libraries. Otherwise we might observe an enabled specialization without initialized cache
         * on the fast-path.
         */
    for (SpecializationData specialization : filteredSpecializations) {
        boolean resetSpecializationClass = false;
        for (CacheExpression cache : specialization.getCaches()) {
            if (cache.isAlwaysInitialized()) {
                continue;
            }
            if (cache.isCachedLibraryManuallyDispatched()) {
                if (useSpecializationClass(specialization)) {
                    resetSpecializationClass = true;
                    break;
                }
                builder.startStatement();
                builder.tree(createCacheReference(frameState, specialization, cache)).string(" = null");
                builder.end();
            }
        }
        if (resetSpecializationClass || specialization.hasMultipleInstances()) {
            builder.startStatement();
            builder.string("this.", createSpecializationFieldName(specialization));
            builder.string(" = null");
            builder.end();
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Arrays(java.util.Arrays) Modifier(javax.lang.model.element.Modifier) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression) TypeElement(javax.lang.model.element.TypeElement) ElementUtils.isObject(com.oracle.truffle.dsl.processor.java.ElementUtils.isObject) CreateCastData(com.oracle.truffle.dsl.processor.model.CreateCastData) CodeTypeParameterElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeParameterElement) ElementUtils.uniqueSortedTypes(com.oracle.truffle.dsl.processor.java.ElementUtils.uniqueSortedTypes) NodeFieldData(com.oracle.truffle.dsl.processor.model.NodeFieldData) DSLExpressionReducer(com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionReducer) FINAL(javax.lang.model.element.Modifier.FINAL) ImplicitCastData(com.oracle.truffle.dsl.processor.model.ImplicitCastData) Map(java.util.Map) ElementUtils.getTypeId(com.oracle.truffle.dsl.processor.java.ElementUtils.getTypeId) ElementUtils.firstLetterUpperCase(com.oracle.truffle.dsl.processor.java.ElementUtils.firstLetterUpperCase) ArrayType(javax.lang.model.type.ArrayType) ClassLiteral(com.oracle.truffle.dsl.processor.expression.DSLExpression.ClassLiteral) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) ElementUtils.setVisibility(com.oracle.truffle.dsl.processor.java.ElementUtils.setVisibility) Set(java.util.Set) Element(javax.lang.model.element.Element) GuardExpression(com.oracle.truffle.dsl.processor.model.GuardExpression) SpecializationGroup(com.oracle.truffle.dsl.processor.parser.SpecializationGroup) NodeChildData(com.oracle.truffle.dsl.processor.model.NodeChildData) ElementUtils.isAssignable(com.oracle.truffle.dsl.processor.java.ElementUtils.isAssignable) DSLExpression(com.oracle.truffle.dsl.processor.expression.DSLExpression) ElementUtils.boxType(com.oracle.truffle.dsl.processor.java.ElementUtils.boxType) GeneratorUtils.createTransferToInterpreterAndInvalidate(com.oracle.truffle.dsl.processor.generator.GeneratorUtils.createTransferToInterpreterAndInvalidate) AbstractDSLExpressionVisitor(com.oracle.truffle.dsl.processor.expression.DSLExpression.AbstractDSLExpressionVisitor) VariableElement(javax.lang.model.element.VariableElement) TruffleTypes(com.oracle.truffle.dsl.processor.TruffleTypes) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ElementUtils.findAnnotationMirror(com.oracle.truffle.dsl.processor.java.ElementUtils.findAnnotationMirror) ElementUtils.getVisibility(com.oracle.truffle.dsl.processor.java.ElementUtils.getVisibility) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression) SpecializationThrowsData(com.oracle.truffle.dsl.processor.model.SpecializationThrowsData) DeclaredType(javax.lang.model.type.DeclaredType) ElementFilter(javax.lang.model.util.ElementFilter) LinkedHashSet(java.util.LinkedHashSet) Variable(com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable) ElementUtils.needsCastTo(com.oracle.truffle.dsl.processor.java.ElementUtils.needsCastTo) VarHandle(java.lang.invoke.VarHandle) ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CodeNames(com.oracle.truffle.dsl.processor.java.model.CodeNames) Lock(java.util.concurrent.locks.Lock) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) Negate(com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate) ExportsGenerator(com.oracle.truffle.dsl.processor.library.ExportsGenerator) ExecutableTypeData(com.oracle.truffle.dsl.processor.model.ExecutableTypeData) ListIterator(java.util.ListIterator) TypeGuard(com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard) ElementUtils.getReadableSignature(com.oracle.truffle.dsl.processor.java.ElementUtils.getReadableSignature) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) ElementUtils.getSimpleName(com.oracle.truffle.dsl.processor.java.ElementUtils.getSimpleName) NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) ElementUtils.getQualifiedName(com.oracle.truffle.dsl.processor.java.ElementUtils.getQualifiedName) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) TruffleProcessorOptions(com.oracle.truffle.dsl.processor.TruffleProcessorOptions) ElementUtils.isVoid(com.oracle.truffle.dsl.processor.java.ElementUtils.isVoid) NodeData(com.oracle.truffle.dsl.processor.model.NodeData) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) ABSTRACT(javax.lang.model.element.Modifier.ABSTRACT) Collection(java.util.Collection) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) TypeKind(javax.lang.model.type.TypeKind) Objects(java.util.Objects) List(java.util.List) TemplateMethod(com.oracle.truffle.dsl.processor.model.TemplateMethod) Entry(java.util.Map.Entry) ElementUtils.isSubtypeBoxed(com.oracle.truffle.dsl.processor.java.ElementUtils.isSubtypeBoxed) Binary(com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) NodeParser(com.oracle.truffle.dsl.processor.parser.NodeParser) ElementUtils.isPrimitive(com.oracle.truffle.dsl.processor.java.ElementUtils.isPrimitive) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) TypeSystemData(com.oracle.truffle.dsl.processor.model.TypeSystemData) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Function(java.util.function.Function) HashSet(java.util.HashSet) ElementUtils.isSubtype(com.oracle.truffle.dsl.processor.java.ElementUtils.isSubtype) ElementUtils.typeEquals(com.oracle.truffle.dsl.processor.java.ElementUtils.typeEquals) ElementUtils.getAnnotationValue(com.oracle.truffle.dsl.processor.java.ElementUtils.getAnnotationValue) ElementUtils(com.oracle.truffle.dsl.processor.java.ElementUtils) ElementUtils.executableEquals(com.oracle.truffle.dsl.processor.java.ElementUtils.executableEquals) CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) PRIVATE(javax.lang.model.element.Modifier.PRIVATE) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Call(com.oracle.truffle.dsl.processor.expression.DSLExpression.Call) PUBLIC(javax.lang.model.element.Modifier.PUBLIC) ExecutableElement(javax.lang.model.element.ExecutableElement) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) STATIC(javax.lang.model.element.Modifier.STATIC) TypeMirror(javax.lang.model.type.TypeMirror) ElementUtils.modifiers(com.oracle.truffle.dsl.processor.java.ElementUtils.modifiers) ElementUtils.firstLetterLowerCase(com.oracle.truffle.dsl.processor.java.ElementUtils.firstLetterLowerCase) Comparator(java.util.Comparator) Collections(java.util.Collections) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) ArrayList(java.util.ArrayList) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression) LinkedHashMap(java.util.LinkedHashMap) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression) ReentrantLock(java.util.concurrent.locks.ReentrantLock) GuardExpression(com.oracle.truffle.dsl.processor.model.GuardExpression) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) SpecializationGroup(com.oracle.truffle.dsl.processor.parser.SpecializationGroup) NodeData(com.oracle.truffle.dsl.processor.model.NodeData) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) ElementUtils.isObject(com.oracle.truffle.dsl.processor.java.ElementUtils.isObject) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) TypeGuard(com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)

Example 3 with PRIVATE

use of javax.lang.model.element.Modifier.PRIVATE in project auto by google.

the class FactoryWriter method isTypeUseAnnotation.

private static boolean isTypeUseAnnotation(AnnotationMirror mirror) {
    Element annotationElement = mirror.getAnnotationType().asElement();
    // This is basically equivalent to:
    // Target target = annotationElement.getAnnotation(Target.class);
    // return target != null
    // && Arrays.asList(annotationElement.getAnnotation(Target.class)).contains(TYPE_USE);
    // but that might blow up if the annotation is being compiled at the same time and has an
    // undefined identifier in its @Target values. The rigmarole below avoids that problem.
    Optional<AnnotationMirror> maybeTargetMirror = Mirrors.getAnnotationMirror(annotationElement, Target.class);
    return maybeTargetMirror.map(targetMirror -> AnnotationValues.getEnums(AnnotationMirrors.getAnnotationValue(targetMirror, "value")).stream().map(VariableElement::getSimpleName).anyMatch(name -> name.contentEquals("TYPE_USE"))).orElse(false);
}
Also used : Provider(javax.inject.Provider) ClassName(com.squareup.javapoet.ClassName) Elements(javax.lang.model.util.Elements) FINAL(javax.lang.model.element.Modifier.FINAL) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) ParameterSpec(com.squareup.javapoet.ParameterSpec) MethodSpec.constructorBuilder(com.squareup.javapoet.MethodSpec.constructorBuilder) Element(javax.lang.model.element.Element) Streams(com.google.common.collect.Streams) Collectors.joining(java.util.stream.Collectors.joining) Sets(com.google.common.collect.Sets) TypeKind(javax.lang.model.type.TypeKind) JavaFile(com.squareup.javapoet.JavaFile) SourceVersion(javax.lang.model.SourceVersion) List(java.util.List) Stream(java.util.stream.Stream) Filer(javax.annotation.processing.Filer) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) TypeVariable(javax.lang.model.type.TypeVariable) Iterables(com.google.common.collect.Iterables) MoreTypes(com.google.auto.common.MoreTypes) VariableElement(javax.lang.model.element.VariableElement) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) TypeSpec.classBuilder(com.squareup.javapoet.TypeSpec.classBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) DeclaredType(javax.lang.model.type.DeclaredType) CodeBlock(com.squareup.javapoet.CodeBlock) TypeVariableName(com.squareup.javapoet.TypeVariableName) PRIVATE(javax.lang.model.element.Modifier.PRIVATE) Iterator(java.util.Iterator) MethodSpec(com.squareup.javapoet.MethodSpec) PUBLIC(javax.lang.model.element.Modifier.PUBLIC) GeneratedAnnotationSpecs.generatedAnnotationSpec(com.google.auto.common.GeneratedAnnotationSpecs.generatedAnnotationSpec) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) IOException(java.io.IOException) Target(java.lang.annotation.Target) TypeSpec(com.squareup.javapoet.TypeSpec) AnnotationMirror(javax.lang.model.element.AnnotationMirror) STATIC(javax.lang.model.element.Modifier.STATIC) Collectors.toList(java.util.stream.Collectors.toList) TypeMirror(javax.lang.model.type.TypeMirror) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) AnnotationValues(com.google.auto.common.AnnotationValues) MethodSpec.methodBuilder(com.squareup.javapoet.MethodSpec.methodBuilder) AnnotationMirrors(com.google.auto.common.AnnotationMirrors) AnnotationMirror(javax.lang.model.element.AnnotationMirror) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

Iterator (java.util.Iterator)3 List (java.util.List)3 Element (javax.lang.model.element.Element)3 FINAL (javax.lang.model.element.Modifier.FINAL)3 ProcessorContext (com.oracle.truffle.dsl.processor.ProcessorContext)2 DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)2 Binary (com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary)2 Call (com.oracle.truffle.dsl.processor.expression.DSLExpression.Call)2 DSLExpressionReducer (com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionReducer)2 Negate (com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate)2 Variable (com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable)2 ElementUtils (com.oracle.truffle.dsl.processor.java.ElementUtils)2 ElementUtils.modifiers (com.oracle.truffle.dsl.processor.java.ElementUtils.modifiers)2 CodeAnnotationMirror (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror)2 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)2 CodeNames (com.oracle.truffle.dsl.processor.java.model.CodeNames)2 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)2 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)2 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)2 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)2