Java Code Examples for javax.lang.model.element.ElementKind.TYPE_PARAMETER

The following are Jave code examples for showing how to use TYPE_PARAMETER of the javax.lang.model.element.ElementKind class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: WhereUsedPanelVariable.java   Source Code and License Vote up 6 votes
@Override
void initialize(final Element element, CompilationController info) {
    final String labelText;
    if(element.getKind() == ElementKind.TYPE_PARAMETER) {
        labelText = UIUtilities.createHeader((TypeParameterElement) element, info.getElements().isDeprecated(element), false, false, true);
    } else {
        labelText = UIUtilities.createHeader((VariableElement) element, info.getElements().isDeprecated(element), false, false, true);
    }
    final Icon labelIcon = ElementIcons.getElementIcon(element.getKind(), element.getModifiers());
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            Dimension preferredSize = label.getPreferredSize();
            label.setText(labelText);
            label.setIcon(labelIcon);
            label.setPreferredSize(preferredSize);
            label.setMinimumSize(preferredSize);
        }
    });
}
 
Example 2
Project: incubator-netbeans   File: Analyzer.java   Source Code and License Vote up 6 votes
private void checkParamsDocumented(List<? extends Element> list, List<? extends Tree> trees, DocTreePath docTreePath, Set<String> inheritedParams, List<ErrorDescription> errors) {
    if(foundInheritDoc) return;
    for (int i = 0; i < list.size() && i < trees.size(); i++) {
        if(ctx.isCanceled()) { return; }
        Element e = list.get(i);
        Tree t = trees.get(i);
        if (!foundParams.contains(e) && !inheritedParams.contains(e.getSimpleName().toString())) {
            boolean isTypeParam = e.getKind() == ElementKind.TYPE_PARAMETER;
            CharSequence paramName = (isTypeParam)
                    ? "<" + e.getSimpleName() + ">"
                    : e.getSimpleName();
            DocTreePathHandle dtph = DocTreePathHandle.create(docTreePath, javac);
            if (dtph != null) {
                errors.add(ErrorDescriptionFactory.forTree(ctx, t, MISSING_PARAM_DESC(paramName), AddTagFix.createAddParamTagFix(dtph, e.getSimpleName().toString(), isTypeParam, i).toEditorFix()));
            }
        }
    }
}
 
Example 3
Project: OpenJSharp   File: Checker.java   Source Code and License Vote up 5 votes
private void checkParamsDocumented(List<? extends Element> list) {
    if (foundInheritDoc)
        return;

    for (Element e: list) {
        if (!foundParams.contains(e)) {
            CharSequence paramName = (e.getKind() == ElementKind.TYPE_PARAMETER)
                    ? "<" + e.getSimpleName() + ">"
                    : e.getSimpleName();
            reportMissing("dc.missing.param", paramName);
        }
    }
}
 
Example 4
Project: openjdk-jdk10   File: Checker.java   Source Code and License Vote up 5 votes
private void checkParamsDocumented(List<? extends Element> list) {
    if (foundInheritDoc)
        return;

    for (Element e: list) {
        if (!foundParams.contains(e)) {
            CharSequence paramName = (e.getKind() == ElementKind.TYPE_PARAMETER)
                    ? "<" + e.getSimpleName() + ">"
                    : e.getSimpleName();
            reportMissing("dc.missing.param", paramName);
        }
    }
}
 
Example 5
Project: openjdk-jdk10   File: SourceCodeAnalysisImpl.java   Source Code and License Vote up 5 votes
private boolean isStaticContext(AnalyzeTask at, TreePath path) {
    switch (path.getLeaf().getKind()) {
        case ARRAY_TYPE:
        case PRIMITIVE_TYPE:
            return true;
        default:
            Element selectEl = at.trees().getElement(path);
            return selectEl != null && (selectEl.getKind().isClass() || selectEl.getKind().isInterface() || selectEl.getKind() == ElementKind.TYPE_PARAMETER) && selectEl.asType().getKind() != TypeKind.ERROR;
    }
}
 
Example 6
Project: incubator-netbeans   File: PullUpTransformer.java   Source Code and License Vote up 4 votes
private <E extends Tree> E fixGenericTypes(E tree, final TreePath path, final Element member) {
    final Map<TypeMirror, TypeParameterElement> mappings = new HashMap<TypeMirror, TypeParameterElement>();
    DeclaredType declaredType = (DeclaredType) sourceType.asType();
    for (TypeMirror typeMirror : declaredType.getTypeArguments()) {
        DeclaredType currentElement = declaredType;
        deepSearchTypes(currentElement, typeMirror, typeMirror, mappings);
    }
    final Types types = workingCopy.getTypes();

    final Map<IdentifierTree, Tree> original2Translated = new HashMap<IdentifierTree, Tree>();
    ErrorAwareTreeScanner<Void, Void> scanner = new ErrorAwareTreeScanner<Void, Void>() {

        @Override
        public Void visitIdentifier(IdentifierTree node, Void p) {
            Element element = workingCopy.getTrees().getElement(new TreePath(path, node));
            if (element != null && element.getKind() == ElementKind.TYPE_PARAMETER) {
                Element typeElement = types.asElement(element.asType());
                if (typeElement != null && typeElement.getKind() == ElementKind.TYPE_PARAMETER) {
                    TypeParameterElement parameterElement = (TypeParameterElement) typeElement;
                    Element genericElement = parameterElement.getGenericElement();
                    if (genericElement != member) {
                        // genericElement is niet gelijk aan het te verplaatsen element. Dus we moeten deze veranderen.
                        // Is het parameterElement gebruikt bij het maken van de superclass

                        Tree type;
                        TypeParameterElement target = mappings.get(parameterElement.asType());
                        if (target != null) {
                            type = make.Type(target.asType());
                        } else {
                            List<? extends TypeMirror> bounds = parameterElement.getBounds();
                            if (bounds.isEmpty()) {
                                type = make.Type("Object"); // NOI18N
                            } else {
                                type = make.Type(bounds.get(0));
                            }
                        }
                        original2Translated.put(node, type);
                    }
                }
            }
            return super.visitIdentifier(node, p);
        }
    };
    scanner.scan(tree, null);
    E result = (E) workingCopy.getTreeUtilities().translate(tree, original2Translated);
    return result;
}
 
Example 7
Project: incubator-netbeans   File: InstantRenamePerformer.java   Source Code and License Vote up 4 votes
private static boolean allowInstantRename(CompilationInfo info, Element e, ElementUtilities eu) {
    if(e.getKind() == ElementKind.FIELD) {
        VariableElement variableElement = (VariableElement) e;
        TypeElement typeElement = eu.enclosingTypeElement(e);
        
        boolean isProperty = false;
        try {
            CodeStyle codeStyle = CodeStyle.getDefault(info.getDocument());
            isProperty = eu.hasGetter(typeElement, variableElement, codeStyle);
            isProperty = isProperty || (!variableElement.getModifiers().contains(Modifier.FINAL) &&
                                eu.hasSetter(typeElement, variableElement, codeStyle));
        } catch (IOException ex) {
        }
        if(isProperty) {
            return false;
        }
    }
    if (org.netbeans.modules.java.editor.base.semantic.Utilities.isPrivateElement(e)) {
        return true;
    }
    
    if (isInaccessibleOutsideOuterClass(e, eu)) {
        return true;
    }
    
    //#92160: check for local classes:
    if (e.getKind() == ElementKind.CLASS) {//only classes can be local
        Element enclosing = e.getEnclosingElement();
        final ElementKind enclosingKind = enclosing.getKind();

        //#150352: parent is annonymous class
        if (enclosingKind == ElementKind.CLASS) {
            final Set<ElementKind> fm = EnumSet.of(ElementKind.METHOD, ElementKind.FIELD);
            if (enclosing.getSimpleName().length() == 0 || fm.contains(enclosing.getEnclosingElement().getKind())) {
                return true;
            }
        }


        return LOCAL_CLASS_PARENTS.contains(enclosingKind);
    }

    if (e.getKind() == ElementKind.TYPE_PARAMETER) {
        return true;
    }
    
    return false;
}
 
Example 8
Project: openjdk-jdk10   File: Symbol.java   Source Code and License Vote up 4 votes
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.TYPE_PARAMETER;
}