use of com.sun.tools.javac.code.Symbol.VarSymbol in project ceylon-compiler by ceylon.
the class JavacMethod method getParameters.
@Override
public List<VariableMirror> getParameters() {
if (parameters == null) {
com.sun.tools.javac.util.List<VarSymbol> params = methodSymbol.getParameters();
List<VariableMirror> ret = new ArrayList<VariableMirror>(params.size());
for (VarSymbol parameter : params) ret.add(new JavacVariable(parameter));
parameters = Collections.unmodifiableList(ret);
}
return parameters;
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project bazel by bazelbuild.
the class AnnotationUtils method getElementValueEnum.
/**
* Version that is suitable for Enum elements.
*/
public static <T extends Enum<T>> T getElementValueEnum(AnnotationMirror anno, CharSequence name, Class<T> t, boolean useDefaults) {
VarSymbol vs = getElementValue(anno, name, VarSymbol.class, useDefaults);
T value = Enum.valueOf(t, vs.getSimpleName().toString());
return value;
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class ASTHelpers method enumValues.
/** @return all values of the given enum type, in declaration order. */
public static LinkedHashSet<String> enumValues(TypeSymbol enumType) {
if (enumType.getKind() != ElementKind.ENUM) {
throw new IllegalStateException();
}
Scope scope = enumType.members();
Deque<String> values = new ArrayDeque<>();
for (Symbol sym : scope.getSymbols()) {
if (sym instanceof VarSymbol) {
VarSymbol var = (VarSymbol) sym;
if ((var.flags() & Flags.ENUM) != 0) {
/**
* Javac gives us the members backwards, apparently. It's worth making an effort to
* preserve declaration order because it's useful for diagnostics (e.g. in
* {@link MissingCasesInEnumSwitch}).
*/
values.push(sym.name.toString());
}
}
}
return new LinkedHashSet<>(values);
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class SimpleDateFormatConstant method matchVariable.
@Override
public Description matchVariable(VariableTree tree, VisitorState state) {
if (tree.getInitializer() == null) {
return NO_MATCH;
}
VarSymbol sym = ASTHelpers.getSymbol(tree);
if (sym == null || sym.getKind() != ElementKind.FIELD) {
return NO_MATCH;
}
String name = sym.getSimpleName().toString();
if (!(sym.isStatic() && sym.getModifiers().contains(Modifier.FINAL))) {
return NO_MATCH;
}
if (!name.equals(name.toUpperCase())) {
return NO_MATCH;
}
if (!isSameType(getType(tree), state.getTypeFromString("java.text.SimpleDateFormat"), state)) {
return NO_MATCH;
}
return buildDescription(tree).addFix(threadLocalFix(tree, state, sym)).addFix(renameVariable(tree, CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tree.getName().toString()), state)).build();
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class FormatStringAnnotationChecker method matchMethod.
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
Type stringType = state.getSymtab().stringType;
boolean isFormatMethod = ASTHelpers.hasAnnotation(ASTHelpers.getSymbol(tree), FormatMethod.class, state);
boolean foundFormatString = false;
boolean foundString = false;
for (VariableTree param : tree.getParameters()) {
VarSymbol paramSymbol = ASTHelpers.getSymbol(param);
boolean isStringParam = ASTHelpers.isSameType(paramSymbol.type, stringType, state);
if (isStringParam) {
foundString = true;
}
if (ASTHelpers.hasAnnotation(paramSymbol, FormatString.class, state)) {
if (!isFormatMethod) {
return buildDescription(tree).setMessage("A parameter can only be annotated @FormatString in a method annotated " + "@FormatMethod: " + param).build();
}
if (!isStringParam) {
return buildDescription(param).setMessage("Only strings can be annotated @FormatString.").build();
}
if (foundFormatString) {
return buildDescription(tree).setMessage("A method cannot have more than one @FormatString parameter.").build();
}
foundFormatString = true;
}
}
if (isFormatMethod && !foundString) {
return buildDescription(tree).setMessage("An @FormatMethod must contain at least one String parameter.").build();
}
return Description.NO_MATCH;
}
Aggregations