Java Code Examples for com.sun.tools.javac.util.ListBuffer#isEmpty()

The following examples show how to use com.sun.tools.javac.util.ListBuffer#isEmpty() . 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: Types.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private Type rewriteSupers(Type t) {
    if (!t.isParameterized())
        return t;
    ListBuffer<Type> from = lb();
    ListBuffer<Type> to = lb();
    adaptSelf(t, from, to);
    if (from.isEmpty())
        return t;
    ListBuffer<Type> rewrite = lb();
    boolean changed = false;
    for (Type orig : to.toList()) {
        Type s = rewriteSupers(orig);
        if (s.isSuperBound() && !s.isExtendsBound()) {
            s = new WildcardType(syms.objectType,
                                 BoundKind.UNBOUND,
                                 syms.boundClass);
            changed = true;
        } else if (s != orig) {
            s = new WildcardType(upperBound(s),
                                 BoundKind.EXTENDS,
                                 syms.boundClass);
            changed = true;
        }
        rewrite.append(s);
    }
    if (changed)
        return subst(t.tsym.type, from.toList(), rewrite.toList());
    else
        return t;
}
 
Example 2
Source File: StringConcat.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Peel the argument list into smaller chunks. */
protected List<List<JCTree>> split(List<JCTree> args) {
    ListBuffer<List<JCTree>> splits = new ListBuffer<>();

    int slots = 0;

    // Need to peel, so that neither call has more than acceptable number
    // of slots for the arguments.
    ListBuffer<JCTree> cArgs = new ListBuffer<>();
    for (JCTree t : args) {
        int needSlots = (t.type.getTag() == LONG || t.type.getTag() == DOUBLE) ? 2 : 1;
        if (slots + needSlots >= MAX_INDY_CONCAT_ARG_SLOTS) {
            splits.add(cArgs.toList());
            cArgs.clear();
            slots = 0;
        }
        cArgs.add(t);
        slots += needSlots;
    }

    // Flush the tail slice
    if (!cArgs.isEmpty()) {
        splits.add(cArgs.toList());
    }

    return splits.toList();
}
 
Example 3
Source File: Types.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private Type rewriteSupers(Type t) {
    if (!t.isParameterized())
        return t;
    ListBuffer<Type> from = lb();
    ListBuffer<Type> to = lb();
    adaptSelf(t, from, to);
    if (from.isEmpty())
        return t;
    ListBuffer<Type> rewrite = lb();
    boolean changed = false;
    for (Type orig : to.toList()) {
        Type s = rewriteSupers(orig);
        if (s.isSuperBound() && !s.isExtendsBound()) {
            s = new WildcardType(syms.objectType,
                                 BoundKind.UNBOUND,
                                 syms.boundClass);
            changed = true;
        } else if (s != orig) {
            s = new WildcardType(upperBound(s),
                                 BoundKind.EXTENDS,
                                 syms.boundClass);
            changed = true;
        }
        rewrite.append(s);
    }
    if (changed)
        return subst(t.tsym.type, from.toList(), rewrite.toList());
    else
        return t;
}
 
Example 4
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitProvides(JCProvides tree) {
    Type st = attr.attribType(tree.serviceName, env, syms.objectType);
    ClassSymbol service = (ClassSymbol) st.tsym;
    if (allProvides.containsKey(service)) {
        log.error(tree.serviceName.pos(), Errors.RepeatedProvidesForService(service));
    }
    ListBuffer<ClassSymbol> impls = new ListBuffer<>();
    for (JCExpression implName : tree.implNames) {
        Type it;
        boolean prevVisitingServiceImplementation = env.info.visitingServiceImplementation;
        try {
            env.info.visitingServiceImplementation = true;
            it = attr.attribType(implName, env, syms.objectType);
        } finally {
            env.info.visitingServiceImplementation = prevVisitingServiceImplementation;
        }
        ClassSymbol impl = (ClassSymbol) it.tsym;
        if ((impl.flags_field & PUBLIC) == 0) {
            log.error(implName.pos(), Errors.NotDefPublic(impl, impl.location()));
        }
        //find provider factory:
        MethodSymbol factory = factoryMethod(impl);
        if (factory != null) {
            Type returnType = factory.type.getReturnType();
            if (!types.isSubtype(returnType, st)) {
                log.error(implName.pos(), Errors.ServiceImplementationProviderReturnMustBeSubtypeOfServiceInterface);
            }
        } else {
            if (!types.isSubtype(it, st)) {
                log.error(implName.pos(), Errors.ServiceImplementationMustBeSubtypeOfServiceInterface);
            } else if ((impl.flags() & ABSTRACT) != 0) {
                log.error(implName.pos(), Errors.ServiceImplementationIsAbstract(impl));
            } else if (impl.isInner()) {
                log.error(implName.pos(), Errors.ServiceImplementationIsInner(impl));
            } else {
                MethodSymbol constr = noArgsConstructor(impl);
                if (constr == null) {
                    log.error(implName.pos(), Errors.ServiceImplementationDoesntHaveANoArgsConstructor(impl));
                } else if ((constr.flags() & PUBLIC) == 0) {
                    log.error(implName.pos(), Errors.ServiceImplementationNoArgsConstructorNotPublic(impl));
                }
            }
        }
        if (it.hasTag(CLASS)) {
            if (Maps.computeIfAbsent(allProvides,service, s -> new HashSet<>()).add(impl)) {
                impls.append(impl);
            } else {
                log.error(implName.pos(), Errors.DuplicateProvides(service, impl));
            }
        }
    }
    if (st.hasTag(CLASS) && !impls.isEmpty()) {
        Directive.ProvidesDirective d = new Directive.ProvidesDirective(service, impls.toList());
        msym.provides = msym.provides.prepend(d);
        msym.directives = msym.directives.prepend(d);
        directiveToTreeMap.put(d, tree);
    }
}
 
Example 5
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitProvides(JCProvides tree) {
    Type st = attr.attribType(tree.serviceName, env, syms.objectType);
    ClassSymbol service = (ClassSymbol) st.tsym;
    if (allProvides.containsKey(service)) {
        log.error(tree.serviceName.pos(), Errors.RepeatedProvidesForService(service));
    }
    ListBuffer<ClassSymbol> impls = new ListBuffer<>();
    for (JCExpression implName : tree.implNames) {
        Type it;
        boolean prevVisitingServiceImplementation = env.info.visitingServiceImplementation;
        try {
            env.info.visitingServiceImplementation = true;
            it = attr.attribType(implName, env, syms.objectType);
        } finally {
            env.info.visitingServiceImplementation = prevVisitingServiceImplementation;
        }
        ClassSymbol impl = (ClassSymbol) it.tsym;
        if ((impl.flags_field & PUBLIC) == 0) {
            log.error(implName.pos(), Errors.NotDefPublic(impl, impl.location()));
        }
        //find provider factory:
        MethodSymbol factory = factoryMethod(impl);
        if (factory != null) {
            Type returnType = factory.type.getReturnType();
            if (!types.isSubtype(returnType, st)) {
                log.error(implName.pos(), Errors.ServiceImplementationProviderReturnMustBeSubtypeOfServiceInterface);
            }
        } else {
            if (!types.isSubtype(it, st)) {
                log.error(implName.pos(), Errors.ServiceImplementationMustBeSubtypeOfServiceInterface);
            } else if ((impl.flags() & ABSTRACT) != 0) {
                log.error(implName.pos(), Errors.ServiceImplementationIsAbstract(impl));
            } else if (impl.isInner()) {
                log.error(implName.pos(), Errors.ServiceImplementationIsInner(impl));
            } else {
                MethodSymbol constr = noArgsConstructor(impl);
                if (constr == null) {
                    log.error(implName.pos(), Errors.ServiceImplementationDoesntHaveANoArgsConstructor(impl));
                } else if ((constr.flags() & PUBLIC) == 0) {
                    log.error(implName.pos(), Errors.ServiceImplementationNoArgsConstructorNotPublic(impl));
                }
            }
        }
        if (it.hasTag(CLASS)) {
            if (allProvides.computeIfAbsent(service, s -> new HashSet<>()).add(impl)) {
                impls.append(impl);
            } else {
                log.error(implName.pos(), Errors.DuplicateProvides(service, impl));
            }
        }
    }
    if (st.hasTag(CLASS) && !impls.isEmpty()) {
        Directive.ProvidesDirective d = new Directive.ProvidesDirective(service, impls.toList());
        msym.provides = msym.provides.prepend(d);
        msym.directives = msym.directives.prepend(d);
        directiveToTreeMap.put(d, tree);
    }
}