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


Java Element类代码示例

本文整理汇总了Java中javax.lang.model.element.Element的典型用法代码示例。如果您正苦于以下问题:Java Element类的具体用法?Java Element怎么用?Java Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: computeReturn

import javax.lang.model.element.Element; //导入依赖的package包/类
private static List<? extends TypeMirror> computeReturn(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    ReturnTree rt = (ReturnTree) parent.getLeaf();
    
    if (rt.getExpression() == error) {
        TreePath method = findMethod(parent);
        
        if (method == null) {
            return null;
        }
        
        Element el = info.getTrees().getElement(method);
        
        if (el == null || el.getKind() != ElementKind.METHOD) {
            return null;
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return Collections.singletonList(((ExecutableElement) el).getReturnType());
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CreateElementUtilities.java

示例2: getAllSelectedElements

import javax.lang.model.element.Element; //导入依赖的package包/类
Set<Element> getAllSelectedElements(DocletEnvironment docenv) {
    Set<Element> result = new TreeSet<Element>((Element e1, Element e2) -> {
        // some grouping by kind preferred
        int rc = e1.getKind().compareTo(e2.getKind());
        if (rc != 0) return rc;
        rc = e1.toString().compareTo(e2.toString());
        if (rc != 0) return rc;
        return Integer.compare(e1.hashCode(), e2.hashCode());
    });
    Set<? extends Element> elements = docenv.getIncludedElements();
    for (ModuleElement me : ElementFilter.modulesIn(elements)) {
        addEnclosedElements(docenv, result, me);
    }
    for (PackageElement pe : ElementFilter.packagesIn(elements)) {
        ModuleElement mdle = docenv.getElementUtils().getModuleOf(pe);
        if (mdle != null)
            addEnclosedElements(docenv, result, mdle);
        addEnclosedElements(docenv, result, pe);
    }
    for (TypeElement te : ElementFilter.typesIn(elements)) {
        addEnclosedElements(docenv, result, te);
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ModuleTestBase.java

示例3: checkElementVisibility

import javax.lang.model.element.Element; //导入依赖的package包/类
/**
 * Checks that {@code target} is visible from {@code fromPkg}.
 * If {@code fromPkg} is {@code null}, we take that to mean that {@code target} should be visible everywhere.
 * Throws an {@link EasyPluginException} with a proper error message if the target element does not match
 * the visibility constraint.
 * @param eles Elements
 * @param target The target element to check for visibility
 * @param fromPkg The package to check for visibility from.
 *                Null indicates it needs to be globally visible.
 * @throws EasyPluginException if it's not visible
 */
static void checkElementVisibility(Elements eles, Element target, String fromPkg) {
    // I would have used a switch, but that messed up compilation somehow.
    // I guess it generated another class file?
    // Anyways, this works.
    if (target.getKind().isClass() || target.getKind().isInterface()) {
        checkClassVisibility(eles, (TypeElement) target, fromPkg);
    } else if (target.getKind().isField()
            || target.getKind() == ElementKind.METHOD
            || target.getKind() == ElementKind.CONSTRUCTOR) {
        checkMemberVisibility(eles, target, fromPkg);
    } else if (target.getKind() == ElementKind.ENUM_CONSTANT) {
        checkClassVisibility(eles, (TypeElement) target.getEnclosingElement(), fromPkg);
    } else {
        // This isn't an EasyPluginException because our code shouldn't be dumb
        // enough to check the visibility of any other kind of element.
        throw new IllegalArgumentException("Bad kind for element visibility check: " + target.getKind());
    }
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:30,代码来源:Util.java

示例4: visitIdentifier

import javax.lang.model.element.Element; //导入依赖的package包/类
@Override
public State visitIdentifier(IdentifierTree node, Void p) {
    super.visitIdentifier(node, p);
    
    Element e = info.getTrees().getElement(getCurrentPath());

    if (e == null || !isVariableElement(e)) {
        return State.POSSIBLE_NULL;
    }
    if (e.getKind() == ElementKind.ENUM_CONSTANT) {
        // enum constants are never null
        return State.NOT_NULL;
    }

    State s = variable2State.get((VariableElement) e);
    if (s != null) {
        return s;
    }
    
    return getStateFromAnnotations(info, e);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:NPECheck.java

示例5: deleteDeclIfMatch

import javax.lang.model.element.Element; //导入依赖的package包/类
private void deleteDeclIfMatch(Tree tree, Element elementToFind) {
    if (JavaPluginUtils.isSyntheticPath(workingCopy, getCurrentPath())) {
        return ;
    }
    
    Element el = workingCopy.getTrees().getElement(getCurrentPath());
    if (isMatch(el, elementToFind)) {
        Tree parent = getCurrentPath().getParentPath().getLeaf();
        Tree newOne = null;
        if (TreeUtilities.CLASS_TREE_KINDS.contains(parent.getKind())) {
            newOne = make.removeClassMember((ClassTree) parent, tree);
        } else if (parent.getKind() == Tree.Kind.COMPILATION_UNIT) {
            newOne = make.removeCompUnitTypeDecl((CompilationUnitTree) parent, tree);
        } else if (tree.getKind() == Tree.Kind.VARIABLE) {
            if (parent.getKind() == Tree.Kind.METHOD) {
                newOne = make.removeMethodParameter((MethodTree)parent, (VariableTree) tree);
            } else {
                newOne = make.removeBlockStatement((BlockTree)parent, (VariableTree) tree);
            }
        }
        if (newOne!=null) {
            rewrite(parent,newOne);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:DeleteTransformer.java

示例6: visitClass

import javax.lang.model.element.Element; //导入依赖的package包/类
@Override
public Void visitClass(ClassTree tree, Void d) {
    Element el = info.getTrees().getElement(getCurrentPath());
    if (toFind.equals(el)) {
        try {
            int[] span = treeUtils.findNameSpan(tree);
            if(span != null) {
                MutablePositionRegion region = createRegion(doc, span[0], span[1]);
                usages.add(region);
            }
        } catch (BadLocationException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    handleJavadoc(getCurrentPath());
    return super.visitClass(tree, d);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:FindLocalUsagesQuery.java

示例7: buildOnChangeBinding

import javax.lang.model.element.Element; //导入依赖的package包/类
private void buildOnChangeBinding(MethodSpec.Builder constructorBuilder, Element element) {
  OnPrefChange onPrefChange = element.getAnnotation(OnPrefChange.class);
  if (onPrefChange != null) {
    int[] resourceIds = onPrefChange.value();

    for (int resourceId : resourceIds) {
      constructorBuilder.addStatement("target.findPreference(target.getString($L))"
          + ".setOnPreferenceChangeListener(new $T(){\n"
          + "@Override public boolean onPreferenceChange($T preference, Object newValue) {\n"
          + "\t\ttarget.$L(preference, newValue);\n"
          + "\t\treturn true;\n"
          + "\t}\n"
          + "})", resourceId, CHANGE_LISTENER, PREFERENCE, element.getSimpleName());
    }
  }
}
 
开发者ID:quangctkm9207,项目名称:prefpin,代码行数:17,代码来源:PrefPinProcessor.java

示例8: printDocComment

import javax.lang.model.element.Element; //导入依赖的package包/类
private void printDocComment(Element e) {
    String docComment = elementUtils.getDocComment(e);

    if (docComment != null) {
        // Break comment into lines
        StringTokenizer st = new StringTokenizer(docComment,
                                                          "\n\r");
        indent();
        writer.println("/**");

        while(st.hasMoreTokens()) {
            indent();
            writer.print(" *");
            writer.println(st.nextToken());
        }

        indent();
        writer.println(" */");
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:PrintingProcessor.java

示例9: getMethodParams

import javax.lang.model.element.Element; //导入依赖的package包/类
private List<ParamInfo> getMethodParams(Element classElement) {
    List<ParamInfo> methodParams = new LinkedList<ParamInfo>();
    ExecutableElement methodElement = (ExecutableElement) classElement;

    for (VariableElement methodParam : methodElement.getParameters()) {
        try {
            String name = getParamName(methodParam);
            ParamInfo.Type type = getParamType(methodParam);
            String clsName = getParamClsName(methodParam);
            
            methodParams.add(new ParamInfo(name, type, clsName));
        } catch (IllegalArgumentException ex) {
            // Do nothing, thrown when we are missing some info.
        }
    }
    return methodParams;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:18,代码来源:ClassCrawler.java

示例10: overridableKind

import javax.lang.model.element.Element; //导入依赖的package包/类
private static int overridableKind(Element el) {
    if (   el.getModifiers().contains(Modifier.FINAL)
        || el.getModifiers().contains(Modifier.PRIVATE)) {
        return -1;
    }

    if (el.getKind().isClass() || el.getKind().isInterface()) {
        return el.getModifiers().contains(Modifier.ABSTRACT) ? 0 : 1;
    }

    if (   el.getKind() == ElementKind.METHOD
        && !el.getModifiers().contains(Modifier.STATIC)
        && !el.getEnclosingElement().getModifiers().contains(Modifier.FINAL)) {
        return el.getModifiers().contains(Modifier.ABSTRACT) ? 2 : 3;
    }

    return -1;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:GoToSupport.java

示例11: handleFlowResults

import javax.lang.model.element.Element; //导入依赖的package包/类
private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) {
    for (Env<AttrContext> env: queue) {
        switch (env.tree.getTag()) {
            case JCTree.CLASSDEF:
                JCClassDecl cdef = (JCClassDecl) env.tree;
                if (cdef.sym != null)
                    elems.append(cdef.sym);
                break;
            case JCTree.TOPLEVEL:
                JCCompilationUnit unit = (JCCompilationUnit) env.tree;
                if (unit.packge != null)
                    elems.append(unit.packge);
                break;
        }
    }
    genList.addAll(queue);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:18,代码来源:JavacTaskImpl.java

示例12: isElementAvail

import javax.lang.model.element.Element; //导入依赖的package包/类
/**
 * Checks if the element is still available. Tests if it is still valid.
 * (Was not deleted by matching mechanism.)
 * If element is available, returns null, otherwise it creates problem.
 * (Helper method for refactoring implementation as this problem is
 * general for all refactorings.)
 *
 * @param   e  element to check
 * @param info 
 * @return  problem message or null if the element is valid
 */
protected static Problem isElementAvail(TreePathHandle e, CompilationInfo info) {
    if (e==null) {
        //element is null or is not valid.
        return new Problem(true, NbBundle.getMessage(FindVisitor.class, "DSC_ElNotAvail")); // NOI18N
    } else {
        Element el = e.resolveElement(info);
        String elName = el != null ? el.getSimpleName().toString() : null;
        if (el == null || el.asType().getKind() == TypeKind.ERROR || "<error>".equals(elName)) { // NOI18N
            return new Problem(true, NbBundle.getMessage(FindVisitor.class, "DSC_ElementNotResolved"));
        }
        
        if ("this".equals(elName) || "super".equals(elName)) { // NOI18N
            return new Problem(true, NbBundle.getMessage(FindVisitor.class, "ERR_CannotRefactorThis", el.getSimpleName()));
        }
        
        // element is still available
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:JavaRefactoringPlugin.java

示例13: getNodeForElement

import javax.lang.model.element.Element; //导入依赖的package包/类
public ElementNode getNodeForElement(ElementHandle<Element> eh) {

        if (getDescritption().elementHandle != null
                && eh.signatureEquals(getDescritption().elementHandle)) {
            return this;
        }

        Children ch = getChildren();
        if (ch instanceof ElementChilren) {
            for (Node sub : ch.getNodes()) {
                ElementNode result = ((ElementNode) sub).getNodeForElement(eh);
                if (result != null) {
                    return result;
                }
            }
        }

        return null;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ElementNode.java

示例14: testGoToTypeVariable

import javax.lang.model.element.Element; //导入依赖的package包/类
public void testGoToTypeVariable() throws Exception {
    final boolean[] wasCalled = new boolean[1];

    performTest("package test; public class Test<TTT> {public void test() {TTT t;}}", 60, new OrigUiUtilsCaller() {
        public void open(FileObject fo, int pos) {
            assertTrue(source == fo);
            assertEquals(32, pos);
            wasCalled[0] = true;
        }
        public void beep() {
            fail("Should not be called.");
        }
        public void open(ClasspathInfo info, Element el) {
            fail("Should not be called.");
        }
    }, false);

    assertTrue(wasCalled[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:GoToSupportTest.java

示例15: handleFlowResults

import javax.lang.model.element.Element; //导入依赖的package包/类
private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) {
    for (Env<AttrContext> env: queue) {
        switch (env.tree.getTag()) {
            case CLASSDEF:
                JCClassDecl cdef = (JCClassDecl) env.tree;
                if (cdef.sym != null)
                    elems.append(cdef.sym);
                break;
            case MODULEDEF:
                JCModuleDecl mod = (JCModuleDecl) env.tree;
                if (mod.sym != null)
                    elems.append(mod.sym);
                break;
            case PACKAGEDEF:
                JCCompilationUnit unit = env.toplevel;
                if (unit.packge != null)
                    elems.append(unit.packge);
                break;
        }
    }
    genList.addAll(queue);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JavacTaskImpl.java


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