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


Java ElementFilter類代碼示例

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


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

示例1: getAnnotationValue

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
private static AnnotationValue getAnnotationValue(AnnotationMirror mirror, String name) {
    ExecutableElement valueMethod = null;
    for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) {
        if (method.getSimpleName().toString().equals(name)) {
            valueMethod = method;
            break;
        }
    }

    if (valueMethod == null) {
        return null;
    }

    AnnotationValue value = mirror.getElementValues().get(valueMethod);
    if (value == null) {
        value = valueMethod.getDefaultValue();
    }

    return value;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:MatchProcessor.java

示例2: doGet

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
@Override 
protected ExecutableElement doGet(ProcessingEnvironment env) { 
  TypeElement typeElt = env.getElementUtils().getTypeElement(fqn.getName()); 
  if (typeElt != null) { 
    next: 
    for (ExecutableElement executableElement : ElementFilter.methodsIn(typeElt.getEnclosedElements())) {
      if (executableElement.getSimpleName().toString().equals(name)) { 
        List<? extends TypeMirror> parameterTypes = ((ExecutableType)executableElement.asType()).getParameterTypes(); 
        int len = parameterTypes.size(); 
        if (len == this.parameterTypes.size()) { 
          for (int i = 0;i < len;i++) { 
            if (!parameterTypes.get(i).toString().equals(this.parameterTypes.get(i))) { 
              continue next; 
            } 
          } 
          return executableElement; 
        } 
      } 
    } 
  } 
  return null; 
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:23,代碼來源:ElementHandle.java

示例3: getAllFields

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
/**
 * Including super classes' fields.
 */

List<VariableElement> getAllFields(TypeElement subclazz) {
    List<VariableElement> fields = new ArrayList<VariableElement>();
    TypeElement cd = null;
    Stack<TypeElement> s = new Stack<TypeElement>();

    cd = subclazz;
    while (true) {
        s.push(cd);
        TypeElement c = (TypeElement) (types.asElement(cd.getSuperclass()));
        if (c == null)
            break;
        cd = c;
    }

    while (!s.empty()) {
        cd = s.pop();
        fields.addAll(ElementFilter.fieldsIn(cd.getEnclosedElements()));
    }

    return fields;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:Gen.java

示例4: overriddenMethod

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
public ExecutableElement overriddenMethod(ExecutableElement method) {
    if (isStatic(method)) {
        return null;
    }
    final TypeElement origin = getEnclosingTypeElement(method);
    for (TypeMirror t = getSuperType(origin);
            t.getKind() == DECLARED;
            t = getSuperType(asTypeElement(t))) {
        TypeElement te = asTypeElement(t);
        if (te == null) {
            return null;
        }
        List<? extends Element> methods = te.getEnclosedElements();
        for (ExecutableElement ee : ElementFilter.methodsIn(methods)) {
            if (configuration.workArounds.overrides(method, ee, origin)) {
                return ee;
            }
        }
        if (t.equals(getObjectType()))
            return null;
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:Utils.java

示例5: generateReadMethod

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
private static boolean generateReadMethod(Context context) {
  TypeElement type = context.autoValueClass();
  //Find method with param as JSONObject and return type as autovalue class.
  for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
    if (method.getModifiers().contains(Modifier.STATIC) && method.getParameters().size() == 1) {
      TypeMirror rType = method.getReturnType();
      TypeName returnType = TypeName.get(rType);

      TypeMirror pType = method.getParameters().get(0).asType();
      TypeName paramType = TypeName.get(pType);
      if (returnType.equals(TypeName.get(type.asType())) && paramType.equals(
          JSON_OBJ_CLASS_NAME)) {
        return true;
      }
    }
  }
  return false;
}
 
開發者ID:setheclark,項目名稱:auto-value-json,代碼行數:19,代碼來源:AutoValueJsonExtension.java

示例6: testIsDeprecated2

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
public void testIsDeprecated2() throws Exception {
    prepareTest();
    
    TypeElement test = info.getElements().getTypeElement("sourceutils.TestIsDeprecated2");
    
    assertNotNull(test);
    
    ExecutableElement methodDeprecated = findElementBySimpleName("methodDeprecated", ElementFilter.methodsIn(test.getEnclosedElements()));
    ExecutableElement methodNotDeprecated = findElementBySimpleName("methodNotDeprecated", ElementFilter.methodsIn(test.getEnclosedElements()));
    VariableElement fieldDeprecated = findElementBySimpleName("fieldDeprecated", ElementFilter.fieldsIn(test.getEnclosedElements()));
    VariableElement fieldNotDeprecated = findElementBySimpleName("fieldNotDeprecated", ElementFilter.fieldsIn(test.getEnclosedElements()));
    TypeElement classDeprecated = findElementBySimpleName("classDeprecated", ElementFilter.typesIn(test.getEnclosedElements()));
    TypeElement classNotDeprecated = findElementBySimpleName("classNotDeprecated", ElementFilter.typesIn(test.getEnclosedElements()));
    
    assertFalse(info.getElements().isDeprecated(methodNotDeprecated));
    assertFalse(info.getElements().isDeprecated(fieldNotDeprecated));
    assertFalse(info.getElements().isDeprecated(classNotDeprecated));

    assertTrue(info.getElements().isDeprecated(methodDeprecated));
    assertTrue(info.getElements().isDeprecated(fieldDeprecated));
    assertTrue(info.getElements().isDeprecated(classDeprecated));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:SourceUtilsTest.java

示例7: 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,代碼來源:GeneratorUtilitiesTest.java

示例8: 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);
    assertNotNull(te);
    ArrayList<ExecutableElement> methods = new ArrayList<ExecutableElement>(2);
    TypeElement object = copy.getElements().getTypeElement("java.lang.Object");
    assertNotNull(object);
    for (ExecutableElement method : ElementFilter.methodsIn(object.getEnclosedElements())) {
        if (method.getSimpleName().contentEquals("clone"))
            methods.add(method);
        else if (method.getSimpleName().contentEquals("toString"))
            methods.add(method);
    }
    GeneratorUtilities utilities = GeneratorUtilities.get(copy);
    assertNotNull(utilities);
    ClassTree newCt = utilities.insertClassMembers(ct, utilities.createOverridingMethods(te, methods));
    copy.rewrite(ct, newCt);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:GeneratorUtilitiesTest.java

示例9: getAllFields

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
public static List<VariableTree> getAllFields(JavaSource source) {
    final List<VariableTree> allFields = new ArrayList<VariableTree>();

    try {
        source.runUserActionTask(new AbstractTask<CompilationController>() {

            public void run(CompilationController controller) throws IOException {
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
                TypeElement classElement = getTopLevelClassElement(controller);
                List<VariableElement> fields = ElementFilter.fieldsIn(classElement.getEnclosedElements());

                for (VariableElement field : fields) {
                    allFields.add((VariableTree) controller.getTrees().getTree(field));
                }
            }
        }, true);
    } catch (IOException ex) {
    }
    return allFields;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:JavaSourceHelper.java

示例10: 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

示例11: nonPrivateDeclaredTypes

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
/**
 * Finds all types that are declared with non private visibility by the given {@code TypeMirror},
 * any class in its superclass chain, or any interface it implements.
 */
private static Set<TypeMirror> nonPrivateDeclaredTypes(Types typeUtils, TypeMirror type) {
  if (type == null) {
    return new TypeMirrorSet();
  } else {
    Set<TypeMirror> declared = new TypeMirrorSet();
    declared.add(type);
    List<TypeElement> nestedTypes =
        ElementFilter.typesIn(typeUtils.asElement(type).getEnclosedElements());
    for (TypeElement nestedType : nestedTypes) {
      if (!nestedType.getModifiers().contains(PRIVATE)) {
        declared.add(nestedType.asType());
      }
    }
    for (TypeMirror supertype : typeUtils.directSupertypes(type)) {
      declared.addAll(nonPrivateDeclaredTypes(typeUtils, supertype));
    }
    return declared;
  }
}
 
開發者ID:sopak,項目名稱:auto-value-step-builder,代碼行數:24,代碼來源:TypeSimplifier.java

示例12: getModuleRequires

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
/**
 * Returns the "requires" modules for the target module.
 * @param mdle the target module element
 * @param onlyTransitive true gets all the requires transitive, otherwise
 *                 gets all the non-transitive requires
 *
 * @return a set of modules
 */
private Set<ModuleElement> getModuleRequires(ModuleElement mdle, boolean onlyTransitive) throws ToolException {
    Set<ModuleElement> result = new HashSet<>();
    for (RequiresDirective rd : ElementFilter.requiresIn(mdle.getDirectives())) {
        ModuleElement dep = rd.getDependency();
        if (result.contains(dep))
            continue;
        if (!isMandated(mdle, rd) && onlyTransitive == rd.isTransitive()) {
            if (!haveModuleSources(dep)) {
                messager.printWarning(dep, "main.module_not_found", dep.getSimpleName());
            }
            result.add(dep);
        } else if (isMandated(mdle, rd) && haveModuleSources(dep)) {
            result.add(dep);
        }
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ElementsTable.java

示例13: hasWebMethods

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
protected boolean hasWebMethods(TypeElement element) {
    if (element.getQualifiedName().toString().equals(Object.class.getName()))
        return false;
    WebMethod webMethod;
    for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
        webMethod = method.getAnnotation(WebMethod.class);
        if (webMethod != null) {
            if (webMethod.exclude()) {
                if (webMethod.operationName().length() > 0)
                    builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_WEBMETHOD_ELEMENT_WITH_EXCLUDE(
                            "operationName", element.getQualifiedName(), method.toString()), method);
                if (webMethod.action().length() > 0)
                    builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_WEBMETHOD_ELEMENT_WITH_EXCLUDE(
                            "action", element.getQualifiedName(), method.toString()), method);
            } else {
                return true;
            }
        }
    }
    return false;//hasWebMethods(d.getSuperclass().getDeclaration());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:WebServiceVisitor.java

示例14: findAnnotationValue

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
protected static AnnotationValue findAnnotationValue(AnnotationMirror mirror, String name) {
    ExecutableElement valueMethod = null;
    for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) {
        if (method.getSimpleName().toString().equals(name)) {
            valueMethod = method;
            break;
        }
    }

    if (valueMethod == null) {
        return null;
    }

    AnnotationValue value = mirror.getElementValues().get(valueMethod);
    if (value == null) {
        value = valueMethod.getDefaultValue();
    }

    return value;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:AbstractVerifier.java

示例15: accept

import javax.lang.model.util.ElementFilter; //導入依賴的package包/類
@Override
public boolean accept(CompilationInfo info, TypeMirror tm) {
    if (minimalVersion != null && minimalVersion.compareTo(info.getSourceVersion()) > 0) {
        return false;
    }
    
    TypeElement clazz = info.getElements().getTypeElement(fqn);

    if (clazz == null) {
        return false;
    }

    for (ExecutableElement m : ElementFilter.methodsIn(clazz.getEnclosedElements())) {
        if (m.getSimpleName().contentEquals(methodName)) {
            return true;
        }
    }

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


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