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


Java MoreElements类代码示例

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


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

示例1: getElementOwnerClassName

import com.google.auto.common.MoreElements; //导入依赖的package包/类
/**
 * Get class name of special element
 */
protected String getElementOwnerClassName(Element element) {
    String clazzName;

    // todo: Get the Class which element's owner.
    ElementKind elementKind = element.getKind();
    if (ElementKind.FIELD == elementKind) {
        clazzName = MoreElements.asVariable(element).getEnclosingElement().toString();
        logger("[getDIClazzSafe]MoreElements.asVariable().getEnclosingElement(): " + MoreElements.asVariable(element).getEnclosingElement());
    } else if (ElementKind.METHOD == elementKind) {
        clazzName = MoreElements.asExecutable(element).getEnclosingElement().toString();
    } else {
        clazzName = typeUtils.erasure(element.asType()).toString();
    }


    return clazzName;
}
 
开发者ID:wangjiegulu,项目名称:RapidRouter,代码行数:21,代码来源:BaseAbstractProcessor.java

示例2: deepSame

import com.google.auto.common.MoreElements; //导入依赖的package包/类
/**
 * 两组参数类型相同
 */
public static boolean deepSame(List<? extends VariableElement> _this, List<? extends VariableElement> _that) {
    if (null == _this && null == _that) {
        return true;
    }

    if (null == _this || null == _that) {
        return false;
    }

    if (_this.size() != _that.size()) {
        return false;
    }

    for (int i = 0, len = _this.size(); i < len; i++) {
        VariableElement _thisEle = _this.get(i);
        VariableElement _thatEle = _that.get(i);

        if (!MoreElements.asType(_thisEle).getQualifiedName().toString()
                .equals(MoreElements.asType(_thatEle).getQualifiedName().toString())) {
            return false;
        }
    }

    return true;
}
 
开发者ID:wangjiegulu,项目名称:RapidRouter,代码行数:29,代码来源:ElementUtil.java

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

示例4: process

import com.google.auto.common.MoreElements; //导入依赖的package包/类
@Override
public Set<Element> process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
    ImmutableSet.Builder<Element> elementsForLaterProcessing = ImmutableSet.builder();
    for (Map.Entry<Class<? extends Annotation>, Element> entry : elementsByAnnotation.entries()) {
        if (!entry.getValue().getKind().isInterface()) {
            getProcessingEnv().getMessager().printMessage(Diagnostic.Kind.ERROR, entry.getKey().getName()
                    + " annotation can be used only with interfaces", entry.getValue());
        }

        Element value = entry.getValue();

        if (validate(value)) {
            generate(MoreElements.asType(value));
        } else {
            elementsForLaterProcessing.add(value);
        }
    }

    return elementsForLaterProcessing.build();
}
 
开发者ID:trollsoftware,项目名称:jcomposition,代码行数:21,代码来源:GenerateStep.java

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

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

示例7: validateActionCreator

import com.google.auto.common.MoreElements; //导入依赖的package包/类
private static void validateActionCreator(ExecutableElement element,
                                          String actionName,
                                          TypeMirror actionCreator,
                                          ArrayList<VariableElement> args,
                                          Map<String, ActionCreatorElement> knownActionCreators,
                                          Env env) throws ValidationException {
    Element actionCreatorElement = MoreTypes.asElement(actionCreator);
    if (!MoreElements.isAnnotationPresent(actionCreatorElement, ActionCreator.class)) {
        throw new ValidationException(element, "Action creator %s should be annotated with @%s", actionCreator, ActionCreator.class.getSimpleName());
    }

    ActionCreatorElement creatorElement = knownActionCreators.get(env.getElements().getBinaryName((TypeElement) actionCreatorElement).toString());
    if (creatorElement == null) {
        throw new ElementNotReadyException();
    }
    if (!creatorElement.hasAction(actionName, args)) {
        throw new ValidationException(element, "Cannot find action creator for action \"%s\" and args %s in interface %s", actionName, toString(args), creatorElement.getName(env));
    }
}
 
开发者ID:Yarikx,项目名称:reductor,代码行数:20,代码来源:ReduceAction.java

示例8: parseConstructors

import com.google.auto.common.MoreElements; //导入依赖的package包/类
private static List<AutoReducerConstructor> parseConstructors(TypeElement typeElement) throws ValidationException {
    List<AutoReducerConstructor> constructors = new ArrayList<>();
    boolean hasNonDefaultConstructors = false;
    for (Element element : typeElement.getEnclosedElements()) {
        if (element.getKind() == ElementKind.CONSTRUCTOR) {
            ExecutableElement executableElement = MoreElements.asExecutable(element);

            if (executableElement.getModifiers().contains(Modifier.PRIVATE)) continue;

            List<? extends VariableElement> parameters = executableElement.getParameters();

            hasNonDefaultConstructors |= parameters.size() != 0;
            constructors.add(new AutoReducerConstructor(executableElement));
        }
    }

    //if we only have one default constructor, it can be omitted
    if (!hasNonDefaultConstructors && constructors.size() == 1) return Collections.emptyList();

    //this is the case when all constructors are private
    if (constructors.size() == 0)
        throw new ValidationException(typeElement, "No accessible constructors available for class %s", typeElement);

    return constructors;
}
 
开发者ID:Yarikx,项目名称:reductor,代码行数:26,代码来源:StringReducerElement.java

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

示例10: buildClassName

import com.google.auto.common.MoreElements; //导入依赖的package包/类
private ClassName buildClassName(Element element) {
    String name = element.getSimpleName().toString();

    // try to remove Presenter at the end of the name
    String newName = removeEndingName(name, "Presenter");
    if (newName == null) {
        errors.addInvalid("Class name " + newName);
    }

    String pkg = MoreElements.getPackage(element).getQualifiedName().toString();
    if (StringUtils.isBlank(pkg)) {
        errors.addInvalid("Package name " + pkg);
    }
    pkg = pkg + ".stackable";

    return ClassName.get(pkg, newName + "Stackable");
}
 
开发者ID:lukaspili,项目名称:Mortar-architect,代码行数:18,代码来源:ScopeProcessing.java

示例11: findScope

import com.google.auto.common.MoreElements; //导入依赖的package包/类
/**
 * Find annotation that is itself annoted with @Scope
 * If there is one, it will be later applied on the generated component
 * Otherwise the component will be unscoped
 * Throw error if more than one scope annotation found
 */
private AnnotationMirror findScope() {
    AnnotationMirror annotationTypeMirror = null;

    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        Element annotationElement = annotationMirror.getAnnotationType().asElement();
        if (MoreElements.isAnnotationPresent(annotationElement, Scope.class)) {
            // already found one scope
            if (annotationTypeMirror != null) {
                errors.addInvalid("Several dagger scopes on same element are not allowed");
                continue;
            }

            annotationTypeMirror = annotationMirror;
        }
    }

    return annotationTypeMirror;
}
 
开发者ID:lukaspili,项目名称:Mortar-architect,代码行数:25,代码来源:ScopeExtractor.java

示例12: buildClassName

import com.google.auto.common.MoreElements; //导入依赖的package包/类
private ClassName buildClassName() {
    String name = extractor.getElement().getSimpleName().toString();

    // try to remove NavigationScope at the end of the name
    String newName = removeEndingName(removeEndingName(name, "Scope"), "Navigation");
    if (newName == null) {
        errors.addInvalid("Class name " + newName);
    }

    String pkg = MoreElements.getPackage(extractor.getElement()).getQualifiedName().toString();
    if (StringUtils.isBlank(pkg)) {
        errors.addInvalid("Package name " + pkg);
    }
    pkg = pkg + ".path";

    return ClassName.get(pkg, newName + "Path");
}
 
开发者ID:lukaspili,项目名称:Mortar-architect,代码行数:18,代码来源:PathProcessing.java

示例13: extract

import com.google.auto.common.MoreElements; //导入依赖的package包/类
@Override
public void extract() {
    if (element.getKind() != ElementKind.CLASS) {
        errors.addInvalid("Annotation can be applied only on a class");
        return;
    }

    viewTypeMirror = ExtractorUtils.getValueFromAnnotation(element, AutoPath.class, ANNOTATION_VIEW);
    if (viewTypeMirror == null) {
        errors.addMissing("withView() value");
    }

    constructorElements = new ArrayList<>();
    for (Element e : element.getEnclosedElements()) {
        if (e.getKind() == ElementKind.CONSTRUCTOR) {
            constructorElements.add(MoreElements.asExecutable(e));
        }
    }
}
 
开发者ID:lukaspili,项目名称:Mortar-architect,代码行数:20,代码来源:PathExtractor.java

示例14: buildClassName

import com.google.auto.common.MoreElements; //导入依赖的package包/类
private ClassName buildClassName(Element element) {
    String name = element.getSimpleName().toString();

    // try to remove Presenter at the end of the name
    String newName = removeEndingName(name, "Presenter");
    if (newName == null) {
        errors.addInvalid("Class name " + newName);
    }

    String pkg = MoreElements.getPackage(element).getQualifiedName().toString();
    if (StringUtils.isBlank(pkg)) {
        errors.addInvalid("Package name " + pkg);
    }
    pkg = pkg + ".screen";

    return ClassName.get(pkg, newName + "Screen");
}
 
开发者ID:lukaspili,项目名称:Auto-Mortar,代码行数:18,代码来源:ScreenProcessing.java

示例15: findWriteToParcel

import com.google.auto.common.MoreElements; //导入依赖的package包/类
@Nullable private ExecutableElement findWriteToParcel(TypeElement subject) {
  TypeMirror parcel = elements.getTypeElement("android.os.Parcel").asType();
  @SuppressWarnings("deprecation") // Support for kapt2
  ImmutableSet<ExecutableElement> methods =
      MoreElements.getLocalAndInheritedMethods(subject, elements);
  for (ExecutableElement element : methods) {
    if (element.getSimpleName().contentEquals("writeToParcel")
        && MoreTypes.isTypeOf(void.class, element.getReturnType())
        && !element.getModifiers().contains(Modifier.ABSTRACT)) {
      List<? extends VariableElement> parameters = element.getParameters();
      if (parameters.size() == 2
          && types.isSameType(parcel, parameters.get(0).asType())
          && MoreTypes.isTypeOf(int.class, parameters.get(1).asType())) {
        return element;
      }
    }
  }
  return null;
}
 
开发者ID:grandstaish,项目名称:paperparcel,代码行数:20,代码来源:PaperParcelAutoValueExtensionValidator.java


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