use of com.sun.tools.javac.code.Symbol.VarSymbol in project j2objc by google.
the class TreeConverter method convertVariableExpression.
private VariableDeclarationExpression convertVariableExpression(JCTree.JCVariableDecl node) {
VarSymbol var = node.sym;
boolean isVarargs = (node.sym.flags() & Flags.VARARGS) > 0;
Type newType = convertType(var.asType(), getPosition(node), isVarargs);
VariableDeclarationFragment fragment = new VariableDeclarationFragment();
fragment.setVariableElement(var).setInitializer((Expression) convert(node.getInitializer()));
return new VariableDeclarationExpression().setType(newType).addFragment(fragment);
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project j2objc by google.
the class TreeConverter method convertVariableDeclaration.
private TreeNode convertVariableDeclaration(JCTree.JCVariableDecl node) {
VarSymbol var = node.sym;
if (var.getKind() == ElementKind.FIELD) {
FieldDeclaration newNode = new FieldDeclaration(var, (Expression) convert(node.getInitializer()));
convertBodyDeclaration(node, node.getModifiers(), newNode, var);
return newNode;
}
if (var.getKind() == ElementKind.LOCAL_VARIABLE) {
return new VariableDeclarationStatement(var, (Expression) convert(node.getInitializer()));
}
if (var.getKind() == ElementKind.ENUM_CONSTANT) {
EnumConstantDeclaration newNode = new EnumConstantDeclaration().setVariableElement(var);
convertBodyDeclaration(node, node.getModifiers(), newNode, var);
ClassInstanceCreation init = (ClassInstanceCreation) convert(node.getInitializer());
TreeUtil.moveList(init.getArguments(), newNode.getArguments());
if (init.getAnonymousClassDeclaration() != null) {
newNode.setAnonymousClassDeclaration(TreeUtil.remove(init.getAnonymousClassDeclaration()));
}
return newNode.setExecutablePair(init.getExecutablePair()).setVarargsType(init.getVarargsType());
}
return convertSingleVariable(node);
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project j2objc by google.
the class TreeConverter method convertSingleVariable.
private TreeNode convertSingleVariable(JCTree.JCVariableDecl node) {
VarSymbol var = node.sym;
SourcePosition pos = getPosition(node);
boolean isVarargs = (node.sym.flags() & Flags.VARARGS) > 0;
Type newType = convertType(var.asType(), pos, isVarargs);
return new SingleVariableDeclaration().setType(newType).setIsVarargs(isVarargs).setAnnotations(convertAnnotations(node.getModifiers())).setVariableElement(var).setInitializer((Expression) convert(node.getInitializer()));
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class TryFailThrowable method hasInitialStringParameter.
private static boolean hasInitialStringParameter(MethodSymbol sym, VisitorState state) {
Types types = state.getTypes();
List<VarSymbol> parameters = sym.getParameters();
return !parameters.isEmpty() && types.isSameType(parameters.get(0).type, state.getSymtab().stringType);
}
use of com.sun.tools.javac.code.Symbol.VarSymbol in project error-prone by google.
the class TypeParameterUnusedInFormals method matchMethod.
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
if (methodSymbol == null) {
return Description.NO_MATCH;
}
// Only match methods where the return type is just a type parameter.
// e.g. the following is OK: <T> List<T> newArrayList();
TypeVar retType;
switch(methodSymbol.getReturnType().getKind()) {
case TYPEVAR:
retType = (TypeVar) methodSymbol.getReturnType();
break;
default:
return Description.NO_MATCH;
}
if (!methodSymbol.equals(retType.tsym.owner)) {
return Description.NO_MATCH;
}
// e.g.: <T extends Enum<T>> T unsafeEnumDeserializer();
if (retType.bound != null && TypeParameterFinder.visit(retType.bound).contains(retType.tsym)) {
return Description.NO_MATCH;
}
// e.g.: <T> T noop(T t);
for (VarSymbol formalParam : methodSymbol.getParameters()) {
if (TypeParameterFinder.visit(formalParam.type).contains(retType.tsym)) {
return Description.NO_MATCH;
}
}
return describeMatch(tree);
}
Aggregations