org.eclipse.jdt.core.dom.Annotation类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中org.eclipse.jdt.core.dom.Annotation类的一些代码示例,展示了Annotation类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation类的具体详情如下:
包路径:org.eclipse.jdt.core.dom.Annotation
类名称:Annotation

Annotation介绍

[英]Abstract base class of AST nodes that represent annotations.

Annotation: 
NormalAnnotation 
MarkerAnnotation 
SingleMemberAnnotation

[中]表示注释的AST节点的抽象基类。

Annotation: 
NormalAnnotation 
MarkerAnnotation 
SingleMemberAnnotation

代码示例

代码示例来源:origin: org.projectlombok/lombok

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);

代码示例来源:origin: forge/roaster

@Override
public String toString()
{
 return annotation.toString();
}

代码示例来源:origin: org.projectlombok/lombok

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("(");

代码示例来源:origin: org.jboss.forge/roaster-jdt

@Override
public String getName()
{
 return annotation.getTypeName().getFullyQualifiedName();
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

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;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

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);

代码示例来源:origin: windup/windup

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());

代码示例来源:origin: org.jboss.forge/roaster-jdt

@Override
public AnnotationSource<O> setName(final String className)
{
 annotation.setTypeName(ast.newName(className));
 return this;
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core

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(' '));
  }
}

代码示例来源:origin: mono/sharpen

private boolean isIgnoredAnnotation(Annotation m) {
  return _configuration.isIgnoredAnnotation(qualifiedName(m.resolveAnnotationBinding().getAnnotationType()));
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

private void visitAnnotationsList(List annotations) {
  for (Iterator it = annotations.iterator(); it.hasNext(); ) {
    Annotation annotation = (Annotation) it.next();
    annotation.accept(this);
    this.buffer.append(' ');
  }
}

代码示例来源:origin: forge/roaster

@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);
 }
}

代码示例来源:origin: feenkcom/jdt2famix

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);

代码示例来源:origin: org.eclipse.scout.sdk.s2e/org.eclipse.scout.sdk.s2e

/**
 * 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;
}

代码示例来源:origin: forge/roaster

@Override
public String getName()
{
 return annotation.getTypeName().getFullyQualifiedName();
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

@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;
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

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);

代码示例来源:origin: forge/roaster

@Override
public AnnotationSource<O> setName(final String className)
{
 annotation.setTypeName(ast.newName(className));
 return this;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

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(' '));
  }
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

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);
}

相关文章