当前位置: 首页>>代码示例>>Java>>正文


Java List.length方法代码示例

本文整理汇总了Java中com.sun.tools.javac.util.List.length方法的典型用法代码示例。如果您正苦于以下问题:Java List.length方法的具体用法?Java List.length怎么用?Java List.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.util.List的用法示例。


在下文中一共展示了List.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hasParameterTypes

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
private boolean hasParameterTypes(MethodSymbol method, String[] argTypes) {

        if (argTypes == null) {
            // wildcard
            return true;
        }

        int i = 0;
        List<Type> types = method.type.getParameterTypes();

        if (argTypes.length != types.length()) {
            return false;
        }

        for (Type t : types) {
            String argType = argTypes[i++];
            // For vararg method, "T..." matches type T[].
            if (i == argTypes.length) {
                argType = argType.replace("...", "[]");
            }
            if (!hasTypeName(env.types.erasure(t), argType)) {  //###(gj)
                return false;
            }
        }
        return true;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:ClassDocImpl.java

示例2: genStats

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
 * Derived visitor method: check whether CharacterRangeTable
 * should be emitted, if so, put a new entry into CRTable
 * and call method to generate bytecode.
 * If not, just call method to generate bytecode.
 *
 * @param trees    The list of trees to be visited.
 * @param env      The environment to use.
 * @param crtFlags The CharacterRangeTable flags
 *                 indicating type of the entry.
 * @see #genStats(List, Env)
 */
public void genStats(List<JCStatement> trees, Env<GenContext> env, int crtFlags) {
    if (!genCrt) {
        genStats(trees, env);
        return;
    }
    if (trees.length() == 1) {        // mark one statement with the flags
        genStat(trees.head, env, crtFlags | CRT_STATEMENT);
    } else {
        int startpc = code.curPc();
        genStats(trees, env);
        code.crt.put(trees, crtFlags, startpc, code.curPc());
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:Gen.java

示例3: Subst

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
public Subst(List<Type> from, List<Type> to) {
    int fromLength = from.length();
    int toLength = to.length();
    while (fromLength > toLength) {
        fromLength--;
        from = from.tail;
    }
    while (fromLength < toLength) {
        toLength--;
        to = to.tail;
    }
    this.from = from;
    this.to = to;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:15,代码来源:Types.java

示例4: adaptRecursive

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
private void adaptRecursive(List<Type> source, List<Type> target) {
    if (source.length() == target.length()) {
        while (source.nonEmpty()) {
            adaptRecursive(source.head, target.head);
            source = source.tail;
            target = target.tail;
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:10,代码来源:Types.java

示例5: annotations

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
 * Get the annotations of this program element.
 * Return an empty array if there are none.
 */
public AnnotationDesc[] annotations() {
    if (!type.isAnnotated()) {
        return new AnnotationDesc[0];
    }
    List<? extends TypeCompound> tas = type.getAnnotationMirrors();
    AnnotationDesc res[] = new AnnotationDesc[tas.length()];
    int i = 0;
    for (Attribute.Compound a : tas) {
        res[i++] = new AnnotationDescImpl(env, a);
    }
    return res;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TypeVariableImpl.java

示例6: parameters

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
 * Get argument information.
 *
 * @see ParameterImpl
 *
 * @return an array of ParameterImpl, one element per argument
 * in the order the arguments are present.
 */
public Parameter[] parameters() {
    // generate the parameters on the fly:  they're not cached
    List<VarSymbol> params = sym.params();
    Parameter result[] = new Parameter[params.length()];

    int i = 0;
    for (VarSymbol param : params) {
        result[i++] = new ParameterImpl(env, param);
    }
    return result;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ExecutableMemberDocImpl.java

示例7: elementValues

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
 * Returns this annotation's elements and their values.
 * Only those explicitly present in the annotation are
 * included, not those assuming their default values.
 * Returns an empty array if there are none.
 */
public ElementValuePair[] elementValues() {
    List<Pair<MethodSymbol,Attribute>> vals = annotation.values;
    ElementValuePair res[] = new ElementValuePair[vals.length()];
    int i = 0;
    for (Pair<MethodSymbol,Attribute> val : vals) {
        res[i++] = new ElementValuePairImpl(env, val.fst, val.snd);
    }
    return res;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:AnnotationDescImpl.java

示例8: setOption

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
 * indicate an option with the specified list of arguments was given.
 */
private void setOption(String opt, List<String> arguments) {
    String[] args = new String[arguments.length() + 1];
    int k = 0;
    args[k++] = opt;
    for (List<String> i = arguments; i.nonEmpty(); i=i.tail) {
        args[k++] = i.head;
    }
    options.append(args);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:Start.java

示例9: genStats

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/** Derived visitor method: check whether CharacterRangeTable
 *  should be emitted, if so, put a new entry into CRTable
 *  and call method to generate bytecode.
 *  If not, just call method to generate bytecode.
 *  @see    #genStats(List, Env)
 *
 *  @param  trees    The list of trees to be visited.
 *  @param  env      The environment to use.
 *  @param  crtFlags The CharacterRangeTable flags
 *                   indicating type of the entry.
 */
public void genStats(List<JCStatement> trees, Env<GenContext> env, int crtFlags) {
    if (!genCrt) {
        genStats(trees, env);
        return;
    }
    if (trees.length() == 1) {        // mark one statement with the flags
        genStat(trees.head, env, crtFlags | CRT_STATEMENT);
    } else {
        int startpc = code.curCP();
        genStats(trees, env);
        code.crt.put(trees, crtFlags, startpc, code.curCP());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:Gen.java

示例10: initNodes

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
 * Create the graph nodes. First a simple node is created for every inference
 * variables to be solved. Then Tarjan is used to found all connected components
 * in the graph. For each component containing more than one node, a super node is
 * created, effectively replacing the original cyclic nodes.
 */
void initNodes() {
    //add nodes
    nodes = new ArrayList<>();
    for (Type t : inferenceContext.restvars()) {
        nodes.add(new Node(t));
    }
    //add dependencies
    for (Node n_i : nodes) {
        Type i = n_i.data.first();
        for (Node n_j : nodes) {
            Type j = n_j.data.first();
            // don't compare a variable to itself
            if (i != j) {
                UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i);
                if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) {
                    //update i's bound dependencies
                    n_i.addDependency(n_j);
                }
            }
        }
    }
    //merge cyclic nodes
    ArrayList<Node> acyclicNodes = new ArrayList<>();
    for (List<? extends Node> conSubGraph : GraphUtils.tarjan(nodes)) {
        if (conSubGraph.length() > 1) {
            Node root = conSubGraph.head;
            root.mergeWith(conSubGraph.tail);
            for (Node n : conSubGraph) {
                notifyUpdate(n, root);
            }
        }
        acyclicNodes.add(conSubGraph.head);
    }
    nodes = acyclicNodes;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:Infer.java

示例11: attributeAnnotationValues

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
 *  Attribute annotation elements creating a list of pairs of the Symbol representing that
 *  element and the value of that element as an Attribute. */
private List<Pair<MethodSymbol, Attribute>> attributeAnnotationValues(JCAnnotation a,
        Type expected, Env<AttrContext> env)
{
    // The annotation might have had its type attributed (but not
    // checked) by attr.attribAnnotationTypes during MemberEnter,
    // in which case we do not need to do it again.
    Type at = (a.annotationType.type != null ?
            a.annotationType.type : attr.attribType(a.annotationType, env));
    a.type = chk.checkType(a.annotationType.pos(), at, expected);

    boolean isError = a.type.isErroneous();
    if (!a.type.tsym.isAnnotationType() && !isError) {
        log.error(a.annotationType.pos(), Errors.NotAnnotationType(a.type));
        isError = true;
    }

    // List of name=value pairs (or implicit "value=" if size 1)
    List<JCExpression> args = a.args;

    boolean elidedValue = false;
    // special case: elided "value=" assumed
    if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
        args.head = make.at(args.head.pos).
                Assign(make.Ident(names.value), args.head);
        elidedValue = true;
    }

    ListBuffer<Pair<MethodSymbol,Attribute>> buf = new ListBuffer<>();
    for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) {
        Pair<MethodSymbol, Attribute> p = attributeAnnotationNameValuePair(tl.head, a.type, isError, env, elidedValue);
        if (p != null && !p.fst.type.isErroneous())
            buf.append(p);
    }
    return buf.toList();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:Annotate.java

示例12: checkIntersection

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
Type checkIntersection(JCTree tree, List<JCExpression> bounds) {
    Set<Type> boundSet = new HashSet<Type>();
    if (bounds.nonEmpty()) {
        // accept class or interface or typevar as first bound.
        bounds.head.type = checkBase(bounds.head.type, bounds.head, env, false, false, false);
        boundSet.add(types.erasure(bounds.head.type));
        if (bounds.head.type.isErroneous()) {
            return bounds.head.type;
        }
        else if (bounds.head.type.hasTag(TYPEVAR)) {
            // if first bound was a typevar, do not accept further bounds.
            if (bounds.tail.nonEmpty()) {
                log.error(bounds.tail.head.pos(),
                          "type.var.may.not.be.followed.by.other.bounds");
                return bounds.head.type;
            }
        } else {
            // if first bound was a class or interface, accept only interfaces
            // as further bounds.
            for (JCExpression bound : bounds.tail) {
                bound.type = checkBase(bound.type, bound, env, false, true, false);
                if (bound.type.isErroneous()) {
                    bounds = List.of(bound);
                }
                else if (bound.type.hasTag(CLASS)) {
                    chk.checkNotRepeated(bound.pos(), types.erasure(bound.type), boundSet);
                }
            }
        }
    }

    if (bounds.length() == 0) {
        return syms.objectType;
    } else if (bounds.length() == 1) {
        return bounds.head.type;
    } else {
        Type owntype = types.makeCompoundType(TreeInfo.types(bounds));
        // ... the variable's bound is a class type flagged COMPOUND
        // (see comment for TypeVar.bound).
        // In this case, generate a class tree that represents the
        // bound class, ...
        JCExpression extending;
        List<JCExpression> implementing;
        if (!bounds.head.type.isInterface()) {
            extending = bounds.head;
            implementing = bounds.tail;
        } else {
            extending = null;
            implementing = bounds;
        }
        JCClassDecl cd = make.at(tree).ClassDef(
            make.Modifiers(PUBLIC | ABSTRACT),
            names.empty, List.<JCTypeParameter>nil(),
            extending, implementing, List.<JCTree>nil());

        ClassSymbol c = (ClassSymbol)owntype.tsym;
        Assert.check((c.flags() & COMPOUND) != 0);
        cd.sym = c;
        c.sourcefile = env.toplevel.sourcefile;

        // ... and attribute the bound class
        c.flags_field |= UNATTRIBUTED;
        Env<AttrContext> cenv = enter.classEnv(cd, env);
        typeEnvs.put(c, cenv);
        attribClass(c);
        return owntype;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:69,代码来源:Attr.java

示例13: checkPotentiallyAmbiguousOverloads

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
  * Report warnings for potentially ambiguous method declarations. Two declarations
  * are potentially ambiguous if they feature two unrelated functional interface
  * in same argument position (in which case, a call site passing an implicit
  * lambda would be ambiguous).
  */
void checkPotentiallyAmbiguousOverloads(DiagnosticPosition pos, Type site,
        MethodSymbol msym1, MethodSymbol msym2) {
    if (msym1 != msym2 &&
            allowDefaultMethods &&
            lint.isEnabled(LintCategory.OVERLOADS) &&
            (msym1.flags() & POTENTIALLY_AMBIGUOUS) == 0 &&
            (msym2.flags() & POTENTIALLY_AMBIGUOUS) == 0) {
        Type mt1 = types.memberType(site, msym1);
        Type mt2 = types.memberType(site, msym2);
        //if both generic methods, adjust type variables
        if (mt1.hasTag(FORALL) && mt2.hasTag(FORALL) &&
                types.hasSameBounds((ForAll)mt1, (ForAll)mt2)) {
            mt2 = types.subst(mt2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
        }
        //expand varargs methods if needed
        int maxLength = Math.max(mt1.getParameterTypes().length(), mt2.getParameterTypes().length());
        List<Type> args1 = rs.adjustArgs(mt1.getParameterTypes(), msym1, maxLength, true);
        List<Type> args2 = rs.adjustArgs(mt2.getParameterTypes(), msym2, maxLength, true);
        //if arities don't match, exit
        if (args1.length() != args2.length()) return;
        boolean potentiallyAmbiguous = false;
        while (args1.nonEmpty() && args2.nonEmpty()) {
            Type s = args1.head;
            Type t = args2.head;
            if (!types.isSubtype(t, s) && !types.isSubtype(s, t)) {
                if (types.isFunctionalInterface(s) && types.isFunctionalInterface(t) &&
                        types.findDescriptorType(s).getParameterTypes().length() > 0 &&
                        types.findDescriptorType(s).getParameterTypes().length() ==
                        types.findDescriptorType(t).getParameterTypes().length()) {
                    potentiallyAmbiguous = true;
                } else {
                    break;
                }
            }
            args1 = args1.tail;
            args2 = args2.tail;
        }
        if (potentiallyAmbiguous) {
            //we found two incompatible functional interfaces with same arity
            //this means a call site passing an implicit lambda would be ambigiuous
            msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
            msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
            log.warning(LintCategory.OVERLOADS, pos, "potentially.ambiguous.overload",
                        msym1, msym1.location(),
                        msym2, msym2.location());
            return;
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:56,代码来源:Check.java

示例14: checkIntersection

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
Type checkIntersection(JCTree tree, List<JCExpression> bounds) {
    Set<Type> boundSet = new HashSet<>();
    if (bounds.nonEmpty()) {
        // accept class or interface or typevar as first bound.
        bounds.head.type = checkBase(bounds.head.type, bounds.head, env, false, false, false);
        boundSet.add(types.erasure(bounds.head.type));
        if (bounds.head.type.isErroneous()) {
            return bounds.head.type;
        }
        else if (bounds.head.type.hasTag(TYPEVAR)) {
            // if first bound was a typevar, do not accept further bounds.
            if (bounds.tail.nonEmpty()) {
                log.error(bounds.tail.head.pos(),
                          Errors.TypeVarMayNotBeFollowedByOtherBounds);
                return bounds.head.type;
            }
        } else {
            // if first bound was a class or interface, accept only interfaces
            // as further bounds.
            for (JCExpression bound : bounds.tail) {
                bound.type = checkBase(bound.type, bound, env, false, true, false);
                if (bound.type.isErroneous()) {
                    bounds = List.of(bound);
                }
                else if (bound.type.hasTag(CLASS)) {
                    chk.checkNotRepeated(bound.pos(), types.erasure(bound.type), boundSet);
                }
            }
        }
    }

    if (bounds.length() == 0) {
        return syms.objectType;
    } else if (bounds.length() == 1) {
        return bounds.head.type;
    } else {
        Type owntype = types.makeIntersectionType(TreeInfo.types(bounds));
        // ... the variable's bound is a class type flagged COMPOUND
        // (see comment for TypeVar.bound).
        // In this case, generate a class tree that represents the
        // bound class, ...
        JCExpression extending;
        List<JCExpression> implementing;
        if (!bounds.head.type.isInterface()) {
            extending = bounds.head;
            implementing = bounds.tail;
        } else {
            extending = null;
            implementing = bounds;
        }
        JCClassDecl cd = make.at(tree).ClassDef(
            make.Modifiers(PUBLIC | ABSTRACT),
            names.empty, List.nil(),
            extending, implementing, List.nil());

        ClassSymbol c = (ClassSymbol)owntype.tsym;
        Assert.check((c.flags() & COMPOUND) != 0);
        cd.sym = c;
        c.sourcefile = env.toplevel.sourcefile;

        // ... and attribute the bound class
        c.flags_field |= UNATTRIBUTED;
        Env<AttrContext> cenv = enter.classEnv(cd, env);
        typeEnvs.put(c, cenv);
        attribClass(c);
        return owntype;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:69,代码来源:Attr.java

示例15: checkPotentiallyAmbiguousOverloads

import com.sun.tools.javac.util.List; //导入方法依赖的package包/类
/**
  * Report warnings for potentially ambiguous method declarations. Two declarations
  * are potentially ambiguous if they feature two unrelated functional interface
  * in same argument position (in which case, a call site passing an implicit
  * lambda would be ambiguous).
  */
void checkPotentiallyAmbiguousOverloads(DiagnosticPosition pos, Type site,
        MethodSymbol msym1, MethodSymbol msym2) {
    if (msym1 != msym2 &&
            allowDefaultMethods &&
            lint.isEnabled(LintCategory.OVERLOADS) &&
            (msym1.flags() & POTENTIALLY_AMBIGUOUS) == 0 &&
            (msym2.flags() & POTENTIALLY_AMBIGUOUS) == 0) {
        Type mt1 = types.memberType(site, msym1);
        Type mt2 = types.memberType(site, msym2);
        //if both generic methods, adjust type variables
        if (mt1.hasTag(FORALL) && mt2.hasTag(FORALL) &&
                types.hasSameBounds((ForAll)mt1, (ForAll)mt2)) {
            mt2 = types.subst(mt2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
        }
        //expand varargs methods if needed
        int maxLength = Math.max(mt1.getParameterTypes().length(), mt2.getParameterTypes().length());
        List<Type> args1 = rs.adjustArgs(mt1.getParameterTypes(), msym1, maxLength, true);
        List<Type> args2 = rs.adjustArgs(mt2.getParameterTypes(), msym2, maxLength, true);
        //if arities don't match, exit
        if (args1.length() != args2.length()) return;
        boolean potentiallyAmbiguous = false;
        while (args1.nonEmpty() && args2.nonEmpty()) {
            Type s = args1.head;
            Type t = args2.head;
            if (!types.isSubtype(t, s) && !types.isSubtype(s, t)) {
                if (types.isFunctionalInterface(s) && types.isFunctionalInterface(t) &&
                        types.findDescriptorType(s).getParameterTypes().length() > 0 &&
                        types.findDescriptorType(s).getParameterTypes().length() ==
                        types.findDescriptorType(t).getParameterTypes().length()) {
                    potentiallyAmbiguous = true;
                } else {
                    break;
                }
            }
            args1 = args1.tail;
            args2 = args2.tail;
        }
        if (potentiallyAmbiguous) {
            //we found two incompatible functional interfaces with same arity
            //this means a call site passing an implicit lambda would be ambigiuous
            msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
            msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
            log.warning(LintCategory.OVERLOADS, pos,
                        Warnings.PotentiallyAmbiguousOverload(msym1, msym1.location(),
                                                              msym2, msym2.location()));
            return;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:56,代码来源:Check.java


注:本文中的com.sun.tools.javac.util.List.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。