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

The following examples show how to use com.sun.tools.javac.util.ListBuffer#nonEmpty() . 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: TypeAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 2
Source File: TypeAnnotations.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 3
Source File: TypeAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 4
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void apportionTypeAnnotations(JCLambda tree,
                                      Supplier<List<Attribute.TypeCompound>> source,
                                      Consumer<List<Attribute.TypeCompound>> owner,
                                      Consumer<List<Attribute.TypeCompound>> lambda) {

    ListBuffer<Attribute.TypeCompound> ownerTypeAnnos = new ListBuffer<>();
    ListBuffer<Attribute.TypeCompound> lambdaTypeAnnos = new ListBuffer<>();

    for (Attribute.TypeCompound tc : source.get()) {
        if (tc.position.onLambda == tree) {
            lambdaTypeAnnos.append(tc);
        } else {
            ownerTypeAnnos.append(tc);
        }
    }
    if (lambdaTypeAnnos.nonEmpty()) {
        owner.accept(ownerTypeAnnos.toList());
        lambda.accept(lambdaTypeAnnos.toList());
    }
}
 
Example 5
Source File: TypeAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 6
Source File: TypeAnnotations.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 7
Source File: TypeAnnotations.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 8
Source File: TypeAnnotations.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 9
Source File: Types.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public Type visitClassType(ClassType t, Symbol sym) {
    if (t.tsym == sym)
        return t;
    Type base = asSuper(sym.type, t.tsym);
    if (base == null)
        return null;
    ListBuffer<Type> from = new ListBuffer<Type>();
    ListBuffer<Type> to = new ListBuffer<Type>();
    try {
        adapt(base, t, from, to);
    } catch (AdaptFailure ex) {
        return null;
    }
    Type res = subst(sym.type, from.toList(), to.toList());
    if (!isSubtype(res, t))
        return null;
    ListBuffer<Type> openVars = new ListBuffer<Type>();
    for (List<Type> l = sym.type.allparams();
         l.nonEmpty(); l = l.tail)
        if (res.contains(l.head) && !t.contains(l.head))
            openVars.append(l.head);
    if (openVars.nonEmpty()) {
        if (t.isRaw()) {
            // The subtype of a raw type is raw
            res = erasure(res);
        } else {
            // Unbound type arguments default to ?
            List<Type> opens = openVars.toList();
            ListBuffer<Type> qs = new ListBuffer<Type>();
            for (List<Type> iter = opens; iter.nonEmpty(); iter = iter.tail) {
                qs.append(new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass, (TypeVar) iter.head));
            }
            res = subst(res, opens, qs.toList());
        }
    }
    return res;
}
 
Example 10
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) {
    DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site);
    for (Symbol m : types.membersClosure(site, false).getSymbols(dcf)) {
        Assert.check(m.kind == MTH);
        List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol)m);
        if (prov.size() > 1) {
            ListBuffer<Symbol> abstracts = new ListBuffer<>();
            ListBuffer<Symbol> defaults = new ListBuffer<>();
            for (MethodSymbol provSym : prov) {
                if ((provSym.flags() & DEFAULT) != 0) {
                    defaults = defaults.append(provSym);
                } else if ((provSym.flags() & ABSTRACT) != 0) {
                    abstracts = abstracts.append(provSym);
                }
                if (defaults.nonEmpty() && defaults.size() + abstracts.size() >= 2) {
                    //strong semantics - issue an error if two sibling interfaces
                    //have two override-equivalent defaults - or if one is abstract
                    //and the other is default
                    String errKey;
                    Symbol s1 = defaults.first();
                    Symbol s2;
                    if (defaults.size() > 1) {
                        errKey = "types.incompatible.unrelated.defaults";
                        s2 = defaults.toList().tail.head;
                    } else {
                        errKey = "types.incompatible.abstract.default";
                        s2 = abstracts.first();
                    }
                    log.error(pos, errKey,
                            Kinds.kindName(site.tsym), site,
                            m.name, types.memberType(site, m).getParameterTypes(),
                            s1.location(), s2.location());
                    break;
                }
            }
        }
    }
}
 
Example 11
Source File: Types.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Type visitClassType(ClassType t, Symbol sym) {
    if (t.tsym == sym)
        return t;
    Type base = asSuper(sym.type, t.tsym);
    if (base == null)
        return null;
    ListBuffer<Type> from = new ListBuffer<Type>();
    ListBuffer<Type> to = new ListBuffer<Type>();
    try {
        adapt(base, t, from, to);
    } catch (AdaptFailure ex) {
        return null;
    }
    Type res = subst(sym.type, from.toList(), to.toList());
    if (!isSubtype(res, t))
        return null;
    ListBuffer<Type> openVars = new ListBuffer<Type>();
    for (List<Type> l = sym.type.allparams();
         l.nonEmpty(); l = l.tail)
        if (res.contains(l.head) && !t.contains(l.head))
            openVars.append(l.head);
    if (openVars.nonEmpty()) {
        if (t.isRaw()) {
            // The subtype of a raw type is raw
            res = erasure(res);
        } else {
            // Unbound type arguments default to ?
            List<Type> opens = openVars.toList();
            ListBuffer<Type> qs = new ListBuffer<Type>();
            for (List<Type> iter = opens; iter.nonEmpty(); iter = iter.tail) {
                qs.append(new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass, (TypeVar) iter.head));
            }
            res = subst(res, opens, qs.toList());
        }
    }
    return res;
}
 
Example 12
Source File: ModuleFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) {
    ListBuffer<ModuleSymbol> results = new ListBuffer<>();
    Map<Name, Location> namesInSet = new HashMap<>();
    boolean multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
    while (moduleLocationIterator.hasNext()) {
        Set<Location> locns = (moduleLocationIterator.next());
        namesInSet.clear();
        for (Location l: locns) {
            try {
                Name n = names.fromString(fileManager.inferModuleName(l));
                if (namesInSet.put(n, l) == null) {
                    ModuleSymbol msym = syms.enterModule(n);
                    if (msym.sourceLocation != null || msym.classLocation != null) {
                        // module has already been found, so ignore this instance
                        continue;
                    }
                    if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) &&
                        msym.patchLocation == null) {
                        msym.patchLocation =
                                fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH,
                                                                 msym.name.toString());
                        if (msym.patchLocation != null &&
                            multiModuleMode &&
                            fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.patchOutputLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    }
                    if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
                        msym.sourceLocation = l;
                        if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.classLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    } else {
                        msym.classLocation = l;
                    }
                    if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES ||
                        moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) {
                        msym.flags_field |= Flags.SYSTEM_MODULE;
                    }
                    if (toFind == null ||
                        (toFind == msym && (msym.sourceLocation != null || msym.classLocation != null))) {
                        // Note: cannot return msym directly, because we must finish
                        // processing this set first
                        results.add(msym);
                    }
                } else {
                    log.error(Errors.DuplicateModuleOnPath(
                            getDescription(moduleLocationIterator.outer), n));
                }
            } catch (IOException e) {
                // skip location for now?  log error?
            }
        }
        if (toFind != null && results.nonEmpty())
            return results.toList();
    }

    return results.toList();
}
 
Example 13
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Generate an indy method call to the meta factory
 */
private JCExpression makeMetafactoryIndyCall(TranslationContext<?> context,
        int refKind, Symbol refSym, List<JCExpression> indy_args) {
    JCFunctionalExpression tree = context.tree;
    //determine the static bsm args
    MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym);
    List<Object> staticArgs = List.of(
            typeToMethodType(samSym.type),
            new Pool.MethodHandle(refKind, refSym, types),
            typeToMethodType(tree.getDescriptorType(types)));

    //computed indy arg types
    ListBuffer<Type> indy_args_types = new ListBuffer<>();
    for (JCExpression arg : indy_args) {
        indy_args_types.append(arg.type);
    }

    //finally, compute the type of the indy call
    MethodType indyType = new MethodType(indy_args_types.toList(),
            tree.type,
            List.nil(),
            syms.methodClass);

    Name metafactoryName = context.needsAltMetafactory() ?
            names.altMetafactory : names.metafactory;

    if (context.needsAltMetafactory()) {
        ListBuffer<Object> markers = new ListBuffer<>();
        for (Type t : tree.targets.tail) {
            if (t.tsym != syms.serializableType.tsym) {
                markers.append(t.tsym);
            }
        }
        int flags = context.isSerializable() ? FLAG_SERIALIZABLE : 0;
        boolean hasMarkers = markers.nonEmpty();
        boolean hasBridges = context.bridges.nonEmpty();
        if (hasMarkers) {
            flags |= FLAG_MARKERS;
        }
        if (hasBridges) {
            flags |= FLAG_BRIDGES;
        }
        staticArgs = staticArgs.append(flags);
        if (hasMarkers) {
            staticArgs = staticArgs.append(markers.length());
            staticArgs = staticArgs.appendList(markers.toList());
        }
        if (hasBridges) {
            staticArgs = staticArgs.append(context.bridges.length() - 1);
            for (Symbol s : context.bridges) {
                Type s_erasure = s.erasure(types);
                if (!types.isSameType(s_erasure, samSym.erasure(types))) {
                    staticArgs = staticArgs.append(s.erasure(types));
                }
            }
        }
        if (context.isSerializable()) {
            int prevPos = make.pos;
            try {
                make.at(kInfo.clazz);
                addDeserializationCase(refKind, refSym, tree.type, samSym,
                        tree, staticArgs, indyType);
            } finally {
                make.at(prevPos);
            }
        }
    }

    return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args, samSym.name);
}
 
Example 14
Source File: ModuleFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) {
    ListBuffer<ModuleSymbol> results = new ListBuffer<>();
    Map<Name, Location> namesInSet = new HashMap<>();
    boolean multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
    while (moduleLocationIterator.hasNext()) {
        Set<Location> locns = (moduleLocationIterator.next());
        namesInSet.clear();
        for (Location l: locns) {
            try {
                Name n = names.fromString(fileManager.inferModuleName(l));
                if (namesInSet.put(n, l) == null) {
                    ModuleSymbol msym = syms.enterModule(n);
                    if (msym.sourceLocation != null || msym.classLocation != null) {
                        // module has already been found, so ignore this instance
                        continue;
                    }
                    if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) &&
                        msym.patchLocation == null) {
                        msym.patchLocation =
                                fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH,
                                                                 msym.name.toString());
                        if (msym.patchLocation != null &&
                            multiModuleMode &&
                            fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.patchOutputLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    }
                    if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
                        msym.sourceLocation = l;
                        if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.classLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    } else {
                        msym.classLocation = l;
                    }
                    if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES ||
                        moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) {
                        msym.flags_field |= Flags.SYSTEM_MODULE;
                    }
                    if (toFind == null ||
                        (toFind == msym && (msym.sourceLocation != null || msym.classLocation != null))) {
                        // Note: cannot return msym directly, because we must finish
                        // processing this set first
                        results.add(msym);
                    }
                } else {
                    log.error(Errors.DuplicateModuleOnPath(
                            getDescription(moduleLocationIterator.outer), n));
                }
            } catch (IOException e) {
                // skip location for now?  log error?
            }
        }
        if (toFind != null && results.nonEmpty())
            return results.toList();
    }

    return results.toList();
}