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

The following examples show how to use javax.lang.model.element.ElementKind#TYPE_PARAMETER . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: WhereUsedPanelVariable.java    License: Apache License 2.0 6 votes vote down vote up
@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
Source Project: featured   File: Names.java    License: Apache License 2.0 6 votes vote down vote up
private TypeName getFeatureParameterTypeVariableName(DeclaredType featureType,
                                                     int featureParameterIndex) {
    Element paramElem = getFeatureParameterElement(featureType, featureParameterIndex);
    if (paramElem == null) {
        return null;
    }

    if (paramElem.getKind() == ElementKind.TYPE_PARAMETER) {
        return TypeVariableName.get((TypeVariable) paramElem.asType());

    } else if (paramElem.getKind() == ElementKind.CLASS) {
        return TypeName.get(paramElem.asType());
    }

    return null;
}
 
Example 3
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
Source Project: jdk8u60   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
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
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 6
Source Project: buck   File: TreeBackedTrees.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Tree getTree(Element element) {
  if (element.getKind() == ElementKind.TYPE_PARAMETER) {
    // This is a weird javac behavior that we're emulating.
    return null;
  }

  TreePath path = getPath(element);
  if (path == null) {
    return null;
  }
  return path.getLeaf();
}
 
Example 7
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 8
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 9
Source Project: hottub   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 10
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 11
Source Project: openjdk-8   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 12
Source Project: featured   File: Names.java    License: Apache License 2.0 5 votes vote down vote up
private ClassName getFeatureParameterClass(FeatureNode featureNode, int parameterIndex) {
    TypeMirror superClass = featureNode.getElement().getSuperclass();
    if (superClass.getKind() != TypeKind.DECLARED) {
        throw new IllegalArgumentException(
                "Check model validator. It must check feature super class.");
    }

    Element argElem = getFeatureParameterElement((DeclaredType) superClass, parameterIndex);
    if (argElem == null || argElem.getKind() == ElementKind.TYPE_PARAMETER) {
        return null;
    }
    return ClassName.get((TypeElement) argElem);
}
 
Example 13
Source Project: featured   File: Names.java    License: Apache License 2.0 5 votes vote down vote up
private TypeVariableName getParameterTypeVariableName(FeatureNode featureNode,
                                                      int parameterIndex) {
    TypeMirror type = featureNode.getElement().asType();
    if (type.getKind() != TypeKind.DECLARED) {
        throw new IllegalArgumentException("FeatureNode type is not supported: " + featureNode);
    }
    Element paramElem = getFeatureParameterElement((DeclaredType) type, parameterIndex);
    if (paramElem.getKind() == ElementKind.TYPE_PARAMETER) {
        return TypeVariableName.get((TypeVariable) paramElem.asType());
    }
    throw new IllegalArgumentException(
            "Expecting paramElem of kind TYPE_PARAMETER, while received" + paramElem);
}
 
Example 14
Source Project: netbeans   File: PullUpTransformer.java    License: Apache License 2.0 4 votes vote down vote up
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 15
Source Project: netbeans   File: InstantRenamePerformer.java    License: Apache License 2.0 4 votes vote down vote up
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 16
@Override
public ElementKind getKind()
{
	return ElementKind.TYPE_PARAMETER;
}
 
Example 17
@Override
public ElementKind getKind() {
  return ElementKind.TYPE_PARAMETER;
}
 
Example 18
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.TYPE_PARAMETER;
}
 
Example 19
Source Project: j2objc   File: ElementUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isTypeParameterElement(Element e) {
  return e.getKind() == ElementKind.TYPE_PARAMETER;
}
 
Example 20
@Override
public ElementKind getKind() {
  return ElementKind.TYPE_PARAMETER;
}