當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。