本文整理匯總了Java中javax.lang.model.element.ElementKind.CONSTRUCTOR屬性的典型用法代碼示例。如果您正苦於以下問題:Java ElementKind.CONSTRUCTOR屬性的具體用法?Java ElementKind.CONSTRUCTOR怎麽用?Java ElementKind.CONSTRUCTOR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.lang.model.element.ElementKind
的用法示例。
在下文中一共展示了ElementKind.CONSTRUCTOR屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ElementGrip
private ElementGrip(TreePathHandle delegateElementHandle, Element elm, CompilationInfo info) {
this.delegateElementHandle = delegateElementHandle;
this.handle = elm == null ? null : ElementHandle.create(elm);
if (elm != null) {
if (elm.getKind() == ElementKind.CLASS && elm.getSimpleName().length() == 0) {
this.toString = ((TypeElement) elm).asType().toString();
this.icon = ElementIcons.getElementIcon(elm.getKind(), elm.getModifiers());
} else if(elm.getKind() == ElementKind.ENUM
&& elm.getSimpleName().length() == 0
&& elm.getEnclosingElement() != null) {
final Element enclosingElement = elm.getEnclosingElement();
this.toString = enclosingElement.getSimpleName().toString();
this.icon = ElementIcons.getElementIcon(enclosingElement.getKind(), enclosingElement.getModifiers());
} else {
// workaround for issue 171692
this.toString = elm.getKind() != ElementKind.CONSTRUCTOR
? elm.getSimpleName().toString()
: elm.getEnclosingElement().getSimpleName().toString();
this.icon = ElementIcons.getElementIcon(elm.getKind(), elm.getModifiers());
// this.toString = ElementHeaders.getHeader(treePath, info, ElementHeaders.NAME);
}
}
this.fileObject = info.getFileObject();
}
示例2: findExecutableMember
private ExecutableElement findExecutableMember(TypeElement clazz, String methodName, List<TypeMirror> paramTypes, Types types) {
List<ExecutableElement> members = methodName.contentEquals(clazz.getSimpleName())
? ElementFilter.constructorsIn(clazz.getEnclosedElements())
: ElementFilter.methodsIn(clazz.getEnclosedElements());
outer: for (ExecutableElement ee : members) {
if (ee.getKind() == ElementKind.CONSTRUCTOR || methodName.contentEquals(ee.getSimpleName())) {
List<? extends TypeMirror> memberParamTypes = ((ExecutableType) ee.asType()).getParameterTypes();
if (memberParamTypes.size() == paramTypes.size()) {
Iterator<TypeMirror> it = paramTypes.iterator();
for (TypeMirror memberParamType : memberParamTypes) {
TypeMirror type = it.next();
if (types.isSameType(type, memberParamType)) {
continue outer;
}
}
return ee;
}
}
}
return null;
}
示例3: constructor
@Hint(id="org.netbeans.modules.java.hints.UtilityClass_2", displayName="#MSG_PublicConstructor", description="#HINT_PublicConstructor", category="api", enabled=false, severity=Severity.HINT, suppressWarnings="UtilityClassWithPublicConstructor")
@TriggerTreeKind(Kind.METHOD)
public static ErrorDescription constructor(HintContext ctx) {
CompilationInfo compilationInfo = ctx.getInfo();
TreePath treePath = ctx.getPath();
Element e = compilationInfo.getTrees().getElement(treePath);
if (e == null) {
return null;
}
if ( e.getKind() != ElementKind.CONSTRUCTOR
|| compilationInfo.getElementUtilities().isSynthetic(e)
|| (!e.getModifiers().contains(Modifier.PROTECTED) && !e.getModifiers().contains(Modifier.PUBLIC))) {
return null;
}
if (!isUtilityClass(compilationInfo, e.getEnclosingElement())) return null;
return ErrorDescriptionFactory.forName(ctx,
treePath,
NbBundle.getMessage(UtilityClass.class, "MSG_PublicConstructor"),
new FixImpl(false,
TreePathHandle.create(e, compilationInfo)
).toEditorFix());
}
示例4: visitNewClass
@Override
public Tree visitNewClass(NewClassTree node, Trees p) {
Tree t = super.visitNewClass(node, p);
// new class tree > expression statement tree > block. Does not accept anonymous classes for ctor references.
if (node.getClassBody() == null && singleStatementLambdaMethodBody == getCurrentPath().getParentPath().getParentPath().getLeaf()) {
Tree parent = getCurrentPath().getParentPath().getLeaf();
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null || el.getKind() != ElementKind.CONSTRUCTOR || !el.getEnclosingElement().getKind().isClass()) {
return t;
}
el = el.getEnclosingElement();
if (parent.getKind() == Tree.Kind.EXPRESSION_STATEMENT || parent.getKind() == Tree.Kind.RETURN) {
ExpressionTree et = node.getEnclosingExpression();
if (et != null) {
if (el.getModifiers().contains(Modifier.STATIC) || !isMeaninglessQualifier(new TreePath(getCurrentPath().getParentPath(), et))) {
return t;
}
}
foundConstructorReferenceCandidate = true;
}
}
return t;
}
示例5: attributeParamIdentifier
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
Symbol javadocSymbol = getElement(path);
if (javadocSymbol == null)
return null;
ElementKind kind = javadocSymbol.getKind();
List<? extends Symbol> params = List.nil();
if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
MethodSymbol ee = (MethodSymbol) javadocSymbol;
params = ptag.isTypeParameter()
? ee.getTypeParameters()
: ee.getParameters();
} else if (kind.isClass() || kind.isInterface()) {
ClassSymbol te = (ClassSymbol) javadocSymbol;
params = te.getTypeParameters();
}
for (Symbol param : params) {
if (param.getSimpleName() == ptag.getName().getName()) {
return param;
}
}
return null;
}
示例6: ConvertToLambdaPreconditionChecker
public ConvertToLambdaPreconditionChecker(TreePath pathToNewClassTree, CompilationInfo info) {
this.pathToNewClassTree = pathToNewClassTree;
this.newClassTree = (NewClassTree) pathToNewClassTree.getLeaf();
this.info = info;
this.types = info.getTypes();
Element el = info.getTrees().getElement(pathToNewClassTree);
if (el != null && el.getKind() == ElementKind.CONSTRUCTOR) {
createdClass = el.getEnclosingElement();
} else {
createdClass = null;
}
this.lambdaMethodTree = getMethodFromFunctionalInterface(this.pathToNewClassTree);
this.localScope = getScopeFromTree(this.pathToNewClassTree);
this.ownerClass = findFieldOwner();
}
示例7: visitNewClass
@Override
public State visitNewClass(NewClassTree node, Void p) {
scan(node.getEnclosingExpression(), p);
scan(node.getIdentifier(), p);
scan(node.getTypeArguments(), p);
for (Tree param : node.getArguments()) {
Map<VariableElement, State> origVariable2State = variable2State;
variable2State = new HashMap<>(variable2State);
scan(param, p);
mergeNonHypotheticalVariable2State(origVariable2State);
}
scan(node.getClassBody(), p);
Element invoked = info.getTrees().getElement(getCurrentPath());
if (invoked != null && invoked.getKind() == ElementKind.CONSTRUCTOR) {
recordResumeOnExceptionHandler((ExecutableElement) invoked);
}
return State.NOT_NULL;
}
示例8: visitNewClass
@Override
public Object visitNewClass(NewClassTree node, Object p) {
Element e = ci.getTrees().getElement(getCurrentPath());
if (e != null && e.getKind() == ElementKind.CONSTRUCTOR) {
addInstanceForConstructor(e);
}
Object r = scan(node.getEnclosingExpression(), p);
r = scanAndReduce(node.getIdentifier(), p, r);
r = scanAndReduce(node.getTypeArguments(), p, r);
r = scanAndReduce(node.getArguments(), p, r);
// switch context to the anonymous class
if (e != null) {
TypeElement saveType = enclosingType;
enclosingType = ci.getElementUtilities().enclosingTypeElement(e);
r = scanAndReduce(node.getClassBody(), p, r);
this.enclosingType = saveType;
}
return r;
}
示例9: isPossibleBuilderMethod
/**
* Return true if the possibleBuilderMethod matches the
* Style#attributeBuilder() and returns a class.
*
* TODO: may need to make this return true if the return type is an interface too...
*
* @param possibleBuilderMethod executableElement
*/
private static boolean isPossibleBuilderMethod(Element possibleBuilderMethod, boolean onValueType, ValueAttribute valueAttribute) {
if (possibleBuilderMethod.getKind() == ElementKind.METHOD) {
String detectedAttributeBuilder = valueAttribute.containingType.names()
.rawFromAttributeBuilder(possibleBuilderMethod.getSimpleName().toString());
if (detectedAttributeBuilder.isEmpty()) {
return false;
}
ExecutableElement candidateMethod = (ExecutableElement) possibleBuilderMethod;
return possibleBuilderMethod.getModifiers().containsAll(
Arrays.asList(Modifier.STATIC, Modifier.PUBLIC))
&& candidateMethod.getParameters().isEmpty()
&& candidateMethod
.getReturnType().getKind()
== TypeKind.DECLARED
&& ((DeclaredType) candidateMethod.getReturnType())
.asElement().getKind() == ElementKind.CLASS;
} else if (!onValueType && possibleBuilderMethod.getKind() == ElementKind.CONSTRUCTOR) {
if (!valueAttribute.containingType.names().newTokenInAttributeBuilder()) {
return false;
}
ExecutableElement candidateConstructor = (ExecutableElement) possibleBuilderMethod;
return candidateConstructor.getModifiers().contains(Modifier.PUBLIC)
&& candidateConstructor.getTypeParameters().isEmpty();
}
return false;
}
示例10: visitNewClass
public Boolean visitNewClass(NewClassTree node, ConstructorData p) {
TypeElement oldTarget = referenceTarget;
super.visitNewClass(node, p);
Element invoked = info.getTrees().getElement(getCurrentPath());
if (invoked != null && invoked.getKind() == ElementKind.CONSTRUCTOR) {
recordResumeOnExceptionHandler((ExecutableElement) invoked);
}
referenceTarget = oldTarget;
return null;
}
示例11: WhereUsedQueryUI
private WhereUsedQueryUI(TreePathHandle handle, Element el, List<Pair<Pair<String, Icon>, TreePathHandle>> classes) {
this.query = new WhereUsedQuery(Lookups.singleton(handle));
this.element = handle;
if (UIUtilities.allowedElementKinds.contains(el.getKind())) {
elementHandle = ElementHandle.create(el);
}
kind = el.getKind();
if(kind == ElementKind.CONSTRUCTOR) {
name = el.getEnclosingElement().getSimpleName().toString();
} else {
name = el.getSimpleName().toString();
}
this.classes = classes;
}
示例12: getStringElements
private Element[] getStringElements (Element stringElement) {
List<? extends Element> members = ((TypeElement)stringElement).getEnclosedElements();
Element[] result = new Element[3];
for (Element member : members) {
if (member.getKind() == ElementKind.METHOD && "length".contentEquals(member.getSimpleName())) {
result[0] = member;
}
if (member.getKind() == ElementKind.CONSTRUCTOR) {
List<? extends VariableElement> params = ((ExecutableElement)member).getParameters();
if (params.size() == 1) {
TypeMirror type = params.get(0).asType();
if (type.getKind() == TypeKind.DECLARED) {
TypeElement element = (TypeElement)((DeclaredType)type).asElement();
if (java.lang.StringBuilder.class.getName().contentEquals(element.getQualifiedName())) {
result[1] = element;
}
}
}
}
if (member.getKind() == ElementKind.FIELD) {
VariableElement ve = (VariableElement) member;
if ("value".contentEquals(ve.getSimpleName())) {
result[2] = member;
}
}
}
return result;
}
示例13: visitNewClass
@Override
public Boolean visitNewClass(NewClassTree tree, Stack<Tree> d) {
Element el = info.getTrees().getElement(getCurrentPath());
if (el != null && el.getKind() == ElementKind.CONSTRUCTOR) {
for (TypeMirror m : ((ExecutableElement) el).getThrownTypes()) {
addToExceptionsMap(m, tree);
}
}
return null;
}
示例14: addInstanceOfParameterOwner
private void addInstanceOfParameterOwner(Element el) {
while (el != null && el.getKind() != ElementKind.CONSTRUCTOR && el.getKind() != ElementKind.METHOD && !el.getKind().isClass() && !el.getKind().isInterface()) {
el = el.getEnclosingElement();
}
if (el == null || el instanceof TypeElement || el == enclosingElement) {
return;
}
addInstanceForMemberOf(el);
}
示例15: generatePresenterBinderClass
private static String generatePresenterBinderClass(final String builder, String targetClass, final Field field) {
TypeElement clazz = (TypeElement) ((DeclaredType) field.getClazz()).asElement();
String s = "\tpublic class " + field.getGeneratedClassName() + " extends PresenterField {\n" +
"\t\tpublic " + field.getGeneratedClassName() + "() {\n" +
"\t\t\tsuper(" + field.getTag() + ", PresenterType." + field.getType().name() + ", " + field.getPresenterId() + ", " + clazz + ".class);\n" +
"\t\t}\n" +
"\n" +
"\t\[email protected]\n" +
"\t\tpublic void bind(Object target, MvpPresenter presenter) {\n" +
"\t\t\t((" + targetClass + ") target)." + field.getName() + " = (" + clazz.getQualifiedName() + ") presenter;\n" +
"\t\t}\n";
s += "\n" +
"\t\[email protected]\n" +
"\t\tpublic MvpPresenter<?> providePresenter(Object delegated) {\n";
if (field.getPresenterProviderMethodName() != null) {
s+= "\t\t\treturn ((" + targetClass + ") delegated)." + field.getPresenterProviderMethodName() + "();\n";
} else {
boolean hasEmptyConstructor = false;
List<? extends Element> enclosedElements = clazz.getEnclosedElements();
for (Element enclosedElement : enclosedElements) {
if (enclosedElement.getKind() == ElementKind.CONSTRUCTOR) {
List<? extends VariableElement> parameters = ((ExecutableElement) enclosedElement).getParameters();
if (parameters == null || parameters.isEmpty()) {
hasEmptyConstructor = true;
break;
}
}
}
if (hasEmptyConstructor) {
s += "\t\t\treturn new " + clazz.getQualifiedName() + "();\n";
} else {
s += "\t\t\tthrow new IllegalStateException(\"" + clazz.getSimpleName() + " has not default constructor. You can apply @ProvidePresenter to some method which will construct Presenter. Also you can make it default constructor\");\n";
}
}
s += "\t\t}\n";
if (field.getPresenterTagProviderMethodName() != null) {
s += "\n" +
"\t\[email protected]\n" +
"\t\tpublic String getTag(Object delegated) {\n" +
"\t\t\treturn String.valueOf(((" + targetClass + ") delegated)." + field.getPresenterTagProviderMethodName() + "());\n" +
"\t\t}\n";
}
s += "\t}\n" +
"\n";
return builder + s;
}