本文整理汇总了Java中javax.lang.model.element.ElementKind.METHOD属性的典型用法代码示例。如果您正苦于以下问题:Java ElementKind.METHOD属性的具体用法?Java ElementKind.METHOD怎么用?Java ElementKind.METHOD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.lang.model.element.ElementKind
的用法示例。
在下文中一共展示了ElementKind.METHOD属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFragment
private CharSequence getFragment(Element e) {
StringBuilder sb = new StringBuilder();
if (!e.getKind().isClass() && !e.getKind().isInterface()) {
if (e.getKind() == ElementKind.CONSTRUCTOR) {
sb.append(e.getEnclosingElement().getSimpleName());
} else {
sb.append(e.getSimpleName());
}
if (e.getKind() == ElementKind.METHOD || e.getKind() == ElementKind.CONSTRUCTOR) {
ExecutableElement ee = (ExecutableElement)e;
sb.append('('); //NOI18N
for (Iterator<? extends VariableElement> it = ee.getParameters().iterator(); it.hasNext();) {
VariableElement param = it.next();
appendType(sb, param.asType(), ee.isVarArgs() && !it.hasNext());
if (it.hasNext())
sb.append(", ");
}
sb.append(')'); //NOI18N
}
}
return sb;
}
示例2: create
public static <T extends Element> MemberInfo<ElementHandle<T>> create(T el, CompilationInfo c) {
String format = ElementHeaders.NAME;
Group g = Group.TYPE;
if (el.getKind() == ElementKind.FIELD) {
format += " : " + ElementHeaders.TYPE; // NOI18N
g=Group.FIELD;
} else if (el.getKind() == ElementKind.METHOD) {
format += ElementHeaders.PARAMETERS + " : " + ElementHeaders.TYPE; // NOI18N
g=Group.METHOD;
} else if (el.getKind() == ElementKind.CONSTRUCTOR) {
format += ElementHeaders.PARAMETERS;
g=Group.METHOD;
}
MemberInfo<ElementHandle<T>> mi = new MemberInfo<ElementHandle<T>>(ElementHandle.create(el), el.getSimpleName().toString(), ElementHeaders.getHeader(el, c, format), ElementIcons.getElementIcon(el.getKind(), el.getModifiers()));
mi.modifiers = el.getModifiers();
mi.group = g;
return mi;
}
示例3: isElegibleAccessorMethod
private static boolean isElegibleAccessorMethod(Element element) {
if (element.getKind() != ElementKind.METHOD) {
return false;
}
if (element.getModifiers().contains(Modifier.STATIC)) {
return false;
}
switch (element.getSimpleName().toString()) {
case HASH_CODE_METHOD:
case TO_STRING_METHOD:
return false;
default:
}
String definitionType = element.getEnclosingElement().toString();
if (definitionType.equals(Object.class.getName())
|| definitionType.equals(Proto.ORDINAL_VALUE_INTERFACE_TYPE)
|| definitionType.equals(Proto.PARCELABLE_INTERFACE_TYPE)) {
return false;
}
return true;
}
示例4: visitMethodInvocation
@Override
public Boolean visitMethodInvocation(MethodInvocationTree tree, Stack<Tree> d) {
Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), tree.getMethodSelect()));
if (el == null) {
System.err.println("Warning: decl == null");
System.err.println("tree=" + tree);
}
if (el != null && el.getKind() == ElementKind.METHOD) {
for (TypeMirror m : ((ExecutableElement) el).getThrownTypes()) {
addToExceptionsMap(m, tree);
}
}
super.visitMethodInvocation(tree, d);
return null;
}
示例5: findAttribute
private static ExecutableElement findAttribute(Element e, String attrName) {
for (Element attr : e.getEnclosedElements()) {
if (attr.getKind() == ElementKind.METHOD && attr.getSimpleName().contentEquals(attrName)) {
return (ExecutableElement)attr;
}
}
return null;
}
示例6: getExecutableElements
List<ExecutableElement> getExecutableElements() {
List<Element> enclosed = getEnclosedElements();
List<ExecutableElement> executable = new ArrayList<>(enclosed.size());
for (Element element : enclosed) {
if (element.getKind() == ElementKind.METHOD) {
executable.add((ExecutableElement) element);
}
}
return executable;
}
示例7: getDescriptorElement
/**
* Find the element of the method descriptor associated to the functional interface.
*
* @param origin functional interface element
* @return associated method descriptor element or <code>null</code> if the <code>origin</code> is not a functional interface.
* @since 2.14
*/
public ExecutableElement getDescriptorElement(TypeElement origin) {
com.sun.tools.javac.code.Types types = com.sun.tools.javac.code.Types.instance(info.impl.getJavacTask().getContext());
if (types.isFunctionalInterface((TypeSymbol)origin)) {
Symbol sym = types.findDescriptorSymbol((TypeSymbol)origin);
if (sym != null && sym.getKind() == ElementKind.METHOD) {
return (ExecutableElement)sym;
}
}
return null;
}
示例8: cbMemberActionPerformed
private void cbMemberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbMemberActionPerformed
Object o = cbMember.getSelectedItem();
if (o != null && !disableUpdates) {
MemberDescription md = (MemberDescription)o;
if (md.kind == ElementKind.METHOD) {
changedOptions.put(PropertyNames.JSHELL_FROM_FIELD, null);
changedOptions.put(PropertyNames.JSHELL_FROM_METHOD, md.name);
} else {
changedOptions.put(PropertyNames.JSHELL_FROM_METHOD, null);
changedOptions.put(PropertyNames.JSHELL_FROM_FIELD, md.name);
}
message = null;
storeChanges();
}
}
示例9: process
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
for (Element e : roundEnv.getElementsAnnotatedWith(RandomlyFails.class)) {
Element typeEl = e.getKind() == ElementKind.METHOD ? e.getEnclosingElement() : e;
TypeMirror nbTestCaseType = processingEnv.getElementUtils().
getTypeElement(NbTestCase.class.getName()).asType();
if (!processingEnv.getTypeUtils().isAssignable(typeEl.asType(), nbTestCaseType)) {
processingEnv.getMessager().printMessage(Kind.ERROR, "@RandomlyFails must be used on NbTestCase subclasses", e);
}
}
return true;
}
return false;
}
示例10: 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);
}
示例11: detectMethodsForClass
private List<int[]> detectMethodsForClass(CompilationInfo info, Document document, TreePath clazz, List<TypeElement> superTypes, TypeElement thisType) {
List<int[]> highlights = new ArrayList<int[]>();
ClassTree clazzTree = (ClassTree) clazz.getLeaf();
TypeElement jlObject = info.getElements().getTypeElement("java.lang.Object");
OUTER: for (Tree member: clazzTree.getMembers()) {
if (isCancelled()) {
return null;
}
if (member.getKind() == Kind.METHOD) {
TreePath path = new TreePath(clazz, member);
Element el = info.getTrees().getElement(path);
if (el.getKind() == ElementKind.METHOD) {
for (TypeElement superType : superTypes) {
for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(superType))) {
if (info.getElements().overrides((ExecutableElement) el, ee, thisType) && (superType.getKind().isClass() || !ee.getEnclosingElement().equals(jlObject))) {
Token t = Utilities.getToken(info, document, path);
if (t != null) {
highlights.add(new int[] {t.offset(null), t.offset(null) + t.length()});
}
continue OUTER;
}
}
}
}
}
}
return highlights;
}
示例12: visitExecutable
@Override
public ImmutableSet.Builder<MethodSignature> visitExecutable(final ExecutableElement element, final ImmutableSet.Builder<MethodSignature> builder) {
if (element.getKind() == ElementKind.METHOD) {
builder.add(MethodSignature.fromExecutableElementWithSubstitutor(element, Inventory.this::applyTypeSubstitution));
}
return builder;
}
示例13: handleMethodInvocation
private List<ErrorDescription> handleMethodInvocation(CompilationInfo info, TreePath treePath) {
Element el = info.getTrees().getElement(treePath);
if (el == null || (el.getKind() != ElementKind.CONSTRUCTOR && el.getKind() != ElementKind.METHOD)) {
return null;
}
MethodInvocationTree mit = (MethodInvocationTree) treePath.getLeaf();
ExecutableElement ee = (ExecutableElement) el;
if (ee.getParameters().size() != mit.getArguments().size()) {
//should not happen?
return null;
}
List<ErrorDescription> result = new ArrayList<ErrorDescription>();
for (int cntr = 0; cntr < ee.getParameters().size(); cntr++) {
String declarationName = ee.getParameters().get(cntr).getSimpleName().toString();
ExpressionTree arg = mit.getArguments().get(cntr);
String actualName = getName(arg);
if (isConflicting(info, declarationName, actualName)) {
long start = info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), arg);
long end = info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), arg);
if (start != (-1) && end != (-1)) {
result.add(ErrorDescriptionFactory.createErrorDescription(getSeverity().toEditorSeverity(), "Suspicious names combination", info.getFileObject(), (int) start, (int) end));
}
}
}
return result;
}
示例14: N
public N(JShellEnvironment env, SnippetHandle handle) {
super(Children.LEAF,
Lookups.fixed(
env,
handle,
env,
env.getConsoleFile()
)
);
this.snipHandle = handle;
this.env = env;
Snippet.Kind k = handle.getKind();
switch (k) {
case TYPE_DECL:
nodeKind = ElementKind.CLASS;
break;
case METHOD:
nodeKind = ElementKind.METHOD;
break;
case VAR:
nodeKind = ElementKind.FIELD;
break;
default:
throw new IllegalArgumentException();
}
Snippet s = handle.getSnippet();
String dispName = null;
switch (s.kind()) {
case TYPE_DECL:
dispName = handle.text();
break;
case METHOD: {
MethodSnippet m = (MethodSnippet)s;
dispName = m.name() + "(" + m.parameterTypes() + ")"; // NOI18N
htmlDisplayName = m.name() + "(<font color=\"" +
getHtmlColor(typeColor, DEFAULT_TYPE_COLOR) + "\">"+
m.parameterTypes() +
"</font>)";
break;
}
case VAR: {
VarSnippet v = (VarSnippet)s;
dispName = v.name() + " : " + v.typeName(); // NOI18N
htmlDisplayName = v.name() + " : <font color=\"" +
getHtmlColor(typeColor, DEFAULT_TYPE_COLOR) + "\">"+
v.typeName() +
"</font>";
dispName = handle.text();
break;
}
default:
throw new AssertionError(s.kind().name());
}
if (htmlDisplayName == null) {
htmlDisplayName = dispName;
}
setDisplayName(dispName);
}
示例15: computeFixes
protected static Fix computeFixes(CompilationInfo info, TreePath treePath, int[] bounds, int[] kind, String[] simpleName) {
if (treePath.getLeaf().getKind() != Kind.MEMBER_SELECT) {
return null;
}
MemberSelectTree mst = (MemberSelectTree)treePath.getLeaf();
Tree expression = mst.getExpression();
TreePath expr = new TreePath(treePath, expression);
TypeMirror tm = info.getTrees().getTypeMirror(expr);
if (!Utilities.isValidType(tm)) {
return null;
}
Element el = info.getTypes().asElement(tm);
if (el == null || (!el.getKind().isClass() && !el.getKind().isInterface())) {
return null;
}
TypeElement type = (TypeElement)el;
if (isError(type)) {
return null;
}
Name idName = null;
if (expression.getKind() == Kind.MEMBER_SELECT) {
MemberSelectTree exprSelect = (MemberSelectTree)expression;
idName = exprSelect.getIdentifier();
}
if (expression.getKind() == Kind.IDENTIFIER) {
IdentifierTree idt = (IdentifierTree)expression;
idName = idt.getName();
}
if (idName != null) {
if (idName.equals(type.getSimpleName())) {
return null;
}
if (idName.equals(type.getQualifiedName())) {
return null;
}
}
Element used = info.getTrees().getElement(treePath);
if (used == null || !used.getModifiers().contains(Modifier.STATIC)) {
return null;
}
if (isError(used)) {
return null;
}
if (used.getKind().isField()) {
kind[0] = 0;
} else {
if (used.getKind() == ElementKind.METHOD) {
kind[0] = 1;
} else {
kind[0] = 2;
}
}
simpleName[0] = used.getSimpleName().toString();
return new FixImpl(info, expr, type).toEditorFix();
}