org.eclipse.jdt.core.dom.Annotation.getAST()方法的使用及代码示例

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

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

Annotation.getAST介绍

暂无

代码示例

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

/**
 * Add the specified annotation to the specified array initializer,
 * padding it with 'null' literals as necessary
 */
private void addInnerToExpressions(Annotation inner, List<Expression> expressions) {
  if (expressions.size() > this.index) {
    throw new IllegalStateException("expressions size is greater than index - size: " + expressions.size() + " - index: " + this.index);
  }
  while (expressions.size() < this.index) {
    expressions.add(inner.getAST().newNullLiteral());
  }
  expressions.add(inner);
}

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

/**
 * Build a new array initializer to hold the specified annotation,
 * padding it with 'null' literals as necessary
 */
private ArrayInitializer buildNewInnerArrayInitializer(Annotation inner) {
  ArrayInitializer ai = inner.getAST().newArrayInitializer();
  this.addInnerToExpressions(inner, this.expressions(ai));
  return ai;
}

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

iter.add((MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp));

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

iter.add((MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp));

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

MemberValuePair mvpCopy = (MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp);
mvpCopy.setValue((Expression) result.getInternal());
iter.add(mvpCopy);

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

MemberValuePair mvpCopy = (MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp);
mvpCopy.setValue((Expression) result.getInternal());
iter.add(mvpCopy);

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

/**
 * Move the annotation to the specified index, leaving its original
 * position cleared out.
 */
public void moveAnnotation(int newIndex, ModifiedDeclaration declaration) {
  int oldIndex = this.index;
  if (newIndex == oldIndex) {
    return;
  }
  Annotation original = this.getAnnotation(declaration);
  if (original == null) {
    this.index = newIndex;
    this.removeAnnotation(declaration);  // clear out the new location (?)
  } else {
    Annotation copy = (Annotation) ASTNode.copySubtree(original.getAST(), original);
    this.index = newIndex;
    this.addAnnotation(declaration, copy);  // install the copy in the new location
    this.index = oldIndex;
    this.removeAnnotation(declaration);  // go back and clear out the original location (AFTER the move)
    this.index = newIndex;
  }
}

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

/**
 * Manipulate the specified expression appropriately.
 * If it is an array initializer, add the specified annotation to it.
 * If it is not, replace the expression or convert it into an array
 * initializer.
 */
private void modifyExpression(ASTNode node, ExpressionProvider expProvider, Annotation inner) {
  Expression value = expProvider.getExpression(node);
  if (value.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
    // ignore the other entries in the array initializer(?) - they may not be matching Annotations...
    List<Expression> expressions = this.expressions((ArrayInitializer) value);
    if (this.index >= expressions.size()) {
      this.addInnerToExpressions(inner, expressions);
    } else {
      expressions.set(this.index, inner);
    }
  } else {
    if (this.index == 0) {
      // replace whatever was there before
      expProvider.setExpression(node, inner);
    } else {
      // convert to an array
      ArrayInitializer ai = inner.getAST().newArrayInitializer();
      List<Expression> expressions = this.expressions(ai);
      expressions.add((Expression) ASTNode.copySubtree(value.getAST(), value));
      this.addInnerToExpressions(inner, expressions);
      expProvider.setExpression(node, ai);
    }
  }
}

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

na.values().add(ASTNode.copySubtree(annotation.getAST(), mvp));

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

public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
  ICompilationUnit cu= context.getCompilationUnit();
  ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof MethodDeclaration)) {
    return;
  }
  MethodDeclaration methodDecl= (MethodDeclaration) selectedNode;
  Annotation annot= StubUtility2.findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$
  if (annot != null) {
    ASTRewrite rewrite= ASTRewrite.create(annot.getAST());
    rewrite.remove(annot, null);
    String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override;
    Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image);
    proposals.add(proposal);
    QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals);
  }
}

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

public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException {
  ICompilationUnit cu= context.getCompilationUnit();
  ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof MethodDeclaration)) {
    return;
  }
  MethodDeclaration methodDecl= (MethodDeclaration) selectedNode;
  Annotation annot= findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$
  if (annot != null) {
    ASTRewrite rewrite= ASTRewrite.create(annot.getAST());
    rewrite.remove(annot, null);
    String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override;
    Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, 6, image);
    proposals.add(proposal);
    
    QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals);
  }
}

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

public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
  ICompilationUnit cu= context.getCompilationUnit();
  ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof MethodDeclaration)) {
    return;
  }
  MethodDeclaration methodDecl= (MethodDeclaration) selectedNode;
  Annotation annot= StubUtility2Core.findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$
  if (annot != null) {
    ASTRewrite rewrite= ASTRewrite.create(annot.getAST());
    rewrite.remove(annot, null);
    String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override;
    Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image);
    proposals.add(proposal);
    QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals);
  }
}

代码示例来源: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.scout.sdk.deps/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.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;
}

相关文章