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


Java MoreElements.asType方法代码示例

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


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

示例1: addQualifyExtension

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public void addQualifyExtension(Metaqualifier context, Element annotatedElement,
        AnnotationMirror annotationMirror, Qualify.Entry qualifyExtension) {
    final Metaextension<?> metaextension = context.use(qualifyExtension);

    final TypeMirror type = metaextension.type().get();
    final TypeElement element = MoreElements.asType(types().asElement(type));

    // Do not requires validation
    if (type.toString().equals("java.lang.String")) return;
    if (type.toString().equals("java.lang.Class")) return;

    // Check extensions types has a valid valueOf(String) static method
    final boolean valid = getExecutableElements(element).stream().anyMatch(method ->
            method.getSimpleName().toString().equals("valueOf")
                    && method.getModifiers().contains(Modifier.STATIC)
                    && method.getParameters().size() == 1
                    && isFirstParameterStringType(method));
    if (!valid) {
        getProcessingEnv().getMessager().printMessage(Diagnostic.Kind.ERROR, String.format(
                "Qualifier extension type '%s' with key '%s' must have a 'valueOf(String)' static " +
                        "method", metaextension.type(), metaextension.extension()),
                annotatedElement, annotationMirror);
    }

}
 
开发者ID:intendia-oss,项目名称:qualifier,代码行数:26,代码来源:QualifyQualifierProcessorProvider.java

示例2: validateSingleUid

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
static void validateSingleUid(Element element, boolean uidFound,
                              String uidElemenetName, ProcessingEnvironment processingEnvironment) {
    TypeElement typeElement = MoreElements.asType(element);
    PackageElement packageElement = MoreElements.getPackage(element);
    for (Element enclosed : packageElement.getEnclosedElements()) {
        TypeElement enclosedType = MoreElements.asType(enclosed);
        if (uidFound && Utils.hasUIDAnnotation(enclosedType)
                && !enclosedType.getQualifiedName().toString().equals(typeElement.getQualifiedName().toString())) {
            processingEnvironment.getMessager().printMessage(Diagnostic.Kind.ERROR.ERROR,
                    "Cannot have two @UID annotated elements in one package: " +
                    uidElemenetName + " and " +
                    enclosedType.getQualifiedName().toString() + ".");
        }
        uidFound = uidFound || Utils.hasUIDAnnotation(enclosedType);
        if (uidFound && uidElemenetName == null) {
            uidElemenetName = enclosedType.getQualifiedName().toString();
        }
    }
    TypeElement type = Utils.getTypeFromPackage(packageElement);
    List<TypeElement> typeElements = Utils.getAnnotationMirrorValueArrayAsTypeElementList(Utils.getTypeAnnotation(type));
    for (TypeElement elt : typeElements) {
        if (Utils.hasTypeAnnotation(elt)) {
            validateSingleUid(elt, uidFound, uidElemenetName, processingEnvironment);
        }
    }
}
 
开发者ID:Jongla,项目名称:braque,代码行数:27,代码来源:TypeValidator.java

示例3: validateThatCurrentPropertyIsReachableFromTheBaseType

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void validateThatCurrentPropertyIsReachableFromTheBaseType(TypeElement restElement, TypeElement currentProperty, TypeElement baseType,
                                                                   Map<String, TypeTree> typeTrees,
                                                                   ProcessingEnvironment processingEnvironment) {
    List<TypeElement> superAndSub = Utils.getSuperAndSubTypes(typeTrees.get(baseType.getQualifiedName().toString()));
    for (TypeElement typeElement : superAndSub) {
        PackageElement packageElement = MoreElements.getPackage(typeElement);
        for (Element element : packageElement.getEnclosedElements()) {
            TypeElement asType = MoreElements.asType(element);
            if (asType.getQualifiedName().toString().equals(currentProperty.getQualifiedName().toString())) {
                return;
            }
        }
    }
    processingEnvironment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Properties must be reachable from their base type. " +
            "In the API endpoint "+restElement+ " for the method "+mOp+", the property "
            +currentProperty.getQualifiedName().toString()+" is not reachable from the (possibly inferred) base type "+
            baseType.getQualifiedName().toString()+".  If you're pretty sure that the property you're using makes sense in "+
            "the API call, then verify that $.class separators are correctly placed.  Remember: "+
            "$.class should be used to end an inner object in an API definition.  If multiple objects end at the same place," +
            " all levels must be closed with a $.class.  Think of $.class like closing curly brackets.");
}
 
开发者ID:Jongla,项目名称:braque,代码行数:22,代码来源:AbstractRestHandler.java

示例4: addAbstractMethods

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void addAbstractMethods(
    TypeMirror typeMirror, List<ExecutableElement> abstractMethods) {
  if (typeMirror.getKind() != TypeKind.DECLARED) {
    return;
  }

  TypeElement typeElement = MoreElements.asType(typeMirror.accept(AS_ELEMENT_VISITOR, null));
  addAbstractMethods(typeElement.getSuperclass(), abstractMethods);
  for (TypeMirror interfaceMirror : typeElement.getInterfaces()) {
    addAbstractMethods(interfaceMirror, abstractMethods);
  }
  for (ExecutableElement method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
    for (Iterator<ExecutableElement> it = abstractMethods.iterator(); it.hasNext(); ) {
      ExecutableElement maybeOverridden = it.next();
      if (elementUtils.overrides(method, maybeOverridden, typeElement)) {
        it.remove();
      }
    }
    if (method.getModifiers().contains(Modifier.ABSTRACT)) {
      abstractMethods.add(method);
    }
  }
}
 
开发者ID:yongjhih,项目名称:RetroFacebook,代码行数:24,代码来源:BuilderSpec.java

示例5: validate

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private boolean validate(Element element) {
    TypeElement typeElement = MoreElements.asType(element);

    for (TypeMirror superInterface : typeElement.getInterfaces()) {
        if (!validateInterface(superInterface)) {
            return false;
        }
    }

    return true;
}
 
开发者ID:trollsoftware,项目名称:jcomposition,代码行数:12,代码来源:GenerateStep.java

示例6: getTypeFromPackage

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
static TypeElement getTypeFromPackage(PackageElement packageElement) {
    for (Element element : packageElement.getEnclosedElements()) {
        if (hasTypeAnnotation(MoreElements.asType(element))) {
            return MoreElements.asType(element);
        }
    }
    return null;
}
 
开发者ID:Jongla,项目名称:braque,代码行数:9,代码来源:Utils.java

示例7: getUIDFromPackage

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
static private TypeElement getUIDFromPackage(PackageElement packageElement) {
    for (Element element : packageElement.getEnclosedElements()) {
        if (hasUIDAnnotation(MoreElements.asType(element))) {
            return MoreElements.asType(element);
        }
    }
    return null;
}
 
开发者ID:Jongla,项目名称:braque,代码行数:9,代码来源:Utils.java

示例8: buildTransformerData

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
 * Process all classes annotated with {@link Transformer} and get information needed to generate the transformer
 * data file.
 */
void buildTransformerData(RoundEnvironment roundEnv) {
    for (Element element : roundEnv.getElementsAnnotatedWith(Transformer.class)) {
        if (!SuperficialValidation.validateElement(element)) continue;
        if (element.getKind() != ElementKind.CLASS) {
            error(element, "@Transformer annotations can only be applied to classes!");
            continue;
        }

        TypeElement typeElement = MoreElements.asType(element);
        // Get ClassName object, we'll store this so that we can write out a real type later.
        ClassName className = ClassName.get(typeElement);
        // Get real class name.
        String realName = className.toString();
        // Get attributes from Transformer annotation.
        Transformer tAnnot = typeElement.getAnnotation(Transformer.class);
        String visibleName = tAnnot.name();
        List<ClassName> validTypes = getValidTypes(tAnnot);
        Integer numArgs = tAnnot.numArgs();
        Boolean isNoArgs = tAnnot.isNoArgs();

        // Validate this transformer class.
        if (!isValidTransformerClass(typeElement, className, visibleName, validTypes, numArgs, isNoArgs)) continue;

        // Store information about this transformer so we can write it out later.
        if (isNoArgs) {
            realNAClassNames.add(realName);
            visibleNANames.put(realName, visibleName);
        } else {
            realClassNames.add(realName);
            visibleNames.put(realName, visibleName);
            numArgsMap.put(realName, numArgs);
            processValidTypes(realName, validTypes);
        }
        classMap.put(realName, className);
    }
}
 
开发者ID:bkromhout,项目名称:Ruqus,代码行数:41,代码来源:TransformerDataBuilder.java

示例9: parse

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public static ActionCreatorElement parse(Element element, Env env) throws ValidationException {
    if (element.getKind() != ElementKind.INTERFACE) {
        throw new ValidationException(element, "%s annotated with @%s should be interface", element, ActionCreator.class.getSimpleName());
    }
    TypeElement typeElement = MoreElements.asType(element);

    List<ActionCreatorAction> actions = new ArrayList<>();
    for (Element methodElement : typeElement.getEnclosedElements()) {
        if (methodElement.getKind() != ElementKind.METHOD) continue;
        actions.add(ActionCreatorAction.parse(MoreElements.asExecutable(methodElement), env));
    }

    return new ActionCreatorElement(actions, typeElement);
}
 
开发者ID:Yarikx,项目名称:reductor,代码行数:15,代码来源:ActionCreatorElement.java

示例10: AdditionExtractor

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public AdditionExtractor(Element additionElement, Class<? extends Annotation> additionAnnotation, Element element, Types types, Elements elements, Errors errors) {
    super(element, types, elements, errors);
    this.additionAnnotation = additionAnnotation;

    try {
        this.additionElement = MoreElements.asType(additionElement);
    } catch (Exception e) {
        errors.addInvalid(additionElement, "%s must be a class", additionElement.getSimpleName());
        return;
    }

    extract();
}
 
开发者ID:lukaspili,项目名称:Auto-Dagger2,代码行数:14,代码来源:AdditionExtractor.java

示例11: process

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
@Override
public void process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
  Set<Element> componentElements = Sets.union(
      elementsByAnnotation.get(Component.class),
      elementsByAnnotation.get(Subcomponent.class));

  for (Element element : componentElements) {
    TypeElement componentElement = MoreElements.asType(element);
    generateObjectGraph(componentElement);
  }
}
 
开发者ID:tbroyer,项目名称:bullet,代码行数:12,代码来源:ComponentProcessingStep.java

示例12: topLevelType

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private static TypeElement topLevelType(TypeElement type) {
    while (type.getNestingKind() != NestingKind.TOP_LEVEL) {
        type = MoreElements.asType(type.getEnclosingElement());
    }
    return type;
}
 
开发者ID:ccheptea,项目名称:auto-value-node,代码行数:7,代码来源:TypeSimplifier.java

示例13: topLevelType

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private static TypeElement topLevelType(TypeElement type) {
  while (type.getNestingKind() != NestingKind.TOP_LEVEL) {
    type = MoreElements.asType(type.getEnclosingElement());
  }
  return type;
}
 
开发者ID:sopak,项目名称:auto-value-step-builder,代码行数:7,代码来源:TypeSimplifier.java

示例14: buildClassAndFieldData

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
 * Process all classes which are annotated with {@link RealmClass} and get information needed to generate the class
 * data and various field data files.
 */
void buildClassAndFieldData(RoundEnvironment roundEnv) {
    for (Element element : roundEnv.getElementsAnnotatedWith(RealmClass.class)) {
        if (!SuperficialValidation.validateElement(element)) continue;
        if (element.getKind() != ElementKind.CLASS) {
            // Really this shouldn't be an issue since Realm's annotation processor will do real checks, but still.
            error(element, "@RealmClass annotations can only be applied to classes!");
            continue;
        }
        TypeElement typeElement = MoreElements.asType(element);
        if (!isValidRealmClass(typeElement)) continue;

        // Get ClassName object, we'll store this so that we can write out a real type later.
        ClassName className = ClassName.get(typeElement);
        // Get real class name.
        String realName = className.simpleName();
        // Check that the real name of the class isn't already in use.
        if (realClassNames.contains(realName)) {
            error(element, "Failed while processing \"%s\" because there is already a realm object class called " +
                            "\"%s\"; Ruqus currently cannot handle multiple classes with the same name.",
                    className.toString(), realName);
            continue;
        }
        // Check class for queryable and visible name annotations to try and figure out visible name.
        String visibleName = null;
        boolean isQueryable = false;
        if (MoreElements.isAnnotationPresent(typeElement, Queryable.class)) {
            Queryable qAnnot = typeElement.getAnnotation(Queryable.class);
            visibleName = qAnnot.name();
            isQueryable = true;
        }
        if ((visibleName == null || visibleName.isEmpty()) &&
                MoreElements.isAnnotationPresent(typeElement, VisibleAs.class)) {
            VisibleAs vaAnnot = typeElement.getAnnotation(VisibleAs.class);
            visibleName = vaAnnot.string();
        }
        if (visibleName == null || visibleName.isEmpty()) {
            // Generate a name from TitleCase.
            visibleName = Utils.makeVisName(realName);
        }
        // Check that visible name hasn't already been used.
        if (visibleNames.values().contains(visibleName)) {
            error(element, "Failed while processing \"%s\" because there is already a realm object class which " +
                    "has the visible name \"%s\"; Ruqus currently cannot handle having multiple classes with the " +
                    "same visible name.", className.toString(), visibleName);
            continue;
        }

        // Get field information for all fields in this class.
        FieldDataBuilder fdBuilder = new FieldDataBuilder(realName);
        processFields(typeElement, fdBuilder);

        // Store these locally until we write out the whole class data file.
        realClassNames.add(realName);
        if (isQueryable) queryable.add(realName);
        classMap.put(realName, className);
        visibleNames.put(realName, visibleName);
        fieldData.put(realName, fdBuilder);
    }
}
 
开发者ID:bkromhout,项目名称:Ruqus,代码行数:64,代码来源:ClassDataBuilder.java

示例15: searchMethodElementsByInjectElement

import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
     * Search all methods that with special return type and @RNamed.
     */
    private List<Element> searchMethodElementsByInjectElement(Element moduleClassElement, AbstractDIField fieldForInject, RNamed namedOfFieldForInject) {
        List<Element> resultMethodElementList = new ArrayList<>();
        if (moduleClassElement.getKind() != ElementKind.CLASS) {
            throw new IllegalArgumentException("ElementKind of " + moduleClassElement + " is not ElementKind.CLASS");
        }

        String exceptInjectType = fieldForInject.getRealFieldClassNameForInject();
        logger("[searchMethodElementsByInjectElement]exceptInjectType: " + exceptInjectType);
//        RNamed injectEleNamedAnno = injectElement.getAnnotation(RNamed.class);

        // set exceptInjectType to injectElement's injectElementQualifierName if @named annotation had not set.
        String injectEleQualifierName = null == namedOfFieldForInject ? exceptInjectType : namedOfFieldForInject.value();

        Element superElement = MoreElements.asType(moduleClassElement);
        while (null != superElement && !superElement.toString().equals(Object.class.getCanonicalName())) {

            for (Element methodEle : superElement.getEnclosedElements()) {
                if (ElementKind.METHOD != methodEle.getKind()) {
                    continue;
                }

                // Match the type of method in module as same as the type of injectElement.
                String methodReturnType = MoreElements.asExecutable(methodEle).getReturnType().toString();
                RNamed methodEleNamedAnno = methodEle.getAnnotation(RNamed.class);
                String methodEleQualifierName = null == methodEleNamedAnno ? methodReturnType : methodEleNamedAnno.value();

                if (methodReturnType.equals(exceptInjectType) // Same type
                        &&
                        methodEleQualifierName.equals(injectEleQualifierName) // Same named
                        ) {
                    resultMethodElementList.add(methodEle);
                }
            }

            TypeMirror superTypeMirror = MoreElements.asType(superElement).getSuperclass();
            if (superTypeMirror.getKind() != TypeKind.DECLARED) {
                break;
            }
            superElement = ((DeclaredType) superTypeMirror).asElement();
        }


        return resultMethodElementList;
    }
 
开发者ID:wangjiegulu,项目名称:Rapier,代码行数:48,代码来源:DIProcessor.java


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