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 TypeAnnotationPosition(final TargetType ttype, final int pos, final int parameter_index, final JCLambda onLambda, final int type_index, final int bound_index, final List<TypePathEntry> location) { Assert.checkNonNull(location); this.type = ttype; this.pos = pos; this.parameter_index = parameter_index; this.onLambda = onLambda; this.type_index = type_index; this.bound_index = bound_index; this.location = location; }
public static TypeAnnotationPosition methodThrowsTAPosition(SourceVersion ver, final int tidx, final int pos) { return call8or9(ver, new TAPCall() { @Override public TypeAnnotationPosition call8(Object ... p) throws InstantiationException, IllegalAccessException, IllegalArgumentException, NoSuchFieldException, SecurityException { TypeAnnotationPosition tapos = TypeAnnotationPosition.class.newInstance(); TypeAnnotationPosition.class.getField("type").set(tapos, TargetType.THROWS); TypeAnnotationPosition.class.getField("type_index").set(tapos, tidx); TypeAnnotationPosition.class.getField("pos").set(tapos, pos); return tapos; } @Override public TypeAnnotationPosition call9(Object... param) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException { return (TypeAnnotationPosition) TypeAnnotationPosition.class .getMethod("methodThrows", List.class, JCLambda.class, int.class, int.class) .invoke(null, TypeAnnotationPosition.class.getField("emptyPath").get(null), null, tidx, pos); } } ); }
public static TypeAnnotationPosition typeParameterTAPosition(SourceVersion ver, final int tpidx, final int pos) { return call8or9(ver, new TAPCall() { @Override public TypeAnnotationPosition call8(Object ... p) throws InstantiationException, IllegalAccessException, IllegalArgumentException, NoSuchFieldException, SecurityException { TypeAnnotationPosition tapos = TypeAnnotationPosition.class.newInstance(); TypeAnnotationPosition.class.getField("type").set(tapos, TargetType.CLASS_TYPE_PARAMETER); TypeAnnotationPosition.class.getField("parameter_index").set(tapos, tpidx); TypeAnnotationPosition.class.getField("pos").set(tapos, pos); return tapos; } @Override public TypeAnnotationPosition call9(Object... param) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException { return (TypeAnnotationPosition) TypeAnnotationPosition.class .getMethod("typeParameter", List.class, JCLambda.class, int.class, int.class) .invoke(null, TypeAnnotationPosition.class.getField("emptyPath").get(null), null, tpidx, pos); } } ); }
public static TypeAnnotationPosition methodTypeParameterTAPosition(SourceVersion ver, final int tpidx, final int pos) { return call8or9(ver, new TAPCall() { @Override public TypeAnnotationPosition call8(Object ... p) throws InstantiationException, IllegalAccessException, IllegalArgumentException, NoSuchFieldException, SecurityException { TypeAnnotationPosition tapos = TypeAnnotationPosition.class.newInstance(); TypeAnnotationPosition.class.getField("type").set(tapos, TargetType.METHOD_TYPE_PARAMETER); TypeAnnotationPosition.class.getField("parameter_index").set(tapos, tpidx); TypeAnnotationPosition.class.getField("pos").set(tapos, pos); return tapos; } @Override public TypeAnnotationPosition call9(Object... param) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException { return (TypeAnnotationPosition) TypeAnnotationPosition.class .getMethod("methodTypeParameter", List.class, JCLambda.class, int.class, int.class) .invoke(null, TypeAnnotationPosition.class.getField("emptyPath").get(null), null, tpidx, pos); } } ); }
public static TypeAnnotationPosition typeParameterBoundTAPosition(SourceVersion ver, final int tpidx, final int bndidx, final int pos) { return call8or9(ver, new TAPCall() { @Override public TypeAnnotationPosition call8(Object ... p) throws InstantiationException, IllegalAccessException, IllegalArgumentException, NoSuchFieldException, SecurityException { TypeAnnotationPosition tapos = TypeAnnotationPosition.class.newInstance(); TypeAnnotationPosition.class.getField("type").set(tapos, TargetType.CLASS_TYPE_PARAMETER_BOUND); TypeAnnotationPosition.class.getField("parameter_index").set(tapos, tpidx); TypeAnnotationPosition.class.getField("bound_index").set(tapos, bndidx); TypeAnnotationPosition.class.getField("pos").set(tapos, pos); return tapos; } @Override public TypeAnnotationPosition call9(Object... param) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException { return (TypeAnnotationPosition) TypeAnnotationPosition.class .getMethod("typeParameterBound", List.class, JCLambda.class, int.class, int.class, int.class) .invoke(null, TypeAnnotationPosition.class.getField("emptyPath").get(null), null, tpidx, bndidx, pos); } } ); }
public static TypeAnnotationPosition methodTypeParameterBoundTAPosition(SourceVersion ver, final int tpidx, final int bndidx, final int pos) { return call8or9(ver, new TAPCall() { @Override public TypeAnnotationPosition call8(Object ... p) throws InstantiationException, IllegalAccessException, IllegalArgumentException, NoSuchFieldException, SecurityException { TypeAnnotationPosition tapos = TypeAnnotationPosition.class.newInstance(); TypeAnnotationPosition.class.getField("type").set(tapos, TargetType.METHOD_TYPE_PARAMETER_BOUND); TypeAnnotationPosition.class.getField("parameter_index").set(tapos, tpidx); TypeAnnotationPosition.class.getField("bound_index").set(tapos, bndidx); TypeAnnotationPosition.class.getField("pos").set(tapos, pos); return tapos; } @Override public TypeAnnotationPosition call9(Object... param) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException { return (TypeAnnotationPosition) TypeAnnotationPosition.class .getMethod("methodTypeParameterBound", List.class, JCLambda.class, int.class, int.class, int.class) .invoke(null, TypeAnnotationPosition.class.getField("emptyPath").get(null), null, tpidx, bndidx, pos); } } ); }
public void visitLambda(JCLambda tree) { JCLambda prevLambda = currentLambda; try { currentLambda = tree; int i = 0; for (JCVariableDecl param : tree.params) { if (!param.mods.annotations.isEmpty()) { // Nothing to do for separateAnnotationsKinds if // there are no annotations of either kind. TypeAnnotationPosition pos = new TypeAnnotationPosition(); pos.type = TargetType.METHOD_FORMAL_PARAMETER; pos.parameter_index = i; pos.pos = param.vartype.pos; pos.onLambda = tree; separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); } ++i; } push(tree); scan(tree.body); scan(tree.params); pop(); } finally { currentLambda = prevLambda; } }
boolean isSimpleStringArg(JCExpression e) { switch (e.getTag()) { case LAMBDA: JCLambda lambda = (JCLambda)e; return (lambda.getBodyKind() == BodyKind.EXPRESSION) && isSimpleStringArg((JCExpression)lambda.body); default: Symbol argSym = TreeInfo.symbolFor(e); return (e.type.constValue() != null || (argSym != null && argSym.kind == Kinds.Kind.VAR)); } }
public void visitLambda(JCLambda tree) { JCLambda prevLambda = currentLambda; try { currentLambda = tree; int i = 0; for (JCVariableDecl param : tree.params) { if (!param.mods.annotations.isEmpty()) { // Nothing to do for separateAnnotationsKinds if // there are no annotations of either kind. final TypeAnnotationPosition pos = TypeAnnotationPosition .methodParameter(tree, i, param.vartype.pos); push(param); try { separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); } finally { pop(); } } ++i; } scan(tree.body); scan(tree.params); } finally { currentLambda = prevLambda; } }
/** * Create a {@code TypeAnnotationPosition} for a method return. * * @param location The type path. * @param onLambda The lambda for this parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodReturn(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_RETURN, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a method receiver parameter. * * @param location The type path. * @param onLambda The lambda for this parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodReceiver(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_RECEIVER, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a method formal parameter. * * @param location The type path. * @param onLambda The lambda for this parameter. * @param parameter_index The index of the parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodParameter(final List<TypePathEntry> location, final JCLambda onLambda, final int parameter_index, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_FORMAL_PARAMETER, pos, parameter_index, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a method formal parameter. * * @param onLambda The lambda for this parameter. * @param parameter_index The index of the parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodParameter(final JCLambda onLambda, final int parameter_index, final int pos) { return methodParameter(emptyPath, onLambda, parameter_index, pos); }
/** * Create a {@code TypeAnnotationPosition} for a method reference. * * @param location The type path. * @param onLambda The lambda for this method reference. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodRef(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_REFERENCE, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a constructor reference. * * @param location The type path. * @param onLambda The lambda for this constructor reference. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition constructorRef(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.CONSTRUCTOR_REFERENCE, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a field. * * @param location The type path. * @param onLambda The lambda for this variable. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition field(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.FIELD, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a local variable. * * @param location The type path. * @param onLambda The lambda for this variable. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition localVariable(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.LOCAL_VARIABLE, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for an exception parameter. * * @param location The type path. * @param onLambda The lambda for this parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition exceptionParameter(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.EXCEPTION_PARAMETER, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a resource variable. * * @param location The type path. * @param onLambda The lambda for this variable. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition resourceVariable(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.RESOURCE_VARIABLE, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a new. * * @param location The type path. * @param onLambda The lambda for this variable. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition newObj(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.NEW, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a class extension. * * @param location The type path. * @param onLambda The lambda for this variable. * @param type_index The index of the interface. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition classExtends(final List<TypePathEntry> location, final JCLambda onLambda, final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.CLASS_EXTENDS, pos, Integer.MIN_VALUE, onLambda, type_index, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for an instanceof. * * @param location The type path. * @param onLambda The lambda for this variable. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition instanceOf(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.INSTANCEOF, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a type cast. * * @param location The type path. * @param onLambda The lambda for this variable. * @param type_index The index into an intersection type. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition typeCast(final List<TypePathEntry> location, final JCLambda onLambda, final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.CAST, pos, Integer.MIN_VALUE, onLambda, type_index, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a method * invocation type argument. * * @param location The type path. * @param onLambda The lambda for this variable. * @param type_index The index of the type argument. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodInvocationTypeArg(final List<TypePathEntry> location, final JCLambda onLambda, final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_INVOCATION_TYPE_ARGUMENT, pos, Integer.MIN_VALUE, onLambda, type_index, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a constructor * invocation type argument. * * @param location The type path. * @param onLambda The lambda for this variable. * @param type_index The index of the type argument. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition constructorInvocationTypeArg(final List<TypePathEntry> location, final JCLambda onLambda, final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, pos, Integer.MIN_VALUE, onLambda, type_index, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a type parameter. * * @param location The type path. * @param onLambda The lambda for this variable. * @param parameter_index The index of the type parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition typeParameter(final List<TypePathEntry> location, final JCLambda onLambda, final int parameter_index, final int pos) { return new TypeAnnotationPosition(TargetType.CLASS_TYPE_PARAMETER, pos, parameter_index, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a method type parameter. * * @param location The type path. * @param onLambda The lambda for this variable. * @param parameter_index The index of the type parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodTypeParameter(final List<TypePathEntry> location, final JCLambda onLambda, final int parameter_index, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_TYPE_PARAMETER, pos, parameter_index, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a throws clause. * * @param location The type path. * @param onLambda The lambda for this variable. * @param type_index The index of the exception. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodThrows(final List<TypePathEntry> location, final JCLambda onLambda, final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.THROWS, pos, Integer.MIN_VALUE, onLambda, type_index, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a method reference * type argument. * * @param location The type path. * @param onLambda The lambda for this variable. * @param type_index The index of the type argument. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodRefTypeArg(final List<TypePathEntry> location, final JCLambda onLambda, final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_REFERENCE_TYPE_ARGUMENT, pos, Integer.MIN_VALUE, onLambda, type_index, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a constructor reference * type argument. * * @param location The type path. * @param onLambda The lambda for this variable. * @param type_index The index of the type argument. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition constructorRefTypeArg(final List<TypePathEntry> location, final JCLambda onLambda, final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, pos, Integer.MIN_VALUE, onLambda, type_index, Integer.MIN_VALUE, location); }
/** * Create a {@code TypeAnnotationPosition} for a type parameter bound. * * @param location The type path. * @param onLambda The lambda for this variable. * @param parameter_index The index of the type parameter. * @param bound_index The index of the type parameter bound. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition typeParameterBound(final List<TypePathEntry> location, final JCLambda onLambda, final int parameter_index, final int bound_index, final int pos) { return new TypeAnnotationPosition(TargetType.CLASS_TYPE_PARAMETER_BOUND, pos, parameter_index, onLambda, Integer.MIN_VALUE, bound_index, location); }
/** * Create a {@code TypeAnnotationPosition} for a method type * parameter bound. * * @param location The type path. * @param onLambda The lambda for this variable. * @param parameter_index The index of the type parameter. * @param bound_index The index of the type parameter bound. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodTypeParameterBound(final List<TypePathEntry> location, final JCLambda onLambda, final int parameter_index, final int bound_index, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_TYPE_PARAMETER_BOUND, pos, parameter_index, onLambda, Integer.MIN_VALUE, bound_index, location); }