if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) { org.eclipse.jdt.core.dom.Annotation annotation = (org.eclipse.jdt.core.dom.Annotation)modifier; String qualifiedAnnotationName = annotation.resolveTypeBinding().getQualifiedName(); if (!"java.lang.Override".equals(qualifiedAnnotationName) && !"java.lang.SuppressWarnings".equals(qualifiedAnnotationName)) annotations.add(annotation);
@Override public String toString() { return annotation.toString(); }
if (annotation.isSingleMemberAnnotation()) { org.eclipse.jdt.core.dom.SingleMemberAnnotation smAnn = (org.eclipse.jdt.core.dom.SingleMemberAnnotation) annotation; values.add(smAnn.getValue().toString()); } else if (annotation.isNormalAnnotation()) { org.eclipse.jdt.core.dom.NormalAnnotation normalAnn = (org.eclipse.jdt.core.dom.NormalAnnotation) annotation; for (Object value : normalAnn.values()) values.add(value.toString()); signature.append("@").append(annotation.resolveTypeBinding().getQualifiedName()); if (!values.isEmpty()) { signature.append("(");
@Override public String getName() { return annotation.getTypeName().getFullyQualifiedName(); }
protected ASTRewrite getRewrite() throws CoreException { AST ast= fAnnotation.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); createImportRewrite((CompilationUnit) fAnnotation.getRoot()); ListRewrite listRewrite; if (fAnnotation instanceof NormalAnnotation) { listRewrite= rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY); } else { NormalAnnotation newAnnotation= ast.newNormalAnnotation(); newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName())); rewrite.replace(fAnnotation, newAnnotation, null); listRewrite= rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY); } addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite); return rewrite; }
private void handleAnnotation(Annotation node) { ASTNode parentNode = node.getParent(); boolean breakAfter = false; boolean isTypeAnnotation = this.declarationModifierVisited; int lParen = this.tm.firstIndexAfter(node.getTypeName(), TokenNameLPAREN); int rParen = this.tm.lastIndexIn(node, TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_annotation);
private AnnotationClassReference processAnnotation(ClassReference annotatedReference, Annotation node) final ITypeBinding typeBinding = node.resolveTypeBinding(); final AnnotationClassReference reference; final String qualifiedName; ResolveClassnameResult result = resolveClassname(node.getTypeName().toString()); status = result.found ? ResolutionStatus.RECOVERED : ResolutionStatus.UNRESOLVED; qualifiedName = result.result; className, status, compilationUnit.getLineNumber(node.getStartPosition()), compilationUnit.getColumnNumber(node.getStartPosition()), node.getLength(), node.toString());
@Override public AnnotationSource<O> setName(final String className) { annotation.setTypeName(ast.newName(className)); return this; }
private void rewriteAnnotationsOnDimension(ArrayType oldArrayType, ArrayType replacingType, int index, int pos, boolean typeReplaced, TextEditGroup editGroup) throws CoreException { if (typeReplaced) { List dimensions = oldArrayType.dimensions(); Dimension oldDim = index < dimensions.size() ? (Dimension) dimensions.get(index) : null; if (oldDim != null) { List oldAnnotations = oldDim.annotations(); int size = oldAnnotations.size(); if (size > 0) { ASTNode prev = getPreviousNode(oldDim); Annotation annotation = (Annotation) oldAnnotations.get(0); int start = prev != null ? prev.getStartPosition() + prev.getLength() : annotation.getStartPosition(); annotation = (Annotation) oldAnnotations.get(size - 1); int end = annotation.getStartPosition() + annotation.getLength(); end = getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, end) - 1; doTextRemove(start, end - start, editGroup); } } insertAnnotationsOnDimension(replacingType, index, pos, editGroup, true); } else { Dimension dim = (Dimension) replacingType.dimensions().get(index); rewriteNodeList(dim, Dimension.ANNOTATIONS_PROPERTY, pos, String.valueOf(' '), String.valueOf(' '), String.valueOf(' ')); } }
private boolean isIgnoredAnnotation(Annotation m) { return _configuration.isIgnoredAnnotation(qualifiedName(m.resolveAnnotationBinding().getAnnotationType())); }
private void visitAnnotationsList(List annotations) { for (Iterator it = annotations.iterator(); it.hasNext(); ) { Annotation annotation = (Annotation) it.next(); annotation.accept(this); this.buffer.append(' '); } }
@SuppressWarnings("unchecked") protected void replace(org.eclipse.jdt.core.dom.Annotation oldNode, org.eclipse.jdt.core.dom.Annotation newNode) { List<IExtendedModifier> modifiers; ASTNode parentNode = oldNode.getParent(); if (parentNode instanceof BodyDeclaration) { modifiers = ((BodyDeclaration) parentNode).modifiers(); } else if (parentNode instanceof SingleVariableDeclaration) { modifiers = ((SingleVariableDeclaration) parentNode).modifiers(); } else { throw new IllegalStateException("Cannot handle annotations attached to " + parentNode); } int pos = modifiers.indexOf(annotation); if (pos >= 0) { modifiers.set(pos, newNode); } }
private void addTypeAnnotationSourceAnchor(Annotation node) { ASTNode parent = node.getParent(); NamedEntity namedEntity = null; if ((parent instanceof AbstractTypeDeclaration) (Method) importer.topOfContainerStack()); if (namedEntity != null && node.resolveAnnotationBinding() != null) { AnnotationInstance annotationInstance = importer.createAnnotationInstanceFromAnnotationBinding(namedEntity, node.resolveAnnotationBinding()); importer.createLightweightSourceAnchor(annotationInstance, node); for (Object object : fragments) { if (((VariableDeclarationFragment) object).resolveBinding() != null && node.resolveAnnotationBinding() != null) { Attribute attribute = importer .ensureAttributeForVariableBinding(((VariableDeclarationFragment) object).resolveBinding()); AnnotationInstance annotationInstance = importer .createAnnotationInstanceFromAnnotationBinding(attribute, node.resolveAnnotationBinding()); importer.createLightweightSourceAnchor(annotationInstance, node);
/** * Gets the sibling where the given {@link Annotation} should be added to the given {@link BodyDeclaration}. The * {@link Annotation} must be added before the returned node. * * @param owner * The owner of the {@link Annotation}. * @param newAnnotation * The new {@link Annotation} that should be added. * @return The */ public static ASTNode getAnnotationSibling(BodyDeclaration owner, Annotation newAnnotation) { Deque<Annotation> annotations = getAnnotations(owner); if (!annotations.isEmpty()) { int newAnnotLen = newAnnotation.toString().length(); Iterator<Annotation> iterator = annotations.descendingIterator(); while (iterator.hasNext()) { Annotation existingAnnotation = iterator.next(); int len = existingAnnotation.getLength(); if (len > 0 && len >= newAnnotLen) { return existingAnnotation; } } } for (Object o : owner.modifiers()) { if (o instanceof Modifier) { return (Modifier) o; } } return null; }
@Override public String getName() { return annotation.getTypeName().getFullyQualifiedName(); }
@Override protected ASTRewrite getRewrite() throws CoreException { AST ast= fAnnotation.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); createImportRewrite((CompilationUnit) fAnnotation.getRoot()); ListRewrite listRewrite; if (fAnnotation instanceof NormalAnnotation) { listRewrite= rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY); } else { NormalAnnotation newAnnotation= ast.newNormalAnnotation(); newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName())); rewrite.replace(fAnnotation, newAnnotation, null); listRewrite= rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY); } addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite); return rewrite; }
private void handleAnnotation(Annotation node) { ASTNode parentNode = node.getParent(); boolean breakAfter = false; boolean isTypeAnnotation = this.declarationModifierVisited; int lParen = this.tm.firstIndexAfter(node.getTypeName(), TokenNameLPAREN); int rParen = this.tm.lastIndexIn(node, TokenNameRPAREN); handleParenthesesPositions(lParen, rParen, this.options.parenthesis_positions_in_annotation);
@Override public AnnotationSource<O> setName(final String className) { annotation.setTypeName(ast.newName(className)); return this; }
private void rewriteAnnotationsOnDimension(ArrayType oldArrayType, ArrayType replacingType, int index, int pos, boolean typeReplaced, TextEditGroup editGroup) throws CoreException { if (typeReplaced) { List dimensions = oldArrayType.dimensions(); Dimension oldDim = index < dimensions.size() ? (Dimension) dimensions.get(index) : null; if (oldDim != null) { List oldAnnotations = oldDim.annotations(); int size = oldAnnotations.size(); if (size > 0) { ASTNode prev = getPreviousNode(oldDim); Annotation annotation = (Annotation) oldAnnotations.get(0); int start = prev != null ? prev.getStartPosition() + prev.getLength() : annotation.getStartPosition(); annotation = (Annotation) oldAnnotations.get(size - 1); int end = annotation.getStartPosition() + annotation.getLength(); end = getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, end) - 1; doTextRemove(start, end - start, editGroup); } } insertAnnotationsOnDimension(replacingType, index, pos, editGroup, true); } else { Dimension dim = (Dimension) replacingType.dimensions().get(index); rewriteNodeList(dim, Dimension.ANNOTATIONS_PROPERTY, pos, String.valueOf(' '), String.valueOf(' '), String.valueOf(' ')); } }
private static boolean isPureTypeAnnotation(Annotation annotation) { IAnnotationBinding binding= annotation.resolveAnnotationBinding(); if (binding == null) { return false; } IAnnotationBinding targetAnnotationBinding= findTargetAnnotation(binding.getAnnotationType().getAnnotations()); if (targetAnnotationBinding == null) { return false; } return isTypeUseOnly(targetAnnotationBinding); }