private static boolean isAnnotationOnType(Symbol sym, TypeAnnotationPosition position) { if (!position.location.isEmpty()) { return false; } switch (sym.getKind()) { case LOCAL_VARIABLE: return position.type == TargetType.LOCAL_VARIABLE; case FIELD: return position.type == TargetType.FIELD; case CONSTRUCTOR: case METHOD: return position.type == TargetType.METHOD_RETURN; case PARAMETER: switch (position.type) { case METHOD_FORMAL_PARAMETER: return ((MethodSymbol) sym.owner).getParameters().indexOf(sym) == position.parameter_index; default: return false; } case CLASS: // There are no type annotations on the top-level type of the class being declared, only // on other types in the signature (e.g. `class Foo extends Bar<@A Baz> {}`). return false; default: throw new AssertionError( "unsupported element kind in MoreAnnotation#isAnnotationOnType: " + sym.getKind()); } }
private static ImmutableList<SuggestedFix> buildUnusedParameterFixes( Symbol varSymbol, List<TreePath> usagePaths, VisitorState state) { MethodSymbol methodSymbol = (MethodSymbol) varSymbol.owner; int index = methodSymbol.params.indexOf(varSymbol); SuggestedFix.Builder fix = SuggestedFix.builder(); for (TreePath path : usagePaths) {
StringBuilder permutationString = new StringBuilder(); for (int i = 0; i < orderedCompilationUnits.size(); i++) { permutation[i] = compilationUnits.indexOf(orderedCompilationUnits.get(i)); permutationString.append("" + i + "=" + permutation[i] + ";");
@Override protected String capturedVarId(CapturedType t, Locale locale) { return "" + (allCaptured.indexOf(t) + 1); } @Override
@Override protected String capturedVarId(CapturedType t, Locale locale) { return "" + (allCaptured.indexOf(t) + 1); } @Override
@Override public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) { String name = annoType.getName(); // Declaration annotations on type variables are stored in type attributes // on the owner of the TypeVariableSymbol List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); int index = owner.getTypeParameters().indexOf(this); for (Attribute.TypeCompound anno : candidates) if (isCurrentSymbolsAnnotation(anno, index) && name.contentEquals(anno.type.tsym.flatName())) return anno; return null; } //where:
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
private static boolean isAnnotationOnType(Symbol sym, TypeAnnotationPosition position) { if (!position.location.isEmpty()) { return false; } switch (sym.getKind()) { case LOCAL_VARIABLE: return position.type == TargetType.LOCAL_VARIABLE; case FIELD: return position.type == TargetType.FIELD; case METHOD: return position.type == TargetType.METHOD_RETURN; case PARAMETER: switch (position.type) { case METHOD_FORMAL_PARAMETER: return ((MethodSymbol) sym.owner).getParameters().indexOf(sym) == position.parameter_index; default: return false; } default: throw new AssertionError(sym.getKind()); } }
@Override public List<Attribute.Compound> getAnnotationMirrors() { // Declaration annotations on type variables are stored in type attributes // on the owner of the TypeVariableSymbol List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); int index = owner.getTypeParameters().indexOf(this); List<Attribute.Compound> res = List.nil(); for (Attribute.TypeCompound a : candidates) { if (isCurrentSymbolsAnnotation(a, index)) res = res.prepend(a); } return res.reverse(); }
private static ImmutableList<SuggestedFix> buildUnusedParameterFixes( Symbol varSymbol, List<TreePath> usagePaths, VisitorState state) { MethodSymbol methodSymbol = (MethodSymbol) varSymbol.owner; int index = methodSymbol.params.indexOf(varSymbol); SuggestedFix.Builder fix = SuggestedFix.builder(); for (TreePath path : usagePaths) {
} else if (frameClassDecl.implementing.contains(tree)) { p.type = TargetType.CLASS_EXTENDS; p.type_index = frameClassDecl.implementing.indexOf(tree); } else { p.type_index = frameNewClass.typeargs.indexOf(tree); } else { p.type = TargetType.NEW; } else if (((JCClassDecl)frame).implementing.contains(tree)) { p.type = TargetType.CLASS_EXTENDS; p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree); } else if (((JCClassDecl)frame).typarams.contains(tree)) { p.type = TargetType.CLASS_TYPE_PARAMETER; p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree); } else { Assert.error("Could not determine position of tree " + tree + if (frameMethod.thrown.contains(tree)) { p.type = TargetType.THROWS; p.type_index = frameMethod.thrown.indexOf(tree); } else if (frameMethod.restype == tree) { p.type = TargetType.METHOD_RETURN; } else if (frameMethod.typarams.contains(tree)) { p.type = TargetType.METHOD_TYPE_PARAMETER; p.parameter_index = frameMethod.typarams.indexOf(tree); } else { Assert.error("Could not determine position of tree " + tree +
} else if (frameClassDecl.implementing.contains(tree)) { p.type = TargetType.CLASS_EXTENDS; p.type_index = frameClassDecl.implementing.indexOf(tree); } else { p.type_index = frameNewClass.typeargs.indexOf(tree); } else { p.type = TargetType.NEW; } else if (((JCClassDecl)frame).implementing.contains(tree)) { p.type = TargetType.CLASS_EXTENDS; p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree); } else if (((JCClassDecl)frame).typarams.contains(tree)) { p.type = TargetType.CLASS_TYPE_PARAMETER; p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree); } else { Assert.error("Could not determine position of tree " + tree + if (frameMethod.thrown.contains(tree)) { p.type = TargetType.THROWS; p.type_index = frameMethod.thrown.indexOf(tree); } else if (frameMethod.restype == tree) { p.type = TargetType.METHOD_RETURN; } else if (frameMethod.typarams.contains(tree)) { p.type = TargetType.METHOD_TYPE_PARAMETER; p.parameter_index = frameMethod.typarams.indexOf(tree); } else { Assert.error("Could not determine position of tree " + tree +
pos.type_index = -1; } else if (classdecl.implementing.contains(tree.clazz)) { pos.type_index = classdecl.implementing.indexOf(tree.clazz); } else {
pos.type_index = -1; } else if (classdecl.implementing.contains(tree.clazz)) { pos.type_index = classdecl.implementing.indexOf(tree.clazz); } else {