当前位置: 首页>>代码示例>>Java>>正文


Java Element.getEnclosedElements方法代码示例

本文整理汇总了Java中javax.lang.model.element.Element.getEnclosedElements方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getEnclosedElements方法的具体用法?Java Element.getEnclosedElements怎么用?Java Element.getEnclosedElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.element.Element的用法示例。


在下文中一共展示了Element.getEnclosedElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: superProperties

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * Returns a list of the super-properties, i.e. properties inherited from the extending tree of {@code iface}.
 * @param env the environment, must not be null
 * @param iface the @Immu/@SuperImmu interface for which to recursively find the properties, must not be null
 * @return the list of properties, in order from the most super interface to the provided one
 */
private List<ImmuProperty> superProperties(ProcessingEnvironment env, TypeMirror iface) {
  final LinkedList<ImmuProperty> properties = new LinkedList<>();

  final Element ifaceElement = env.getTypeUtils().asElement(iface);

  final TypeElement typeElement = (TypeElement) ifaceElement;

  for (TypeMirror mirror : typeElement.getInterfaces()) {
    properties.addAll(superProperties(env, mirror));
  }

  for (Element element : ifaceElement.getEnclosedElements()) {
    if (ElementKind.METHOD.equals(element.getKind())) {
      properties.add(ImmuProperty.from(element));
    }
  }

  return properties;
}
 
开发者ID:hf,项目名称:immu,代码行数:26,代码来源:ImmuObjectElement.java

示例2: parseCompiledR

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
  for (Element element : rClass.getEnclosedElements()) {
    String innerClassName = element.getSimpleName().toString();
    if (SUPPORTED_TYPES.contains(innerClassName)) {
      for (Element enclosedElement : element.getEnclosedElements()) {
        if (enclosedElement instanceof VariableElement) {
          VariableElement variableElement = (VariableElement) enclosedElement;
          Object value = variableElement.getConstantValue();

          if (value instanceof Integer) {
            int id = (Integer) value;
            ClassName rClassName =
                ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R",
                    innerClassName);
            String resourceName = variableElement.getSimpleName().toString();
            QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
            symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
          }
        }
      }
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ButterKnifeProcessor.java

示例3: parseCompiledR

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
    for (Element element : rClass.getEnclosedElements()) {
        String innerClassName = element.getSimpleName().toString();
        if (supportedTypes.contains(innerClassName)) {
            for (Element enclosedElement : element.getEnclosedElements()) {
                if (enclosedElement instanceof VariableElement) {
                    VariableElement variableElement = (VariableElement) enclosedElement;
                    Object value = variableElement.getConstantValue();

                    if (value instanceof Integer) {
                        int id = (Integer) value;
                        ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
                        String resourceName = variableElement.getSimpleName().toString();
                        QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
                        symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
                    }
                }
            }
        }
    }
}
 
开发者ID:hendraanggrian,项目名称:r-parser,代码行数:22,代码来源:RParser.java

示例4: preCheck

import javax.lang.model.element.Element; //导入方法依赖的package包/类
@Override
protected Problem preCheck(CompilationController info) throws IOException {
    fireProgressListenerStart(AbstractRefactoring.PRE_CHECK, 4);
    Problem preCheckProblem = null;
    info.toPhase(JavaSource.Phase.RESOLVED);
    preCheckProblem = isElementAvail(treePathHandle, info);
    if (preCheckProblem != null) {
        return preCheckProblem;
    }
    Element el = treePathHandle.resolveElement(info);
    if (!(el.getKind() == ElementKind.CLASS || el.getKind() == ElementKind.INTERFACE)) {
        preCheckProblem = createProblem(preCheckProblem, true, NbBundle.getMessage(IntroduceLocalExtensionPlugin.class, "ERR_IntroduceLEWrongType")); // NOI18N
        return preCheckProblem;
    }
    for (Element element : el.getEnclosedElements()) {
        if((element.getKind().isClass() || element.getKind().isInterface()) && !element.getModifiers().contains(Modifier.PRIVATE)) {
            preCheckProblem = createProblem(preCheckProblem, true, NbBundle.getMessage(IntroduceLocalExtensionPlugin.class, "ERR_IntroduceLEInnerType")); // NOI18N
            return preCheckProblem;
        }
    }
    return preCheckProblem;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:IntroduceLocalExtensionPlugin.java

示例5: parseCompiledR

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
    for (Element element : rClass.getEnclosedElements()) {
        String innerClassName = element.getSimpleName().toString();
        if (innerClassName.equals("string")) {
            for (Element enclosedElement : element.getEnclosedElements()) {
                if (enclosedElement instanceof VariableElement) {
                    VariableElement variableElement = (VariableElement) enclosedElement;
                    Object value = variableElement.getConstantValue();

                    if (value instanceof Integer) {
                        int id = (Integer) value;
                        ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
                        String resourceName = variableElement.getSimpleName().toString();
                        QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
                        symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
                    }
                }
            }
        }
    }
}
 
开发者ID:WellingtonCosta,项目名称:convalida,代码行数:22,代码来源:ConvalidaProcessor.java

示例6: process

import javax.lang.model.element.Element; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
	for (Element element : roundEnv.getRootElements()) {
		if (element.getSimpleName().toString().equals("InjectPresenterTypeBehaviorView")) {
			for (Element element1 : element.getEnclosedElements()) {
				System.out.println("EnclosedElements: " + element1.getSimpleName());
				ImmutableList<String> of = ImmutableList.of("mPresenterIdLocalPresenter", "mTagLocalPresenter", "mFactoryLocalPresenter", "mFactoryTagPresenter");
				if (of.contains(element1.getSimpleName().toString())) {
					messager.printMessage(Diagnostic.Kind.ERROR, "expected error!", element1);
				}
			}
		}
	}
	return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:ErrorProcessor.java

示例7: addAllNonPrivateFields

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void addAllNonPrivateFields(Element element, Elements elements, Types types, JsonObjectHolder objectHolder) {
    List<? extends Element> enclosedElements = element.getEnclosedElements();
    for (Element enclosedElement : enclosedElements) {
        ElementKind enclosedElementKind = enclosedElement.getKind();
        if (enclosedElementKind == ElementKind.FIELD) {
            Set<Modifier> modifiers = enclosedElement.getModifiers();
            if (!modifiers.contains(Modifier.PRIVATE) && !modifiers.contains(Modifier.PROTECTED) && !modifiers.contains(Modifier.TRANSIENT) && !modifiers.contains(Modifier.STATIC)) {
                createOrUpdateFieldHolder(enclosedElement, elements, types, objectHolder);
            }
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JsonObjectProcessor.java

示例8: getItems0

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private List<Element> getItems0(Element te, boolean filter, Set<ElementKind> kinds) {
    List<Element> elements = new ArrayList<>();
    for (Element e : te.getEnclosedElements()) {
        if (kinds.contains(e.getKind())) {
            if (!filter || shouldDocument(e)) {
                elements.add(e);
            }
        }
    }
    return elements;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Utils.java

示例9: run

import javax.lang.model.element.Element; //导入方法依赖的package包/类
public void run(WorkingCopy copy) throws Exception {
    copy.toPhase(JavaSource.Phase.RESOLVED);
    CompilationUnitTree cut = copy.getCompilationUnit();
    Elements elements = copy.getElements();
    Set<Element> imports = new HashSet<Element>();
    for (String imp : toImport) {
        if (imp.endsWith(".*"))
            imp = imp.substring(0, imp.length() - 2);
        Element el = elements.getTypeElement(imp);
        if (el == null)
            el = elements.getPackageElement(imp);
        if (el == null) {
            int idx = imp.lastIndexOf('.');
            if (idx >= 0) {
                el = elements.getTypeElement(imp.substring(0, idx));
                if (el != null) {
                    String name = imp.substring(idx + 1);
                    for (Element ee : el.getEnclosedElements()) {
                        if (name.contentEquals(ee.getSimpleName())) {                                
                            el = ee;
                            break;
                        }
                    }
                }
            }
        }
        assertNotNull(el);
        imports.add(el);
    }
    GeneratorUtilities utilities = GeneratorUtilities.get(copy);
    assertNotNull(utilities);
    CompilationUnitTree newCut = utilities.addImports(cut, imports);
    copy.rewrite(cut, newCut);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:GeneratorUtilitiesTest.java

示例10: isUtilityClass

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private static boolean isUtilityClass(CompilationInfo compilationInfo, Element clazz) {
    if (clazz.getKind() != ElementKind.CLASS) {
        return false;
    }
    
    TypeMirror supr = ((TypeElement) clazz).getSuperclass();
    if (supr == null) {
        return false;
    }
    Element superElem = compilationInfo.getTypes().asElement(supr);
    if (superElem instanceof TypeElement) {
        Name superName = compilationInfo.getElements().getBinaryName((TypeElement) superElem);
        if (superName != null && !superName.contentEquals("java.lang.Object")) {
            return false;
        }
    }

    int cnt = 0;
    for (Element m : clazz.getEnclosedElements()) {
        if (m.getKind() == ElementKind.METHOD && isMainMethod(((ExecutableElement) m))) return false;
        if (m.getKind() == ElementKind.METHOD || m.getKind() == ElementKind.FIELD) {
            if (!m.getModifiers().contains(Modifier.STATIC)) return false;
            cnt++;
        }
    }

    return cnt > 0;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:UtilityClass.java

示例11: findAndParseTargets

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private List<JavaFile> findAndParseTargets(RoundEnvironment env) {
    List<JavaFile> javaFiles = new ArrayList<>();

    // Process each @RouterModule element.
    for (Element e : env.getElementsAnnotatedWith(RouterModule.class)) {
        if (!SuperficialValidation.validateElement(e))
            continue;
        List<? extends Element> allEle = e.getEnclosedElements();
        parseRouterModule(e, allEle, javaFiles);
    }
    return javaFiles;
}
 
开发者ID:TangXiaoLv,项目名称:Android-Router,代码行数:13,代码来源:AndroidRouterProcessor.java

示例12: isOfKind

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private boolean isOfKind(Element e, EnumSet<ElementKind> kinds) {
    if (kinds.contains(e.getKind())) {
        return true;
    }
    for (Element ee : e.getEnclosedElements()) {
        if (isOfKind(ee, kinds)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:LazyJavaCompletionItem.java

示例13: checkSuperInterface

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * Recursively check the superinterfaces of the provided interface.
 * @param env the environment, must not be null
 * @param extendingIface the interface that extends {@code iface}, must not be null
 * @param iface the interface to check, must not be null
 * @return a list of all the errors, never null
 */
public static List<String> checkSuperInterface(ProcessingEnvironment env, TypeMirror extendingIface, TypeMirror iface) {
  final Element extendingIFaceElement = env.getTypeUtils().asElement(extendingIface);
  final Element ifaceElement = env.getTypeUtils().asElement(iface);

  if (null != ifaceElement.getAnnotation(SuperImmu.class)) {
    // interface is a @SuperImmu, therefore it will be checked soon (or was already checked)
    return Collections.emptyList();
  }

  if (null != ifaceElement.getAnnotation(Immu.class)) {
    // interface already has an @Immu annotation, therefore will be checked soon (or was already checked)
    // also, this means that we can extend the superinterface's properties
    return Collections.emptyList();
  }

  final List<String> errors = new LinkedList<>();

  for (Element enclosedElement : ifaceElement.getEnclosedElements()) {
    if (ElementKind.METHOD.equals(enclosedElement.getKind())) {
      errors.addAll(ImmuValidationMessages.nonImmuInterfaceHasMethod(extendingIFaceElement, ifaceElement, enclosedElement));
    }
  }

  final TypeElement typeElement = (TypeElement) ifaceElement;

  final List<? extends TypeMirror> superInterfaces = typeElement.getInterfaces();

  for (TypeMirror superIface : superInterfaces) {
    errors.addAll(checkSuperInterface(env, iface, superIface));
  }

  return errors;
}
 
开发者ID:hf,项目名称:immu,代码行数:41,代码来源:ImmuObjectElement.java

示例14: getNoArgsConstructor

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * Returns the no-args constructor for {@code type}, or null if no such constructor exists.
 */
static ExecutableElement getNoArgsConstructor(final Element type) {
    for (Element enclosed : type.getEnclosedElements()) {
        if (enclosed.getKind() != ElementKind.CONSTRUCTOR) {
            continue;
        }

        ExecutableElement constructor = (ExecutableElement) enclosed;
        if (constructor.getParameters().isEmpty()) {
            return constructor;
        }
    }

    return null;
}
 
开发者ID:renard314,项目名称:auto-adapter,代码行数:18,代码来源:Util.java

示例15: processEvents

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void processEvents(ComponentInfo componentInfo,
                           Element componentElement) {
  for (Element element : componentElement.getEnclosedElements()) {
    if (!isPublicMethod(element)) {
      continue;
    }

    // Get the name of the prospective event.
    String eventName = element.getSimpleName().toString();
    SimpleEvent simpleEventAnnotation = element.getAnnotation(SimpleEvent.class);

    // Remove overriden events unless SimpleEvent is again specified.
    // See comment in processProperties for an example.
    if (simpleEventAnnotation == null) {
      if (componentInfo.events.containsKey(eventName)) {
        componentInfo.events.remove(eventName);
      }
    } else {
      String eventDescription = simpleEventAnnotation.description();
      if (eventDescription.isEmpty()) {
        eventDescription = elementUtils.getDocComment(element);
        if (eventDescription == null) {
          messager.printMessage(Diagnostic.Kind.WARNING,
                                "In component " + componentInfo.name +
                                ", event " + eventName +
                                " is missing a description.");
          eventDescription = "";
        }
      }
      boolean userVisible = simpleEventAnnotation.userVisible();
      boolean deprecated = elementUtils.isDeprecated(element);
      Event event = new Event(eventName, eventDescription, userVisible, deprecated);
      componentInfo.events.put(event.name, event);

      // Verify that this element has an ExecutableType.
      if (!(element instanceof ExecutableElement)) {
        throw new RuntimeException("In component " + componentInfo.name +
                                   ", the representation of SimpleEvent " + eventName +
                                   " does not implement ExecutableElement.");
      }
      ExecutableElement e = (ExecutableElement) element;

      // Extract the parameters.
      for (VariableElement ve : e.getParameters()) {
        event.addParameter(ve.getSimpleName().toString(),
                           ve.asType().toString());
      }
    }
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:51,代码来源:ComponentProcessor.java


注:本文中的javax.lang.model.element.Element.getEnclosedElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。