当前位置: 首页>>代码示例>>Java>>正文


Java ModifiersTree.getAnnotations方法代码示例

本文整理汇总了Java中com.sun.source.tree.ModifiersTree.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java ModifiersTree.getAnnotations方法的具体用法?Java ModifiersTree.getAnnotations怎么用?Java ModifiersTree.getAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.source.tree.ModifiersTree的用法示例。


在下文中一共展示了ModifiersTree.getAnnotations方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findFxmlAnnotation

import com.sun.source.tree.ModifiersTree; //导入方法依赖的package包/类
private AnnotationTree findFxmlAnnotation(ModifiersTree modTree) {
    for (AnnotationTree annTree : modTree.getAnnotations()) {
        TreePath tp = new TreePath(new TreePath(wcopy.getCompilationUnit()), annTree.getAnnotationType());
        Element  e  = wcopy.getTrees().getElement(tp);
        if (fxmlAnnotationType.equals(e)) {
            return annTree;
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ControllerGenerator.java

示例2: performRewrite

import com.sun.source.tree.ModifiersTree; //导入方法依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    ModifiersTree mt = (ModifiersTree) ctx.getPath().getLeaf();
    
    for (AnnotationTree at : mt.getAnnotations()) {
        Element el = ctx.getWorkingCopy().getTrees().getElement(new TreePath(ctx.getPath(), at));
        
        if (el != null && el.getKind().isInterface() && ((TypeElement ) el).getQualifiedName().contentEquals("java.lang.Override")) {
            ctx.getWorkingCopy().rewrite(mt, ctx.getWorkingCopy().getTreeMaker().removeModifiersAnnotation(mt, at));
            return ;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:RemoveOverride.java

示例3: addSuppressWarningsFix

import com.sun.source.tree.ModifiersTree; //导入方法依赖的package包/类
private Description.Builder addSuppressWarningsFix(
    Tree suggestTree, Description.Builder builder, String checkerName) {
  SuppressWarnings extantSuppressWarnings =
      ASTHelpers.getAnnotation(suggestTree, SuppressWarnings.class);
  SuggestedFix fix;
  if (extantSuppressWarnings == null) {
    fix = SuggestedFix.prefixWith(suggestTree, "@SuppressWarnings(\"" + checkerName + "\") ");
  } else {
    // need to update the existing list of warnings
    List<String> suppressions = Lists.newArrayList(extantSuppressWarnings.value());
    suppressions.add(checkerName);
    // find the existing annotation, so we can replace it
    ModifiersTree modifiers =
        (suggestTree instanceof MethodTree)
            ? ((MethodTree) suggestTree).getModifiers()
            : ((VariableTree) suggestTree).getModifiers();
    List<? extends AnnotationTree> annotations = modifiers.getAnnotations();
    // noinspection ConstantConditions
    com.google.common.base.Optional<? extends AnnotationTree> suppressWarningsAnnot =
        Iterables.tryFind(
            annotations,
            annot -> annot.getAnnotationType().toString().endsWith("SuppressWarnings"));
    if (!suppressWarningsAnnot.isPresent()) {
      throw new AssertionError("something went horribly wrong");
    }
    String replacement =
        "@SuppressWarnings({"
            + Joiner.on(',').join(Iterables.transform(suppressions, s -> '"' + s + '"'))
            + "}) ";
    fix = SuggestedFix.replace(suppressWarningsAnnot.get(), replacement);
  }
  return builder.addFix(fix);
}
 
开发者ID:uber,项目名称:NullAway,代码行数:34,代码来源:NullAway.java

示例4: canLocalHaveHorizontalAnnotations

import com.sun.source.tree.ModifiersTree; //导入方法依赖的package包/类
/**
 * Can a local with a set of modifiers be declared with horizontal annotations? This is currently
 * true if there is at most one marker annotation, and no others.
 *
 * @param modifiers the list of {@link ModifiersTree}s
 * @return whether the local can be declared with horizontal annotations
 */
private Direction canLocalHaveHorizontalAnnotations(ModifiersTree modifiers) {
    int markerAnnotations = 0;
    for (AnnotationTree annotation : modifiers.getAnnotations()) {
        if (annotation.getArguments().isEmpty()) {
            markerAnnotations++;
        }
    }
    return markerAnnotations <= 1 && markerAnnotations == modifiers.getAnnotations().size()
            ? Direction.HORIZONTAL
            : Direction.VERTICAL;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:19,代码来源:JavaInputAstVisitor.java

示例5: fieldAnnotationDirection

import com.sun.source.tree.ModifiersTree; //导入方法依赖的package包/类
/**
 * Should a field with a set of modifiers be declared with horizontal annotations? This is
 * currently true if all annotations are marker annotations.
 */
private Direction fieldAnnotationDirection(ModifiersTree modifiers) {
    for (AnnotationTree annotation : modifiers.getAnnotations()) {
        if (!annotation.getArguments().isEmpty()) {
            return Direction.VERTICAL;
        }
    }
    return Direction.HORIZONTAL;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:13,代码来源:JavaInputAstVisitor.java

示例6: isAlreadyRegistered

import com.sun.source.tree.ModifiersTree; //导入方法依赖的package包/类
private static boolean isAlreadyRegistered(TreePath treePath, String key) {
    ModifiersTree modifiers;
    Tree tree = treePath.getLeaf();
    switch (tree.getKind()) {
    case METHOD:
        modifiers = ((MethodTree) tree).getModifiers();
        break;
    case VARIABLE:
        modifiers = ((VariableTree) tree).getModifiers();
        break;
    case CLASS:
    case ENUM:
    case INTERFACE:
    case ANNOTATION_TYPE:
        modifiers = ((ClassTree) tree).getModifiers();
        break;
    default:
        modifiers = null;
    }
    if (modifiers != null) {
        for (AnnotationTree ann : modifiers.getAnnotations()) {
            Tree annotationType = ann.getAnnotationType();
            if (annotationType.toString().matches("((org[.]openide[.]util[.])?NbBundle[.])?Messages")) { // XXX see above
                List<? extends ExpressionTree> args = ann.getArguments();
                if (args.size() != 1) {
                    continue; // ?
                }
                AssignmentTree assign = (AssignmentTree) args.get(0);
                if (!assign.getVariable().toString().equals("value")) {
                    continue; // ?
                }
                ExpressionTree arg = assign.getExpression();
                if (arg.getKind() == Tree.Kind.STRING_LITERAL) {
                    if (isRegistered(key, arg)) {
                        return true;
                    }
                } else if (arg.getKind() == Tree.Kind.NEW_ARRAY) {
                    for (ExpressionTree elt : ((NewArrayTree) arg).getInitializers()) {
                        if (isRegistered(key, elt)) {
                            return true;
                        }
                    }
                } else {
                    // ?
                }
            }
        }
    }
    TreePath parentPath = treePath.getParentPath();
    if (parentPath == null) {
        return false;
    }
    // XXX better to check all sources in the same package
    return isAlreadyRegistered(parentPath, key);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:UseNbBundleMessages.java

示例7: implement

import com.sun.source.tree.ModifiersTree; //导入方法依赖的package包/类
public ChangeInfo implement(){
    CancellableTask<WorkingCopy> task = new CancellableTask<WorkingCopy>(){
        public void cancel() {}
        
        public void run(WorkingCopy workingCopy) throws Exception {
            workingCopy.toPhase(JavaSource.Phase.RESOLVED);
            TypeElement clazz = classHandle.resolve(workingCopy);
            
            if (clazz != null){
                
                for (ExecutableElement methodElem : ElementFilter.methodsIn(clazz.getEnclosedElements())){
                    if (methodElem.getSimpleName().toString().startsWith("get")){ //NOI18N
                        VariableElement fieldElem = ModelUtils.getField(clazz, ModelUtils.getFieldNameFromAccessor(methodElem.getSimpleName().toString()));
                        
                        if (fieldElem != null){
                            MethodTree methodTree = workingCopy.getTrees().getTree((methodElem));
                            VariableTree fieldTree = (VariableTree) workingCopy.getTrees().getTree(fieldElem);
                            
                            ModifiersTree srcModifiersTree = getSourceModifiers(fieldTree, methodTree);
                            
                            List <AnnotationTree> remainingAnnotations = new LinkedList<AnnotationTree>();
                            List <AnnotationTree> newTargetAnnots = new LinkedList<AnnotationTree>();
                            
                            for (AnnotationTree annTree : srcModifiersTree.getAnnotations()){
                                if (isJPAAttrAnnotation(workingCopy, annTree)){
                                    newTargetAnnots.add(annTree);
                                } else {
                                    remainingAnnotations.add(annTree);
                                }
                            }
                            
                            if (newTargetAnnots.size() > 0){
                                TreeMaker make = workingCopy.getTreeMaker();
                                ModifiersTree targetModifiers = getTargetModifiers(fieldTree, methodTree);
                                
                                workingCopy.rewrite(srcModifiersTree, make.Modifiers(srcModifiersTree, remainingAnnotations));
                                newTargetAnnots.addAll(targetModifiers.getAnnotations());
                                workingCopy.rewrite(targetModifiers,make.Modifiers(targetModifiers,newTargetAnnots));
                            }
                        }
                    }
                }
            }
        }
    };
    
    JavaSource javaSource = JavaSource.forFileObject(fileObject);
    
    try{
        javaSource.runModificationTask(task).commit();
    } catch (IOException e){
        JPAProblemFinder.LOG.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:UnifyAccessType.java


注:本文中的com.sun.source.tree.ModifiersTree.getAnnotations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。