當前位置: 首頁>>代碼示例>>Java>>正文


Java ElementFilter.methodsIn方法代碼示例

本文整理匯總了Java中javax.lang.model.util.ElementFilter.methodsIn方法的典型用法代碼示例。如果您正苦於以下問題:Java ElementFilter.methodsIn方法的具體用法?Java ElementFilter.methodsIn怎麽用?Java ElementFilter.methodsIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.util.ElementFilter的用法示例。


在下文中一共展示了ElementFilter.methodsIn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hasTestableMethods

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
/**
 */
private boolean hasTestableMethods(TypeElement classElem) {
    List<? extends Element> enclosedElems = classElem.getEnclosedElements();
    if (enclosedElems.isEmpty()) {
        return false;
    }
    
    List<ExecutableElement> methods = ElementFilter.methodsIn(enclosedElems);
    if (methods.isEmpty()) {
        return false;
    }
    
    for (ExecutableElement method : methods) {
        if (isMethodTestable(method)) {
            return true;
        }
    }
    
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:TestGeneratorSetup.java

示例2: run

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public void run(WorkingCopy copy) throws Exception {
    copy.toPhase(JavaSource.Phase.RESOLVED);
    TreePath tp = copy.getTreeUtilities().pathFor(offset);
    assertTrue(TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind()));
    ClassTree ct = (ClassTree)tp.getLeaf();
    TypeElement te = (TypeElement)copy.getTrees().getElement(tp);
    DeclaredType dt = (DeclaredType) copy.getTreeUtilities().parseType("java.util.List<java.lang.String>", te);
    TypeElement list = copy.getElements().getTypeElement("java.util.List");
    ExecutableElement ee = null;
    for (ExecutableElement m : ElementFilter.methodsIn(list.getEnclosedElements())) {
        if (m.getSimpleName().contentEquals("toArray") && !m.getTypeParameters().isEmpty()) {
            ee = m;
        }
    }
    assertNotNull(ee);
    GeneratorUtilities utilities = GeneratorUtilities.get(copy);
    assertNotNull(utilities);
    ClassTree newCt = utilities.insertClassMembers(ct, Collections.singletonList(utilities.createMethod(dt, ee)));
    copy.rewrite(ct, newCt);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:GeneratorUtilitiesTest.java

示例3: validate

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public void validate(CompilationInfo info) {
    TypeElement test = info.getElements().getTypeElement("test.Test");
    
    boolean foundRunMethod = false;
    
    for (ExecutableElement ee : ElementFilter.methodsIn(test.getEnclosedElements())) {
        if ("run".equals(ee.getSimpleName().toString())) {
            if (ee.getParameters().isEmpty()) {
                assertFalse(foundRunMethod);
                foundRunMethod = true;
            }
        }
    }
    
    assertTrue(foundRunMethod);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:GeneratorUtilsTest.java

示例4: getMethodByName

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static MethodTree getMethodByName(CompilationController controller, String methodName) {
    TypeElement classElement = getTopLevelClassElement(controller);
    List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements());
    List<MethodTree> found = new ArrayList<MethodTree>();
    for (ExecutableElement method : methods) {
        if (method.getSimpleName().toString().equals(methodName)) {
            found.add(controller.getTrees().getTree(method));
        }
    }
    if (found.size() > 1) {
        throw new IllegalArgumentException("Unexpected overloading methods of '" + methodName + "' found.");
    } else if (found.size() == 1) {
        return found.get(0);
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:JavaSourceHelper.java

示例5: execsIn

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private static Iterable<ExecutableElement> execsIn(CompilationInfo info, TypeElement e, boolean constr, String name) {
    if (constr) {
        return ElementFilter.constructorsIn(info.getElements().getAllMembers(e));
    }
    
    List<ExecutableElement> result = new LinkedList<ExecutableElement>();
    
    for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(e))) {
        if (name.equals(ee.getSimpleName().toString())) {
            result.add(ee);
        }
    }
    
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:CreateElementUtilities.java

示例6: methodsIn

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
/**
 * Returns all public methods of a type element, whether inherited or
 * declared directly. It excludes methods of {@link Object} that are useless
 * for bean patterns.
 * @param clazz class to search
 * @param javac javac
 * @return list of public methods
 */
public static List<? extends ExecutableElement> methodsIn(TypeElement clazz, CompilationInfo javac) {
    List<ExecutableElement> result = ElementFilter.methodsIn(javac.getElements().getAllMembers(clazz));
    final TypeElement objectElement = javac.getElements().getTypeElement("java.lang.Object"); // NOI18N
    for (int i = result.size() - 1; i >= 0; i--) {
        ExecutableElement method = result.get(i);
        if (!method.getModifiers().contains(Modifier.PUBLIC) || objectElement == method.getEnclosingElement()) {
            result.remove(i);
        }
    }
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:BeanUtils.java

示例7: findDuplicateSubMethods

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private List<ExecutableElement> findDuplicateSubMethods(TypeElement enclosingTypeElement, ExecutableElement method, ParameterInfo[] paramTable, AtomicBoolean cancel) {
    List<ExecutableElement> returnmethods = new LinkedList<ExecutableElement>();
    Set<ElementHandle<TypeElement>> subTypes = RefactoringUtils.getImplementorsAsHandles(javac.getClasspathInfo().getClassIndex(), javac.getClasspathInfo(), enclosingTypeElement, cancel);
    for (ElementHandle<TypeElement> elementHandle : subTypes) {
        TypeElement subtype = elementHandle.resolve(javac);
        if(subtype != null) {
            List<ExecutableElement> methods = ElementFilter.methodsIn(javac.getElements().getAllMembers(subtype));
            for (ExecutableElement exMethod : methods) {
                if (!exMethod.equals(method)) {
                    if (exMethod.getSimpleName().equals(method.getSimpleName())
                            && exMethod.getParameters().size() == paramTable.length) {
                        boolean sameParameters = true;
                        for (int j = 0; j < exMethod.getParameters().size(); j++) {
                            TypeMirror exType = ((VariableElement) exMethod.getParameters().get(j)).asType();
                            String type = paramTable[j].getType();
                            if (type == null || type.length() == 0) {
                                sameParameters = false;
                            } else {
                                TypeMirror paramType = javac.getTreeUtilities().parseType(type, enclosingTypeElement);
                                if (!javac.getTypes().isSameType(exType, paramType)) {
                                    sameParameters = false;
                                }
                            }
                        }
                        if (sameParameters) {
                            returnmethods.add(exMethod);
                        }
                    }
                }
            }
        }
    }
    return returnmethods;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:ChangeParametersPlugin.java

示例8: getSetter

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static String getSetter(Element element, Elements elements) {
    TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();

    String elementName = element.getSimpleName().toString();
    String elementNameLowerCase = elementName.toLowerCase();

    List<String> possibleMethodNames = new ArrayList<>();
    possibleMethodNames.add("set" + elementNameLowerCase);

    // Handle the case where variables are named in the form mVariableName instead of just variableName
    if (elementName.length() > 1 && elementName.charAt(0) == 'm' && (elementName.charAt(1) >= 'A' && elementName.charAt(1) <= 'Z')) {
        possibleMethodNames.add("set" + elementNameLowerCase.substring(1));
    }

    List<? extends Element> elementMembers = elements.getAllMembers(enclosingElement);
    List<ExecutableElement> elementMethods = ElementFilter.methodsIn(elementMembers);
    for (ExecutableElement methodElement : elementMethods) {
        String methodNameString = methodElement.getSimpleName().toString();
        String methodNameLowerCase = methodNameString.toLowerCase();

        if (possibleMethodNames.contains(methodNameLowerCase)) {
            if (methodElement.getParameters().size() == 1) {
                if (methodElement.getParameters().get(0).asType().toString().equals(element.asType().toString())) {
                    return methodNameString;
                }
            }
        }
    }

    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:JsonFieldHolder.java

示例9: getImplementationOf

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private static ExecutableElement getImplementationOf(CompilationInfo info, ExecutableElement overridee, TypeElement implementor) {
    for (ExecutableElement overrider : ElementFilter.methodsIn(implementor.getEnclosedElements())) {
        if (info.getElements().overrides(overrider, overridee, implementor)) {
            return overrider;
        }
    }

    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:ComputeOverriders.java

示例10: write

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public void write(OutputStream o, TypeElement clazz) throws Util.Exit {
    try {
        String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS);
        PrintWriter pw = wrapWriter(o);
        pw.println(guardBegin(cname));
        pw.println(cppGuardBegin());

        /* Write statics. */
        List<VariableElement> classfields = getAllFields(clazz);

        for (VariableElement v: classfields) {
            if (!v.getModifiers().contains(Modifier.STATIC))
                continue;
            String s = null;
            s = defineForStatic(clazz, v);
            if (s != null) {
                pw.println(s);
            }
        }

        /* Write methods. */
        List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements());
        for (ExecutableElement md: classmethods) {
            if(md.getModifiers().contains(Modifier.NATIVE)){
                TypeMirror mtr = types.erasure(md.getReturnType());
                String sig = signature(md);
                TypeSignature newtypesig = new TypeSignature(elems);
                CharSequence methodName = md.getSimpleName();
                boolean longName = false;
                for (ExecutableElement md2: classmethods) {
                    if ((md2 != md)
                        && (methodName.equals(md2.getSimpleName()))
                        && (md2.getModifiers().contains(Modifier.NATIVE)))
                        longName = true;

                }
                pw.println("/*");
                pw.println(" * Class:     " + cname);
                pw.println(" * Method:    " +
                           mangler.mangle(methodName, Mangle.Type.FIELDSTUB));
                pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr));
                pw.println(" */");
                pw.println("JNIEXPORT " + jniType(mtr) +
                           " JNICALL " +
                           mangler.mangleMethod(md, clazz,
                                               (longName) ?
                                               Mangle.Type.METHOD_JNI_LONG :
                                               Mangle.Type.METHOD_JNI_SHORT));
                pw.print("  (JNIEnv *, ");
                List<? extends VariableElement> paramargs = md.getParameters();
                List<TypeMirror> args = new ArrayList<TypeMirror>();
                for (VariableElement p: paramargs) {
                    args.add(types.erasure(p.asType()));
                }
                if (md.getModifiers().contains(Modifier.STATIC))
                    pw.print("jclass");
                else
                    pw.print("jobject");

                for (TypeMirror arg: args) {
                    pw.print(", ");
                    pw.print(jniType(arg));
                }
                pw.println(");" + lineSep);
            }
        }
        pw.println(cppGuardEnd());
        pw.println(guardEnd(cname));
    } catch (TypeSignature.SignatureException e) {
        util.error("jni.sigerror", e.getMessage());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:73,代碼來源:JNI.java

示例11: getMethod

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static ExecutableElement[] getMethod(TypeElement clazz, String methodName) {
    List<ExecutableElement> methods = new ArrayList<ExecutableElement>();

    for (ExecutableElement method : ElementFilter.methodsIn(clazz.getEnclosedElements())) {
        if (method.getSimpleName().contentEquals(methodName)) {
            methods.add(method);
        }
    }

    return methods.toArray(new ExecutableElement[methods.size()]);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:ModelUtils.java

示例12: fillInMethods

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private static void fillInMethods(Iterable<? extends TypeElement> types, Map<ElementHandle<TypeElement>, List<ElementHandle<ExecutableElement>>> methods) {
    for (TypeElement te : types) {
        List<ElementHandle<ExecutableElement>> l = new LinkedList<ElementHandle<ExecutableElement>>();

        for (ExecutableElement ee : ElementFilter.methodsIn(te.getEnclosedElements())) {
            l.add(ElementHandle.create(ee));
        }

        methods.put(ElementHandle.create(te), l);

        fillInMethods(ElementFilter.typesIn(te.getEnclosedElements()), methods);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:ComputeOverriders.java

示例13: complete

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
@Override
public List<? extends CompletionItem> complete() {
    // attempt to find methods in the controller
    TypeElement el = controller.resolve(ctx.getCompilationInfo());
    TypeElement eventType = event.getEventType().resolve(ctx.getCompilationInfo());
    if (el == null || eventType == null) {
        return null;
    }

    List<ExecutableElement> allMethods = ElementFilter.methodsIn(ctx.getCompilationInfo().getElements().getAllMembers(el));
    List<CompletionItem> items = new ArrayList<CompletionItem>();

    for (ExecutableElement em : allMethods) {
        if (!FxClassUtils.isFxmlAccessible(em)) {
            continue;
        }
        
        if (em.getParameters().size() > 1 || em.getReturnType().getKind() != TypeKind.VOID) {
            continue;
        }
        if (!em.getParameters().isEmpty()) {
            VariableElement v = em.getParameters().get(0);
            if (!ctx.getCompilationInfo().getTypes().isAssignable(v.asType(), eventType.asType())) {
                continue;
            }
        } else if (!FxClassUtils.isFxmlAnnotated(em)) {
            // require FXML annotation, there are many void no-arg methods.
            continue;
        }
        items.add(new ValueItem(ctx, em.getSimpleName().toString(), "#", ICON_RESOURCE));
    }
    return items;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:HandlerMethodCompleter.java

示例14: resolveMethodByName

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
/**
     * Resolves a method by its name, signature and parent class
     * @param parentClass The parent class
     * @param methodName The method name
     * @param signature The VM signature of the method
     * @return Returns an ExecutableElement representing the method or null
     */
    public static ExecutableElement resolveMethodByName(CompilationInfo ci,
            TypeElement parentClass, String methodName, String signature) {
        // TODO: static initializer
        if ((parentClass == null) || (methodName == null)) {
            return null;
        }

        ExecutableElement foundMethod = null;
        boolean found = false;

        List<ExecutableElement> methods;

        if (methodName.equals(VM_CONSTRUCTUR_SIG)) {
            methods = ElementFilter.constructorsIn(ci.getElements().getAllMembers(parentClass));

        //    } else if (methodName.equals(VM_INITIALIZER_SIG)) {
        //      methods = constructorsIn(parentClass.getEnclosedElements());
        } else {
            // retrieve all defined methods
            methods = ElementFilter.methodsIn(ci.getElements().getAllMembers(parentClass));
        }

// loop over all methods
        for (ExecutableElement method : methods) {
            // match the current method against the required method name and signature
            if (methodNameMatch(methodName, method)) {
                if (signature != null && methodSignatureMatch(ci, signature, method)) {
                    foundMethod = method;
                    found = true;
                    break;
                }
                foundMethod = method; // keeping the track of the closest match
            }
        }

        if (!found) {
            ProfilerLogger.debug("Could not find exact signature match, opening at first method with same name: " + foundMethod); // NOI18N
        }

        return foundMethod;
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:49,代碼來源:ElementUtilitiesEx.java

示例15: getGetter

import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static String getGetter(Element element, Elements elements) {
    TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();

    TypeKind elementTypeKind = element.asType().getKind();

    String elementName = element.getSimpleName().toString();
    String elementNameLowerCase = elementName.toLowerCase();

    List<String> possibleMethodNames = new ArrayList<>();
    possibleMethodNames.add("get" + elementNameLowerCase);
    if (elementTypeKind == TypeKind.BOOLEAN) {
        possibleMethodNames.add("is" + elementNameLowerCase);
        possibleMethodNames.add("has" + elementNameLowerCase);
        possibleMethodNames.add(elementNameLowerCase);
    }

    // Handle the case where variables are named in the form mVariableName instead of just variableName
    if (elementName.length() > 1 && elementName.charAt(0) == 'm' && (elementName.charAt(1) >= 'A' && elementName.charAt(1) <= 'Z')) {
        possibleMethodNames.add("get" + elementNameLowerCase.substring(1));
        if (elementTypeKind == TypeKind.BOOLEAN) {
            possibleMethodNames.add("is" + elementNameLowerCase.substring(1));
            possibleMethodNames.add("has" + elementNameLowerCase.substring(1));
            possibleMethodNames.add(elementNameLowerCase.substring(1));
        }
    }

    List<? extends Element> elementMembers = elements.getAllMembers(enclosingElement);
    List<ExecutableElement> elementMethods = ElementFilter.methodsIn(elementMembers);
    for (ExecutableElement methodElement : elementMethods) {
        if (methodElement.getParameters().size() == 0) {
            String methodNameString = methodElement.getSimpleName().toString();
            String methodNameLowerCase = methodNameString.toLowerCase();

            if (possibleMethodNames.contains(methodNameLowerCase)) {
                if (methodElement.getParameters().size() == 0) {
                    if (methodElement.getReturnType().toString().equals(element.asType().toString())) {
                        return methodNameString;
                    }
                }
            }
        }
    }

    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:46,代碼來源:JsonFieldHolder.java


注:本文中的javax.lang.model.util.ElementFilter.methodsIn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。