com.sun.tools.javac.util.List类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(15.3k)|赞(0)|评价(0)|浏览(344)

本文整理了Java中com.sun.tools.javac.util.List类的一些代码示例,展示了List类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List类的具体详情如下:
包路径:com.sun.tools.javac.util.List
类名称:List

List介绍

[英]A class for generic linked lists. Links are supposed to be immutable, the only exception being the incremental construction of lists via ListBuffers. List is the main container class in GJC. Most data structures and algorithms in GJC use lists rather than arrays.

Lists are always trailed by a sentinel element, whose head and tail are both null.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
[中]通用链表的类。链接应该是不可变的,唯一的例外是通过ListBuffers增量构建列表。列表是GJC中的主要容器类别。GJC中的大多数数据结构和算法使用列表而不是数组。
列表后面总是有一个sentinel元素,它的头和尾都是空的。
这不是任何受支持的API的一部分。如果您编写的代码依赖于此,那么您将自担风险。本代码及其内部接口如有更改或删除,恕不另行通知。

代码示例

代码示例来源:origin: robolectric/robolectric

public void addShadowType(TypeElement shadowType, TypeElement actualType,
  TypeElement shadowPickerType) {
 TypeElement shadowBaseType = null;
 if (shadowPickerType != null) {
  TypeMirror iface = helpers.findInterface(shadowPickerType, ShadowPicker.class);
  if (iface != null) {
   com.sun.tools.javac.code.Type type = ((com.sun.tools.javac.code.Type.ClassType) iface)
     .allparams().get(0);
   String baseClassName = type.asElement().getQualifiedName().toString();
   shadowBaseType = helpers.getTypeElement(baseClassName);
  }
 }
 ShadowInfo shadowInfo =
   new ShadowInfo(shadowType, actualType, shadowPickerType, shadowBaseType);
 if (shadowInfo.isInAndroidSdk()) {
  registerType(shadowInfo.shadowType);
  registerType(shadowInfo.actualType);
  registerType(shadowInfo.shadowBaseClass);
 }
 shadowTypes.put(shadowType.getQualifiedName().toString(), shadowInfo);
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

private boolean shouldWorkaroundBug() {
  Boolean result = HAS_BUG.get();
  if (result != null) {
    return result;
  }
  
  Context ctx = ((JavacProcessingEnvironment) processingEnv).getContext();
  TreeMaker make = TreeMaker.instance(ctx);
  final JCLiteral val = make.Literal("");
  JCMethodDecl method = make.MethodDef(null, null, null, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, val);
  final boolean[] noBug = new boolean[] {false};
  new TreeScanner() {
    @Override
    public void scan(JCTree tree) {
      noBug[0] |= (tree == val);
      super.scan(tree);
    }
  }.scan(method);
  HAS_BUG.compareAndSet(null, Boolean.valueOf(!noBug[0]));
  return HAS_BUG.get();
}

代码示例来源:origin: google/error-prone

int varargsPosition = params.length() - 1;
ArrayType varargsParamType = (ArrayType) params.last().type;
List<JCExpression> arguments = methodInvocation.getArguments();
Types types = state.getTypes();
if (arguments.size() != params.length()) {
 return false;
Type varargsArgumentType = arguments.get(varargsPosition).type;
if (!types.isArray(varargsArgumentType)
  || !types.elemtype(varargsArgumentType).isPrimitive()) {
 return false;

代码示例来源:origin: google/error-prone

@Override
 public Type get(VisitorState state) {
  Type type = typeSupplier.get(state);
  if (type.getTypeArguments().size() <= n) {
   return state.getSymtab().objectType;
  }
  return type.getTypeArguments().get(n);
 }
};

代码示例来源:origin: google/error-prone

public BlockTemplateMatch(JCBlock block, Unifier unifier, int start, int end) {
 super(checkNotNull(block).getStatements().get(start), unifier);
 this.statements = ImmutableList.copyOf(block.getStatements().subList(start, end));
}

代码示例来源:origin: uber/NullAway

/**
 * Works for method parameters defined either in source or in class files
 *
 * @param symbol the method symbol
 * @param paramInd index of the parameter
 * @return all declaration and type-use annotations for the parameter
 */
public static Stream<? extends AnnotationMirror> getAllAnnotationsForParameter(
  Symbol.MethodSymbol symbol, int paramInd) {
 Symbol.VarSymbol varSymbol = symbol.getParameters().get(paramInd);
 return Stream.concat(
   varSymbol.getAnnotationMirrors().stream(),
   symbol
     .getRawTypeAttributes()
     .stream()
     .filter(
       t ->
         t.position.type.equals(TargetType.METHOD_FORMAL_PARAMETER)
           && t.position.parameter_index == paramInd));
}

代码示例来源:origin: cincheo/jsweet

getScope().innerClassNotStatic = true;
    if (parent.getTypeParameters() != null) {
      parentTypeVars.addAll(parent.getTypeParameters().stream().map(t -> (TypeVariableSymbol) t.type.tsym)
          .collect(Collectors.toList()));
      getAdapter().typeVariablesToErase.addAll(parentTypeVars);
  if (classdecl.typarams != null && classdecl.typarams.size() > 0) {
    print("<").printArgList(null, classdecl.typarams).print(">");
  } else if (isAnonymousClass() && classdecl.getModifiers().getFlags().contains(Modifier.STATIC)) {
  if (classdecl.implementing != null && !classdecl.implementing.isEmpty() && !getScope().enumScope) {
    List<JCExpression> implementing = new ArrayList<>(classdecl.implementing);
    if (anonymousClassIndex != -1) {
      for (int i = 0; i < getScope(1).anonymousClassesConstructors.get(anonymousClassIndex).args
          .length(); i++) {
        if (!hasArgs) {
          hasArgs = true;
            .length(); i++) {
          if (hasArg) {
            print(", ");
        if (!newClass.args.isEmpty()) {
          print(", ");
if (getScope().mainMethod != null && getScope().mainMethod.getParameters().size() < 2
    && getScope().mainMethod.sym.getEnclosingElement().equals(classdecl.sym)) {
  String mainClassName = getQualifiedTypeName(classdecl.sym, globals, true);

代码示例来源:origin: cincheo/jsweet

|| !inv.args.isEmpty() && (inv.args.last().type.getKind() != TypeKind.ARRAY
        || !context.types.erasure(((ArrayType) inv.args.last().type).elemtype).equals(
            context.types.erasure(((ArrayType) methSym.getParameters().last().type).elemtype)))) {
  applyVarargs = false;
        if (context.isInvalidOverload(methSym) && !methSym.getParameters().isEmpty()
            && !Util.hasTypeParameters(methSym) && !Util.hasVarargs(methSym)
            && getParent(JCMethodDecl.class) != null
  print(".apply");
} else {
  if (inv.typeargs != null && !inv.typeargs.isEmpty()) {
    print("<");
    for (JCExpression argument : inv.typeargs) {
    if (methSym != null && !methSym.getTypeParameters().isEmpty()) {
        boolean inOverload = overload != null && overload.methods.size() > 1;
        if (!(inOverload && !overload.isValid)) {
          printAnyTypeArguments(methSym.getTypeParameters().size());
  if (inv.args.size() > 1) {
    print("[");
int argsLength = applyVarargs ? inv.args.size() - 1 : inv.args.size();
  JCExpression arg = inv.args.get(i);
  if (inv.meth.type != null) {

代码示例来源:origin: google/error-prone

/** Ignore some common ThreadLocal type arguments that are fine to have per-instance copies of. */
 private boolean wellKnownTypeArgument(NewClassTree tree, VisitorState state) {
  Type type = getType(tree);
  if (type == null) {
   return false;
  }
  type = state.getTypes().asSuper(type, state.getSymbolFromString("java.lang.ThreadLocal"));
  if (type == null) {
   return false;
  }
  if (type.getTypeArguments().isEmpty()) {
   return false;
  }
  Type argType = getOnlyElement(type.getTypeArguments());
  if (WELL_KNOWN_TYPES.contains(argType.asElement().getQualifiedName().toString())) {
   return true;
  }
  if (isSubtype(argType, state.getTypeFromString("java.text.DateFormat"), state)) {
   return true;
  }
  return false;
 }
}

代码示例来源:origin: cincheo/jsweet

String mappedType = context.getTypeMappingTarget(newClass.clazz.type.toString());
if (typeChecker.checkType(newClass, null, newClass.clazz)) {
  if (newClass.args.size() == 0 || !Util.hasVarargs(methSym) //
      || newClass.args.last().type.getKind() != TypeKind.ARRAY
      || !context.types.erasure(((ArrayType) newClass.args.last().type).elemtype).equals(
          context.types.erasure(((ArrayType) methSym.getParameters().last().type).elemtype))) {
    applyVarargs = false;
    for (int i = 0; i < newClass.args.length() - 1; i++) {
      print(", ").print(newClass.args.get(i));
    print("].concat(<any[]>").print(newClass.args.last()).print(")))");
  } else {
    if (newClass.clazz instanceof JCTypeApply) {
        print(typeApply.clazz);
      if (!typeApply.arguments.isEmpty()) {
        print("<").printTypeArgList(typeApply.arguments).print(">");
      } else {
        printAnyTypeArguments(((ClassSymbol) newClass.clazz.type.tsym).getTypeParameters().length());

代码示例来源:origin: cincheo/jsweet

public void visitNewClass(JCNewClass newClass) {
  ClassSymbol clazz = ((ClassSymbol) newClass.clazz.type.tsym);
  if (clazz.getSimpleName().toString().equals(JSweetConfig.GLOBALS_CLASS_NAME)) {
    report(newClass, JSweetProblem.GLOBAL_CANNOT_BE_INSTANTIATED);
    return;
  if (getScope().localClasses.stream().map(c -> c.type).anyMatch(t -> t.equals(newClass.type))) {
    print("new ").print(getScope().name + ".").print(newClass.clazz.toString());
    print("(").printConstructorArgList(newClass, true).print(")");
                if (invocationElement.getMethodName()
                    .equals(JSweetConfig.INDEXED_SET_FUCTION_NAME)) {
                  if (invocation.getArguments().size() == 3) {
                    if ("this".equals(invocation.getArguments().get(0).toString())) {
                      printIndent().print(invocation.args.tail.head).print(": ")
                          .print(invocation.args.tail.tail.head).print(",").println();
                print(param.getName() + ", ");
              if (!method.getParameters().isEmpty()) {
                removeLastChars(2);
                  .create(invocation);
              if (invocationElement.getMethodName().equals(JSweetConfig.INDEXED_SET_FUCTION_NAME)) {
                if (invocation.getArguments().size() == 3) {
                  if ("this".equals(invocation.getArguments().get(0).toString())) {
                    printIndent().print("target[").print(invocation.args.tail.head).print("]")
                        .print(" = ").print(invocation.args.tail.tail.head).print(";")

代码示例来源:origin: google/error-prone

private Optional<String> generateFix(
  MethodInvocationTree methodInvocation, boolean negated, VisitorState state) {
 String methodName = ASTHelpers.getSymbol(methodInvocation).getQualifiedName().toString();
 String hasMethod = methodName.replaceFirst("get", "has");
 // proto3 does not generate has methods for scalar types, e.g. ByteString and String.
 // Do not provide a replacement in these cases.
 Set<MethodSymbol> hasMethods =
   ASTHelpers.findMatchingMethods(
     state.getName(hasMethod),
     ms -> ms.params().isEmpty(),
     getType(getReceiver(methodInvocation)),
     state.getTypes());
 if (hasMethods.isEmpty()) {
  return Optional.empty();
 }
 String replacement = replaceLast(methodInvocation.toString(), methodName, hasMethod);
 return Optional.of(negated ? ("!" + replacement) : replacement);
}

代码示例来源:origin: google/error-prone

private static boolean knownNonNullMethod(
  MethodSymbol methodSymbol, ClassSymbol clazzSymbol, @Nullable Types types) {
 if (types == null) {
  return false;
 }
 // Proto getters are not null
 if (methodSymbol.name.toString().startsWith("get")
   && methodSymbol.params().isEmpty()
   && !methodSymbol.isStatic()) {
  Type type = clazzSymbol.type;
  while (type != null) {
   TypeSymbol typeSymbol = type.asElement();
   if (typeSymbol == null) {
    break;
   }
   if (typeSymbol
     .getQualifiedName()
     .contentEquals("com.google.protobuf.AbstractMessageLite")) {
    return true;
   }
   type = types.supertype(type);
  }
 }
 return false;
}

代码示例来源:origin: robolectric/robolectric

private JCMethodInvocation createSyntheticShadowAccess(VisitorState state) {
 TreeMaker treeMaker = state.getTreeMaker();
 JCExpression application =
   treeMaker.Select(
     treeMaker.Ident(findSymbol(state, "org.robolectric.RuntimeEnvironment")),
     findSymbol(state, "org.robolectric.RuntimeEnvironment", "application"));
 JCExpression shadowOfApp =
   treeMaker.Select(
     treeMaker.Ident(findSymbol(state, "org.robolectric.Shadows")),
     findSymbol(state, "org.robolectric.Shadows", "shadowOf(android.app.Application)"));
 JCMethodInvocation callShadowOf =
   treeMaker.Apply(null, shadowOfApp, com.sun.tools.javac.util.List.of(application));
 callShadowOf.type = callShadowOf.meth.type;
 return callShadowOf;
}

代码示例来源:origin: google/error-prone

Symtab symtab = state.getSymtab();
List<? extends ExpressionTree> args = invocation.getArguments();
switch (symbol.getSimpleName().toString()) {
 case "expect":
  Type type = ASTHelpers.getType(getOnlyElement(invocation.getArguments()));
   Type matcherType =
     state.getTypes().asSuper(type, state.getSymbolFromString("org.hamcrest.Matcher"));
   if (!matcherType.getTypeArguments().isEmpty()) {
    Type matchType = getOnlyElement(matcherType.getTypeArguments());
    if (isSubtype(matchType, symtab.throwableType, state)) {
     exceptionClassName = SuggestedFixes.qualifyType(state, fix, matchType);
 case "expectMessage":
  if (isSubtype(
    getOnlyElement(symbol.getParameters()).asType(), symtab.stringType, state)) {

代码示例来源:origin: cincheo/jsweet

return false;
if (assignedType.isInterface() && expression.type.tsym.isEnum()) {
  String relTarget = getRootRelativeName((Symbol) expression.type.tsym);
  print(relTarget).print("[\"" + Java2TypeScriptTranslator.ENUM_WRAPPER_CLASS_WRAPPERS + "\"][")
  return false;
if (assignedType.getTag() == TypeTag.CHAR && expression.type.getTag() != TypeTag.CHAR) {
  print("String.fromCharCode(").print(expression).print(")");
  return true;
            print("(");
            for (VarSymbol p : method.getParameters()) {
              print(p.getSimpleName().toString()).print(", ");
            if (!method.getParameters().isEmpty()) {
              removeLastChars(2);
            if (!method.getParameters().isEmpty()) {
              removeLastChars(2);
      if (!newClass.type.tsym.getTypeParameters().isEmpty() && newClass.typeargs.isEmpty()) {
        print("<any>(").print(expression).print(")");
        return true;

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/** Return all exceptions in thrown list that are not in handled list.
 *  @param thrown     The list of thrown exceptions.
 *  @param handled    The list of handled exceptions.
 */
List<Type> unhandled(List<Type> thrown, List<Type> handled) {
  List<Type> unhandled = List.nil();
  for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
    if (!isHandled(l.head, handled)) unhandled = unhandled.prepend(l.head);
  return unhandled;
}

代码示例来源:origin: uber/NullAway

private boolean thriftIsSetCall(Symbol.MethodSymbol symbol, Types types) {
  Preconditions.checkNotNull(tbaseType);
  // noinspection ConstantConditions
  return tbaseType.isPresent()
    && symbol.getSimpleName().toString().startsWith("isSet")
    // weeds out the isSet() method in TBase itself
    && symbol.getParameters().length() == 0
    && types.isSubtype(symbol.owner.type, tbaseType.get());
 }
}

代码示例来源:origin: google/error-prone

JCTree inlineBody(Inliner inliner) throws CouldNotResolveImportException {
 if (getBody() instanceof UPlaceholderExpression) {
  UPlaceholderExpression body = (UPlaceholderExpression) getBody();
  Optional<List<JCStatement>> blockBinding =
    inliner.getOptionalBinding(body.placeholder().blockKey());
  if (blockBinding.isPresent()) {
   // this lambda is of the form args -> blockPlaceholder();
   List<JCStatement> blockInlined =
     UPlaceholderExpression.copier(body.arguments(), inliner)
       .copy(blockBinding.get(), inliner);
   if (blockInlined.size() == 1) {
    if (blockInlined.get(0) instanceof JCReturn) {
     return ((JCReturn) blockInlined.get(0)).getExpression();
    } else if (blockInlined.get(0) instanceof JCExpressionStatement) {
     return ((JCExpressionStatement) blockInlined.get(0)).getExpression();
    }
   }
   return inliner.maker().Block(0, blockInlined);
  }
 }
 return getBody().inline(inliner);
}

代码示例来源:origin: cincheo/jsweet

if (((JCMethodDecl) member).sym.isConstructor()
    && ((JCMethodDecl) member).getModifiers().getFlags().contains(Modifier.PUBLIC)) {
  if (mainConstructor == null || mainConstructor.getParameters().size() < ((JCMethodDecl) member)
      .getParameters().size()) {
    mainConstructor = ((JCMethodDecl) member);
if(def instanceof JCVariableDecl) {
  JCVariableDecl var = (JCVariableDecl) def;
  if (var.sym.getModifiers() != null && var.sym.getModifiers().contains(Modifier.PUBLIC)
      && var.sym.getModifiers().contains(Modifier.STATIC)) {
    commentLines.add("@property {" + getMappedDocType(context, var.getType(), var.getType().type) + "} "
        + var.getName().toString());
    Comment varComment = compilationUnit.docComments.getComment(var);
    if(varComment!=null) {

相关文章