本文整理汇总了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('}');
}
示例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;
}
}
}
示例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;
}
示例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());
}
}
示例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());
}
}
示例6: visitArray
import com.sun.tools.javac.code.Attribute; //导入方法依赖的package包/类
public void visitArray(Attribute.Array a) {
printList("values", Arrays.asList(a.values));
visitAttribute(a);
}
示例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());
}
}
示例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);
}
示例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);
}