use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class DoubleCheckedLocking method findDCL.
/**
* Matches an instance of DCL. The canonical pattern is:
*
* <pre>{@code
* if ($X == null) {
* synchronized (...) {
* if ($X == null) {
* ...
* }
* ...
* }
* }
* }</pre>
*
* Gaps before the synchronized or inner 'if' statement are ignored, and the operands in the
* null-checks are accepted in either order.
*/
@Nullable
static DCLInfo findDCL(IfTree outerIf) {
// TODO(cushon): Optional.ifPresent...
ExpressionTree outerIfTest = getNullCheckedExpression(outerIf.getCondition());
if (outerIfTest == null) {
return null;
}
SynchronizedTree synchTree = getChild(outerIf.getThenStatement(), SynchronizedTree.class);
if (synchTree == null) {
return null;
}
IfTree innerIf = getChild(synchTree.getBlock(), IfTree.class);
if (innerIf == null) {
return null;
}
ExpressionTree innerIfTest = getNullCheckedExpression(innerIf.getCondition());
if (innerIfTest == null) {
return null;
}
Symbol outerSym = ASTHelpers.getSymbol(outerIfTest);
if (!Objects.equals(outerSym, ASTHelpers.getSymbol(innerIfTest))) {
return null;
}
if (!(outerSym instanceof VarSymbol)) {
return null;
}
VarSymbol var = (VarSymbol) outerSym;
return DCLInfo.create(outerIf, synchTree, innerIf, var);
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class EqualsReference method matchMethod.
@Override
public Description matchMethod(MethodTree methodTree, VisitorState visitorState) {
if (EQUALS_MATCHER.matches(methodTree, visitorState)) {
VariableTree variableTree = methodTree.getParameters().get(0);
VarSymbol varSymbol = ASTHelpers.getSymbol(variableTree);
TreeScannerEquals treeScannerEquals = new TreeScannerEquals(methodTree);
treeScannerEquals.scan(methodTree.getBody(), varSymbol);
if (treeScannerEquals.hasIllegalEquals) {
return describeMatch(methodTree);
}
}
return Description.NO_MATCH;
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class CatchFail method catchVariableIsUsed.
private boolean catchVariableIsUsed(CatchTree c) {
VarSymbol sym = ASTHelpers.getSymbol(c.getParameter());
boolean[] found = { false };
c.getBlock().accept(new TreeScanner<Void, Void>() {
@Override
public Void visitIdentifier(IdentifierTree node, Void aVoid) {
if (Objects.equals(sym, ASTHelpers.getSymbol(node))) {
found[0] = true;
}
return super.visitIdentifier(node, aVoid);
}
}, null);
return found[0];
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class HidingField method matchClass.
@Override
public Description matchClass(ClassTree classTree, VisitorState visitorState) {
List<VariableTree> originalClassMembers = classTree.getMembers().stream().filter(mem -> mem instanceof VariableTree).map(mem -> (VariableTree) mem).filter(mem -> !isSuppressed(ASTHelpers.getSymbol(mem)) && !isIgnoredType(mem) && !isStatic(mem)).collect(toCollection(ArrayList::new));
ClassSymbol classSymbol = ASTHelpers.getSymbol(classTree);
while (!Objects.equals(classSymbol.getSuperclass(), Type.noType)) {
TypeSymbol parentSymbol = classSymbol.getSuperclass().asElement();
List<Symbol> parentElements = parentSymbol.getEnclosedElements();
Map<Name, VarSymbol> parentMembers = parentElements.stream().filter(mem -> (mem instanceof VarSymbol)).map(mem -> (VarSymbol) mem).filter(mem -> (!mem.isPrivate() && !mem.getModifiers().contains(Modifier.STATIC))).collect(Collectors.toMap(Symbol::getSimpleName, mem -> mem));
checkForHiddenFields(originalClassMembers, parentMembers, parentSymbol.getSimpleName(), classTree, visitorState);
classSymbol = (ClassSymbol) parentSymbol;
}
return Description.NO_MATCH;
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class DateFormatConstant 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 (!isSubtype(getType(tree), state.getTypeFromString("java.text.DateFormat"), 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();
}
Aggregations