public ExpressionTree newAnnotatedParameterizedIdentifier( Optional<List<AnnotationTreeImpl>> annotations, InternalSyntaxToken identifierToken, Optional<TypeArgumentListTreeImpl> typeArguments) { List<AnnotationTree> annotationList = annotations.isPresent() ? ImmutableList.<AnnotationTree>builder().addAll(annotations.get()).build() : ImmutableList.<AnnotationTree>of(); ExpressionTree result = new IdentifierTreeImpl(identifierToken); if (typeArguments.isPresent()) { result = new ParameterizedTypeTreeImpl((TypeTree) result, typeArguments.get()).complete(annotationList); } else { result = ((IdentifierTreeImpl) result).complete(annotationList); } return result; }
private static void moveAnnotations(ExpressionTree result, ExpressionTree firstIdentifier) { List<AnnotationTree> firstIdentifierAnnotations; boolean isParameterizedType = firstIdentifier.is(Tree.Kind.PARAMETERIZED_TYPE); if (isParameterizedType) { firstIdentifierAnnotations = ((ParameterizedTypeTree) firstIdentifier).annotations(); } else { firstIdentifierAnnotations = ((IdentifierTree) firstIdentifier).annotations(); } // move the annotations from the first identifier to the member select or the parameterized type if (!firstIdentifierAnnotations.isEmpty()) { if (result.is(Tree.Kind.MEMBER_SELECT)) { ((MemberSelectExpressionTreeImpl) result).complete(firstIdentifierAnnotations); } else { ((ParameterizedTypeTreeImpl) result).complete(firstIdentifierAnnotations); } if (isParameterizedType) { ((ParameterizedTypeTreeImpl) firstIdentifier).complete(ImmutableList.<AnnotationTree>of()); } else { ((IdentifierTreeImpl) firstIdentifier).complete(ImmutableList.<AnnotationTree>of()); } } }
private static void completeTypeTreeWithAnnotations(TypeTree type, List<AnnotationTree> typeAnnotations) { if (type.is(Tree.Kind.IDENTIFIER)) { ((IdentifierTreeImpl) type).complete(typeAnnotations); } else if (type.is(Tree.Kind.MEMBER_SELECT)) { ((MemberSelectExpressionTreeImpl) type).complete(typeAnnotations); } else if (type.is(Tree.Kind.PARAMETERIZED_TYPE)) { ((ParameterizedTypeTreeImpl) type).complete(typeAnnotations); } else if (type.is(Kind.ARRAY_TYPE)) { ((ArrayTypeTreeImpl) type).complete(typeAnnotations); } else { ((PrimitiveTypeTreeImpl) type).complete(typeAnnotations); } } }