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


Java Elements类代码示例

本文整理汇总了Java中javax.lang.model.util.Elements的典型用法代码示例。如果您正苦于以下问题:Java Elements类的具体用法?Java Elements怎么用?Java Elements使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: before

import javax.lang.model.util.Elements; //导入依赖的package包/类
@Before
public void before() {
    mockedDataClassBuilderAnnotation = mock(DataClassBuilder.class);
    mockedProcessingEnv = mock(ProcessingEnvironment.class);
    mockedTypeElement = mock(TypeElement.class);

    when(mockedDataClassBuilderAnnotation.name()).thenReturn("");
    when(mockedTypeElement.getAnnotation(DataClassBuilder.class)).thenReturn(mockedDataClassBuilderAnnotation);

    mockedElementUtils = mock(Elements.class);
    when(mockedProcessingEnv.getElementUtils()).thenReturn(mockedElementUtils);

    PackageElement mockedPackageElement = mock(PackageElement.class);
    when(mockedElementUtils.getPackageOf(any(Element.class))).thenReturn(mockedPackageElement);

    Name mockedQualifiedName = mock(Name.class);
    when(mockedPackageElement.getQualifiedName()).thenReturn(mockedQualifiedName);
    when(mockedQualifiedName.toString()).thenReturn("eu.rsulkowski.test");

    dataClassBuilderDescriptor = new DataClassBuilderDescriptor(mockedProcessingEnv, mockedTypeElement);
}
 
开发者ID:rsulkowski,项目名称:jdoocsoup,代码行数:22,代码来源:DataClassBuilderDescriptorTest.java

示例2: createOrUpdateFieldHolder

import javax.lang.model.util.Elements; //导入依赖的package包/类
private void createOrUpdateFieldHolder(Element element, Elements elements, Types types, JsonObjectHolder objectHolder) {
    JsonIgnore ignoreAnnotation = element.getAnnotation(JsonIgnore.class);
    boolean shouldParse = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.SERIALIZE_ONLY;
    boolean shouldSerialize = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.PARSE_ONLY;

    if (shouldParse || shouldSerialize) {
        JsonFieldHolder fieldHolder = objectHolder.fieldMap.get(element.getSimpleName().toString());
        if (fieldHolder == null) {
            fieldHolder = new JsonFieldHolder();
            objectHolder.fieldMap.put(element.getSimpleName().toString(), fieldHolder);
        }

        String error = fieldHolder.fill(element, elements, types, null, null, objectHolder, shouldParse, shouldSerialize);
        if (!TextUtils.isEmpty(error)) {
            error(element, error);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:JsonObjectProcessor.java

示例3: determineLifecycleMethods

import javax.lang.model.util.Elements; //导入依赖的package包/类
private void determineLifecycleMethods( @Nonnull final TypeElement typeElement,
                                        @Nonnull final ComponentDescriptor descriptor )
{
  /*
   * Get the list of lifecycle methods that have been overridden by typeElement
   * a parent class, or by a default method method implemented by typeElement or
   * a parent class.
   */
  final Collection<ExecutableElement> lifecycleMethods = getComponentLifecycleMethods().values();
  final Elements elementUtils = processingEnv.getElementUtils();
  final Types typeUtils = processingEnv.getTypeUtils();
  final TypeElement componentType = elementUtils.getTypeElement( Constants.COMPONENT_CLASSNAME );
  final List<MethodDescriptor> overriddenLifecycleMethods =
    // Get all methods on type parent classes, and default methods from interfaces
    ProcessorUtil.getMethods( typeElement, processingEnv.getTypeUtils() ).stream()
      // Only keep methods that override the lifecycle methods
      .filter( m -> lifecycleMethods.stream().anyMatch( l -> elementUtils.overrides( m, l, typeElement ) ) )
      //Remove those that come from the base classes
      .filter( m -> m.getEnclosingElement() != componentType )
      .map( m -> new MethodDescriptor( m, (ExecutableType) typeUtils.asMemberOf( descriptor.getDeclaredType(), m ) ) )
      .collect( Collectors.toList() );

  descriptor.setLifecycleMethods( overriddenLifecycleMethods );
}
 
开发者ID:react4j,项目名称:react4j,代码行数:25,代码来源:ReactProcessor.java

示例4: testImplementsInterface

import javax.lang.model.util.Elements; //导入依赖的package包/类
@Test
public void testImplementsInterface() throws Exception {
    Elements mockElementUtils = Mockito.mock(Elements.class);
    Types mockTypeUtils = Mockito.mock(Types.class);

    TypeElement mockElement = Mockito.mock(TypeElement.class);
    doReturn(mockElement)
            .when(mockElementUtils)
            .getTypeElement(TestInterface.class.getName());

    TypeMirror mockMirror = Mockito.mock(TypeMirror.class);
    doReturn(mockMirror)
            .when(mockElement)
            .asType();

    doReturn(true)
            .when(mockTypeUtils)
            .isAssignable(mockMirror, mockMirror);

    boolean actual = Utils.implementsInterface(mockElementUtils, mockTypeUtils, mockElement, TestInterface.class);

    Assert.assertTrue(actual);
}
 
开发者ID:jzallas,项目名称:LifecycleAware,代码行数:24,代码来源:UtilsTest.java

示例5: isJsonFieldFieldAnnotationValid

import javax.lang.model.util.Elements; //导入依赖的package包/类
private boolean isJsonFieldFieldAnnotationValid(Element element, Elements elements) {
    TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();

    Annotation objectAnnotation = enclosingElement.getAnnotation(JsonObject.class);
    if (objectAnnotation == null) {
        error(enclosingElement, "%s: @%s fields can only be in classes annotated with @%s.", enclosingElement.getQualifiedName(), JsonField.class.getSimpleName(), JsonObject.class.getSimpleName());
        return false;
    }

    if (element.getModifiers().contains(PRIVATE) && (TextUtils.isEmpty(JsonFieldHolder.getGetter(element, elements)) || TextUtils.isEmpty(JsonFieldHolder.getSetter(element, elements)))) {
        error(element, "@%s annotation can only be used on private fields if both getter and setter are present.", JsonField.class.getSimpleName());
        return false;
    }

    return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JsonFieldProcessor.java

示例6: typeFor

import javax.lang.model.util.Elements; //导入依赖的package包/类
public static Type typeFor(TypeMirror typeMirror, TypeMirror typeConverterType, Elements elements, Types types) {
    TypeMirror genericClassTypeMirror = types.erasure(typeMirror);
    boolean hasTypeConverter = typeConverterType != null && !typeConverterType.toString().equals("void");

    Type type;
    if (!hasTypeConverter && typeMirror instanceof ArrayType) {
        TypeMirror arrayTypeMirror = ((ArrayType)typeMirror).getComponentType();
        type = new ArrayCollectionType(Type.typeFor(arrayTypeMirror, null, elements, types));
    } else if (!hasTypeConverter && !genericClassTypeMirror.toString().equals(typeMirror.toString())) {
        type = CollectionType.collectionTypeFor(typeMirror, genericClassTypeMirror, elements, types);

        if (type == null) {
            if (typeMirror.toString().contains("?")) {
                throw new RuntimeException("Generic types with wildcards are currently not supported by LoganSquare.");
            }
            try {
                type = new ParameterizedTypeField(TypeName.get(typeMirror));
            } catch (Exception ignored) { }
        }
    } else {
        type = FieldType.fieldTypeFor(typeMirror, typeConverterType, elements, types);
    }

    return type;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:Type.java

示例7: TypeMirrors

import javax.lang.model.util.Elements; //导入依赖的package包/类
TypeMirrors(ProcessingEnvironment env) {
    final Types typeUtils = env.getTypeUtils();
    final Elements elementUtils = env.getElementUtils();

    STRING_MIRROR = elementUtils.getTypeElement("java.lang.String").asType();
    BINARY_MIRROR = typeUtils.getArrayType(typeUtils.getPrimitiveType(TypeKind.BYTE));
    BOOLEAN_MIRROR = elementUtils.getTypeElement(Boolean.class.getName()).asType();
    LONG_MIRROR = elementUtils.getTypeElement(Long.class.getName()).asType();
    INTEGER_MIRROR = elementUtils.getTypeElement(Integer.class.getName()).asType();
    SHORT_MIRROR = elementUtils.getTypeElement(Short.class.getName()).asType();
    BYTE_MIRROR = elementUtils.getTypeElement(Byte.class.getName()).asType();
    DOUBLE_MIRROR = elementUtils.getTypeElement(Double.class.getName()).asType();
    FLOAT_MIRROR = elementUtils.getTypeElement(Float.class.getName()).asType();
    DATE_MIRROR = elementUtils.getTypeElement(Date.class.getName()).asType();

    PRIMITIVE_LONG_MIRROR = typeUtils.getPrimitiveType(TypeKind.LONG);
    PRIMITIVE_INT_MIRROR = typeUtils.getPrimitiveType(TypeKind.INT);
    PRIMITIVE_SHORT_MIRROR = typeUtils.getPrimitiveType(TypeKind.SHORT);
    PRIMITIVE_BYTE_MIRROR = typeUtils.getPrimitiveType(TypeKind.BYTE);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:TypeMirrors.java

示例8: init

import javax.lang.model.util.Elements; //导入依赖的package包/类
@Before
public void init() {
    Messager messenger = mock(Messager.class);

    this.annotationValue = mock(AnnotationValue.class);

    this.annotationTypeMirror = mock(TypeMirror.class);
    this.executableElement = mock(ExecutableElement.class);

    this.annotationElement = mock(TypeElement.class);
    when(this.annotationElement.asType()).thenReturn(this.annotationTypeMirror);

    this.elementUtils = mock(Elements.class);
    when(this.elementUtils.getTypeElement(any())).thenReturn(this.annotationElement);

    this.processingEnv = mock(ProcessingEnvironment.class);
    when(processingEnv.getMessager()).thenReturn(messenger);
    when(processingEnv.getElementUtils()).thenReturn(this.elementUtils);

    // finally....
    this.testee = new TSModuleHandler(processingEnv);
}
 
开发者ID:dzuvic,项目名称:jtsgen,代码行数:23,代码来源:TSModuleHandlerTest.java

示例9: KickbackElementClass

import javax.lang.model.util.Elements; //导入依赖的package包/类
public KickbackElementClass(VariableElement variableElement, Elements elementUtils) throws VerifyException {
    KickbackElement kickbackElement = variableElement.getAnnotation(KickbackElement.class);
    Weak weak = variableElement.getAnnotation(Weak.class);
    Soft soft = variableElement.getAnnotation(Soft.class);
    PackageElement packageElement = elementUtils.getPackageOf(variableElement);
    this.variableElement = variableElement;
    this.packageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
    this.typeName = TypeName.get(variableElement.asType());
    this.clazzName = variableElement.getSimpleName().toString();
    this.value = variableElement.getConstantValue();
    if(weak != null) this.isWeak = true;
    else this.isWeak = false;
    if(soft != null) this.isSoft = true;
    else this.isSoft = false;

    if(kickbackElement != null) {
        this.elementName =  StringUtils.toUpperCamel(Strings.isNullOrEmpty(kickbackElement.name()) ? this.clazzName : kickbackElement.name());
    } else {
        this.elementName = StringUtils.toUpperCamel(this.clazzName);
    }

    checkPrimitiveType();
    checkModifierValidate();
    checkAnnotationValidate();
}
 
开发者ID:skydoves,项目名称:Kickback,代码行数:26,代码来源:KickbackElementClass.java

示例10: getContainingClassOrPackageHeader

import javax.lang.model.util.Elements; //导入依赖的package包/类
private StringBuilder getContainingClassOrPackageHeader(Element el, Elements elements, ElementUtilities eu) {
    StringBuilder sb = new StringBuilder();
    if (el.getKind() != ElementKind.PACKAGE && el.getKind() != ElementKind.MODULE) {
        TypeElement cls = eu.enclosingTypeElement(el);
        if (cls != null) {
            switch(cls.getEnclosingElement().getKind()) {
                case ANNOTATION_TYPE:
                case CLASS:
                case ENUM:
                case INTERFACE:
                case PACKAGE:
                    sb.append("<font size='+0'><b>"); //NOI18N
                    createLink(sb, cls, makeNameLineBreakable(cls.getQualifiedName().toString()));
                    sb.append("</b></font>"); //NOI18N)
            }
        } else {
            PackageElement pkg = elements.getPackageOf(el);
            if (pkg != null) {
                sb.append("<font size='+0'><b>"); //NOI18N
                createLink(sb, pkg, makeNameLineBreakable(pkg.getQualifiedName().toString()));
                sb.append("</b></font>"); //NOI18N)
            }
        }
    }
    return sb;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ElementJavadoc.java

示例11: addPackageContent

import javax.lang.model.util.Elements; //导入依赖的package包/类
private void addPackageContent(final Env env, PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, boolean insideNew, boolean srcOnly) throws IOException {
    Set<? extends TypeMirror> smartTypes = options.contains(Options.ALL_COMPLETION) ? null : getSmartTypes(env);
    CompilationController controller = env.getController();
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    ElementUtilities eu = controller.getElementUtilities();
    Scope scope = env.getScope();
    for (Element e : pe.getEnclosedElements()) {
        if (e.getKind().isClass() || e.getKind().isInterface()) {
            String name = e.getSimpleName().toString();
            if ((env.getExcludes() == null || !env.getExcludes().contains(e))
                    && startsWith(env, name) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
                    && trees.isAccessible(scope, (TypeElement) e)
                    && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)
                    && !Utilities.isExcluded(eu.getElementName(e, true))) {
                results.add(itemFactory.createTypeItem(env.getController(), (TypeElement) e, (DeclaredType) e.asType(), anchorOffset, null, elements.isDeprecated(e), insideNew, insideNew || env.isInsideClass(), true, isOfSmartType(env, e.asType(), smartTypes), false));
            }
        }
    }
    String pkgName = pe.getQualifiedName() + "."; //NOI18N
    addPackages(env, pkgName, srcOnly);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JavaCompletionTask.java

示例12: nonObjectSuperclass

import javax.lang.model.util.Elements; //导入依赖的package包/类
/**
 * Returns the non-object superclass of the type with the proper type parameters.
 * An absent Optional is returned if there is no non-Object superclass.
 */
public static Optional<DeclaredType> nonObjectSuperclass(final Types types, Elements elements,
                                                         DeclaredType type) {
    checkNotNull(types);
    checkNotNull(elements);
    checkNotNull(type);

    final TypeMirror objectType =
            elements.getTypeElement(Object.class.getCanonicalName()).asType();
    // It's guaranteed there's only a single CLASS superclass because java doesn't have multiple
    // class inheritance.
    TypeMirror superclass = getOnlyElement(FluentIterable.from(types.directSupertypes(type))
            .filter(new Predicate<TypeMirror>() {
                @Override
                public boolean apply(TypeMirror input) {
                    return input.getKind().equals(TypeKind.DECLARED)
                            && (MoreElements.asType(
                            MoreTypes.asDeclared(input).asElement())).getKind().equals(ElementKind.CLASS)
                            && !types.isSameType(objectType, input);
                }
            }), null);
    return superclass != null
            ? Optional.of(MoreTypes.asDeclared(superclass))
            : Optional.<DeclaredType>absent();
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:29,代码来源:MoreTypes.java

示例13: FindPosScanner

import javax.lang.model.util.Elements; //导入依赖的package包/类
FindPosScanner(
        @NonNull final FileObject target,
        @NonNull final Trees trees,
        @NonNull final Elements elements,
        @NonNull final TreeUtilities treeUtilities,
        @NonNull final Collection<? extends ProfileSupport.Violation> violations,
        @NonNull final Result errors) {
    assert target != null;
    assert trees != null;
    assert elements != null;
    assert treeUtilities != null;
    assert violations != null;
    assert errors != null;
    this.target = target;
    this.trees = trees;
    this.elements = elements;
    this.treeUtilities = treeUtilities;
    this.errors = errors;
    for (ProfileSupport.Violation v : violations) {
        final ElementHandle<TypeElement> eh = v.getUsedType();
        if (eh != null) {
            violationsByBinNames.put(eh.getBinaryName(), v);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ProfilesAnalyzer.java

示例14: create

import javax.lang.model.util.Elements; //导入依赖的package包/类
public static LJSONTypeElement create(Elements elements, Element element) {
    if (element.getKind() != ElementKind.CLASS) {
        throw new IllegalArgumentException(
                String.format("Only CLASS can be annotated with @%s", LIMITJSON.class.getSimpleName()));
    }
    TypeElement typeElement = (TypeElement) element;
    LJSONTypeElement ljsonElement = new LJSONTypeElement();
    ljsonElement.typeElement = typeElement;
    ljsonElement.elements = elements;
    ArrayList<LIMITJSONVariable> list = new ArrayList<>();
    List<? extends Element> enclosedElements = typeElement.getEnclosedElements();
    if (!Collections.isEmpty(enclosedElements)) {
        for (Element ele : enclosedElements) {
            if (ele instanceof VariableElement) {
                list.add(LJSONVariableElement.create((VariableElement) ele));
            }
        }
    }
    ljsonElement.variableElements = list;
    return ljsonElement;
}
 
开发者ID:freelifer,项目名称:limitjson,代码行数:22,代码来源:LJSONTypeElement.java

示例15: testFieldSignatureFromElement

import javax.lang.model.util.Elements; //导入依赖的package包/类
public void testFieldSignatureFromElement () throws Exception {
InputStream in = this.prepareData(TEST_CLASS);
try {
    JavacTask jt = prepareJavac ();
    Elements elements = jt.getElements();
    TypeElement be = elements.getTypeElement(TEST_CLASS);
    ClassFile cf = new ClassFile (in, true);
    String className = cf.getName().getInternalName().replace('/','.');	    //NOI18N
    List<? extends Element> members = be.getEnclosedElements();
    for (Element e : members) {
	if (e.getKind() == ElementKind.FIELD) {
	    String[] msig = ClassFileUtil.createFieldDescriptor((VariableElement) e);
	    assertEquals (className,msig[0]);
	    assertEquals (e.getSimpleName().toString(),msig[1]);
	    Variable v = cf.getVariable (e.getSimpleName().toString());		    
	    assertNotNull (v);		    
	    assertEquals (v.getDescriptor(), msig[2]);
	}
    }
} finally {
    in.close ();
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CompromiseSATest.java


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