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


Java Attribute.Array方法代码示例

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


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

示例1: visitArray

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
public void visitArray(Attribute.Array a) {
    // Omit braces from singleton.
    if (a.values.length != 1) sb.append('{');

    boolean first = true;
    for (Attribute elem : a.values) {
        if (first) {
            first = false;
        } else {
            sb.append(", ");
        }
        elem.accept(this);
    }
    // Omit braces from singleton.
    if (a.values.length != 1) sb.append('}');
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:AnnotationValueImpl.java

示例2: visitArray

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
public void visitArray(Attribute.Array a) {
    Name elemName = ((ArrayType) a.type).elemtype.tsym.getQualifiedName();

    if (elemName.equals(elemName.table.names.java_lang_Class)) {   // Class[]
        // Construct a proxy for a MirroredTypesException
        ListBuffer<TypeMirror> elems = new ListBuffer<TypeMirror>();
        for (Attribute value : a.values) {
            Type elem = ((Attribute.Class) value).type;
            elems.append(elem);
        }
        value = new MirroredTypesExceptionProxy(elems.toList());

    } else {
        int len = a.values.length;
        Class<?> returnClassSaved = returnClass;
        returnClass = returnClass.getComponentType();
        try {
            Object res = Array.newInstance(returnClass, len);
            for (int i = 0; i < len; i++) {
                a.values[i].accept(this);
                if (value == null || value instanceof ExceptionProxy) {
                    return;
                }
                try {
                    Array.set(res, i, value);
                } catch (IllegalArgumentException e) {
                    value = null;       // indicates a type mismatch
                    return;
                }
            }
            value = res;
        } finally {
            returnClass = returnClassSaved;
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:37,代码来源:AnnotationProxyMaker.java

示例3: visitArray

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
public void visitArray(Attribute.Array a) {
    ArrayList<AnnotationValue> vals =
        new ArrayList<AnnotationValue>(a.values.length);
    for (Attribute elem : a.values) {
        vals.add(new AnnotationValueImpl(env, elem, annotation));
    }
    value = vals;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:9,代码来源:AnnotationValueImpl.java

示例4: visitArray

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
@Override
public Attribute visitArray(java.util.List<? extends AnnotationValue> vals, Void p) {
    if (!vals.isEmpty()) {
        List<Attribute> valAttrs = List.nil();
        for (AnnotationValue av : vals) {
            valAttrs = valAttrs.append(av.accept(this, p));
        }
        ArrayType arrayType = modelTypes.getArrayType(valAttrs.get(0).type);
        return new Attribute.Array((Type)arrayType, valAttrs);
    } else {
        return new Attribute.Array((Type) meth.getReturnType(), List.<Attribute>nil());
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:14,代码来源:TypeAnnotationUtils.java

示例5: visitArray

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
@Override
public Attribute visitArray(java.util.List<? extends AnnotationValue> vals, Void p) {
    if (!vals.isEmpty()) {
        List<Attribute> valAttrs = List.nil();
        for (AnnotationValue av : vals) {
            valAttrs = valAttrs.append(av.accept(this, p));
        }
        ArrayType arrayType = modelTypes.getArrayType(valAttrs.get(0).type);
        return new Attribute.Array((Type) arrayType, valAttrs);
    } else {
        return new Attribute.Array((Type) meth.getReturnType(), List.<Attribute>nil());
    }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:14,代码来源:TypeAnnotationUtils.java

示例6: visitArray

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
public void visitArray(Attribute.Array a) {
    printList("values", Arrays.asList(a.values));
    visitAttribute(a);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:DPrinter.java

示例7: generate

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
public void generate() {

        final String proxyClassName = String.format("MicroDB%s", mClassName);
        PackageElement packageName = mEnv.getElementUtils().getPackageOf(mClassElement);
        final String fqClassName = String.format("%s.%s", packageName, proxyClassName);

        try {

            TypeSpec.Builder classBuilder = TypeSpec.classBuilder(proxyClassName)
                    .superclass(TypeName.get(mClassElement.asType()))
                    .addModifiers(Modifier.PUBLIC);

            classBuilder.addField(MicroDB.class, "mDb", Modifier.PRIVATE, Modifier.FINAL);

            classBuilder.addMethod(MethodSpec.constructorBuilder()
                    .addModifiers(Modifier.PUBLIC)
                    .addParameter(MicroDB.class, "db")
                    .addCode(CodeBlock.builder().addStatement("mDb = db").build())
                    .build());

            AnnotationMirror am = getAnnotationMirror(mClassElement, DataSet.class);
            Attribute.Array array = (Attribute.Array) getAnnotationValue(am, "objects");
            for(Attribute attribute : array.getValue()) {
                note("visiting object: " + attribute);
                DeclaredType type = (DeclaredType) attribute.getValue();
                visitObjectTypes(classBuilder, type);
            }


            generateInstallMethod(classBuilder);

            for(GenCode genCode : mCodeGen) {
                if(genCode instanceof IndexGenCode) {
                    classBuilder.addMethod(((IndexGenCode) genCode).genQueryIndex());
                }
            }


            JavaFile proxySourceFile = JavaFile.builder(packageName.toString(), classBuilder.build())
                    .skipJavaLangImports(true)
                    .build();

            JavaFileObject sourceFile = mEnv.getFiler().createSourceFile(fqClassName);
            Writer writer = sourceFile.openWriter();
            proxySourceFile.writeTo(writer);
            writer.close();

        } catch (IOException e) {
            error("error generating proxy class: " + e.getMessage());
        }

    }
 
开发者ID:dinocore1,项目名称:MicroDb,代码行数:53,代码来源:DatasetGenerator.java

示例8: extendSuppressionSets

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
/**
 * Extend suppression sets for both {@code @SuppressWarnings} and custom suppression annotations.
 * When we explore a new node, we have to extend the suppression sets with any new suppressed
 * warnings or custom suppression annotations. We also have to retain the previous suppression set
 * so that we can reinstate it when we move up the tree.
 *
 * <p>We do not modify the existing suppression sets, so they can be restored when moving up the
 * tree. We also avoid copying the suppression sets if the next node to explore does not have any
 * suppressed warnings or custom suppression annotations. This is the common case.
 *
 * @param sym The {@code Symbol} for the AST node currently being scanned
 * @param suppressWarningsType The {@code Type} for {@code @SuppressWarnings}, as given by javac's
 *     symbol table
 * @param suppressionsOnCurrentPath The set of strings in all {@code @SuppressWarnings}
 *     annotations on the current path through the AST
 * @param customSuppressionsOnCurrentPath The set of all custom suppression annotations
 */
public SuppressionInfo extendSuppressionSets(
    Symbol sym,
    Type suppressWarningsType,
    Set<String> suppressionsOnCurrentPath,
    Set<Class<? extends Annotation>> customSuppressionsOnCurrentPath,
    boolean inGeneratedCode,
    VisitorState state) {

  boolean newInGeneratedCode = inGeneratedCode || isGenerated(sym, state);

  /** Handle custom suppression annotations. */
  Set<Class<? extends Annotation>> newCustomSuppressions = null;
  for (Class<? extends Annotation> annotationType : customSuppressionAnnotations) {
    if (ASTHelpers.hasAnnotation(sym, annotationType, state)) {
      if (newCustomSuppressions == null) {
        newCustomSuppressions = new HashSet<>(customSuppressionsOnCurrentPath);
      }
      newCustomSuppressions.add(annotationType);
    }
  }

  /** Handle {@code @SuppressWarnings} and {@code @SuppressLint}. */
  Set<String> newSuppressions = null;
  // Iterate over annotations on this symbol, looking for SuppressWarnings
  for (Attribute.Compound attr : sym.getAnnotationMirrors()) {
    if ((attr.type.tsym == suppressWarningsType.tsym)
        || attr.type.tsym.getQualifiedName().contentEquals("android.annotation.SuppressLint")) {
      for (Pair<MethodSymbol, Attribute> value : attr.values) {
        if (value.fst.name.contentEquals("value"))
          if (value.snd
              instanceof Attribute.Array) { // SuppressWarnings/SuppressLint take an array
            for (Attribute suppress : ((Attribute.Array) value.snd).values) {
              if (newSuppressions == null) {
                newSuppressions = new HashSet<>(suppressionsOnCurrentPath);
              }
              // TODO(eaftan): check return value to see if this was a new warning?
              newSuppressions.add((String) suppress.getValue());
            }
          } else {
            throw new RuntimeException(
                "Expected SuppressWarnings/SuppressLint annotation to take array type");
          }
      }
    }
  }

  return new SuppressionInfo(newSuppressions, newCustomSuppressions, newInGeneratedCode);
}
 
开发者ID:google,项目名称:error-prone,代码行数:66,代码来源:SuppressionHelper.java

示例9: extendSuppressionSets

import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
/**
 * Extend suppression sets for both {@code @SuppressWarnings} and custom suppression annotations.
 * When we explore a new node, we have to extend the suppression sets with any new suppressed
 * warnings or custom suppression annotations.  We also have to retain the previous suppression
 * set so that we can reinstate it when we move up the tree.
 *
 * We do not modify the existing suppression sets, so they can be restored when moving up the
 * tree.  We also avoid copying the suppression sets if the next node to explore does not have
 * any suppressed warnings or custom suppression annotations.  This is the common case.
 *
 * @param sym The {@code Symbol} for the AST node currently being scanned
 * @param suppressWarningsType The {@code Type} for {@code @SuppressWarnings}, as given by
 *        javac's symbol table
 * @param suppressionsOnCurrentPath The set of strings in all {@code @SuppressWarnings}
 *        annotations on the current path through the AST
 * @param customSuppressionsOnCurrentPath The set of all custom suppression annotations
 *        on the current path through the AST
 */
public NewSuppressions extendSuppressionSets(Symbol sym,
    Type suppressWarningsType,
    Set<String> suppressionsOnCurrentPath,
    Set<Class<? extends Annotation>> customSuppressionsOnCurrentPath) {

  /**
   * Handle custom suppression annotations.
   */
  Set<Class<? extends Annotation>> newCustomSuppressions = null;
  for (Class<? extends Annotation> annotationType : customSuppressionAnnotations) {
    if (ASTHelpers.hasAnnotation(sym, annotationType)) {
      if (newCustomSuppressions == null) {
        newCustomSuppressions = new HashSet<Class<? extends Annotation>>(customSuppressionsOnCurrentPath);
      }
      newCustomSuppressions.add(annotationType);
    }
  }

  /**
   * Handle @SuppressWarnings.
   */
  Set<String> newSuppressions = null;
  // Iterate over annotations on this symbol, looking for SuppressWarnings
  for (Attribute.Compound attr : sym.getAnnotationMirrors()) {
    // TODO(eaftan): use JavacElements.getAnnotation instead
    if (attr.type.tsym == suppressWarningsType.tsym) {
      for (List<Pair<MethodSymbol,Attribute>> v = attr.values;
          v.nonEmpty(); v = v.tail) {
        Pair<MethodSymbol,Attribute> value = v.head;
        if (value.fst.name.toString().equals("value"))
          if (value.snd instanceof Attribute.Array) {  // SuppressWarnings takes an array
            for (Attribute suppress : ((Attribute.Array) value.snd).values) {
              if (newSuppressions == null) {
                newSuppressions = new HashSet<String>(suppressionsOnCurrentPath);
              }
              // TODO(eaftan): check return value to see if this was a new warning?
              newSuppressions.add((String) suppress.getValue());
            }
          } else {
            throw new RuntimeException("Expected SuppressWarnings annotation to take array type");
          }
      }
    }
  }

  return new NewSuppressions(newSuppressions, newCustomSuppressions);
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:66,代码来源:SuppressionHelper.java


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