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


Java Types.asMemberOf方法代码示例

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


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

示例1: enumerateMethods

import javax.lang.model.util.Types; //导入方法依赖的package包/类
private static void enumerateMethods( @Nonnull final TypeElement scope,
                                      @Nonnull final Types typeUtils,
                                      @Nonnull final TypeElement element,
                                      @Nonnull final Map<String, ExecutableElement> methods )
{
  final TypeMirror superclass = element.getSuperclass();
  if ( TypeKind.NONE != superclass.getKind() )
  {
    enumerateMethods( scope, typeUtils, (TypeElement) ( (DeclaredType) superclass ).asElement(), methods );
  }
  for ( final TypeMirror interfaceType : element.getInterfaces() )
  {
    final TypeElement interfaceElement = (TypeElement) ( (DeclaredType) interfaceType ).asElement();
    enumerateMethods( scope, typeUtils, interfaceElement, methods );
  }
  for ( final Element member : element.getEnclosedElements() )
  {
    if ( member.getKind() == ElementKind.METHOD )
    {
      final ExecutableType methodType =
        (ExecutableType) typeUtils.asMemberOf( (DeclaredType) scope.asType(), member );
      methods.put( member.getSimpleName() + methodType.toString(), (ExecutableElement) member );
    }
  }
}
 
开发者ID:react4j,项目名称:react4j,代码行数:26,代码来源:ProcessorUtil.java

示例2: enumerateFields

import javax.lang.model.util.Types; //导入方法依赖的package包/类
private static void enumerateFields( @Nonnull final TypeElement scope,
                                     @Nonnull final Types typeUtils,
                                     @Nonnull final TypeElement element,
                                     @Nonnull final Map<String, TypeMirror> fields )
{
  final TypeMirror superclass = element.getSuperclass();
  if ( TypeKind.NONE != superclass.getKind() )
  {
    enumerateFields( scope, typeUtils, (TypeElement) ( (DeclaredType) superclass ).asElement(), fields );
  }
  for ( final Element member : element.getEnclosedElements() )
  {
    if ( member.getKind() == ElementKind.FIELD )
    {
      final TypeMirror fieldType = typeUtils.asMemberOf( (DeclaredType) scope.asType(), member );
      fields.put( member.getSimpleName().toString(), fieldType );
    }
  }
}
 
开发者ID:react4j,项目名称:react4j,代码行数:20,代码来源:ProcessorUtil.java

示例3: asMemberOf

import javax.lang.model.util.Types; //导入方法依赖的package包/类
/**
 * Resolves a {@link VariableElement} parameter to a method or constructor based on the given
 * container, or a member of a class. For parameters to a method or constructor, the variable's
 * enclosing element must be a supertype of the container type. For example, given a
 * {@code container} of type {@code Set<String>}, and a variable corresponding to the {@code E e}
 * parameter in the {@code Set.add(E e)} method, this will return a TypeMirror for {@code String}.
 */
public static TypeMirror asMemberOf(Types types, DeclaredType container,
                                    VariableElement variable) {
    if (variable.getKind().equals(ElementKind.PARAMETER)) {
        ExecutableElement methodOrConstructor =
                MoreElements.asExecutable(variable.getEnclosingElement());
        ExecutableType resolvedMethodOrConstructor = MoreTypes.asExecutable(
                types.asMemberOf(container, methodOrConstructor));
        List<? extends VariableElement> parameters = methodOrConstructor.getParameters();
        List<? extends TypeMirror> parameterTypes =
                resolvedMethodOrConstructor.getParameterTypes();
        checkState(parameters.size() == parameterTypes.size());
        for (int i = 0; i < parameters.size(); i++) {
            // We need to capture the parameter type of the variable we're concerned about,
            // for later printing.  This is the only way to do it since we can't use
            // types.asMemberOf on variables of methods.
            if (parameters.get(i).equals(variable)) {
                return parameterTypes.get(i);
            }
        }
        throw new IllegalStateException("Could not find variable: " + variable);
    } else {
        return types.asMemberOf(container, variable);
    }
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:32,代码来源:MoreTypes.java

示例4: asMemberOf

import javax.lang.model.util.Types; //导入方法依赖的package包/类
TypeMirror asMemberOf(Element element, TypeMirror type, Types types) {
    TypeMirror ret = element.asType();
    TypeMirror enclType = element.getEnclosingElement().asType();
    if (enclType.getKind() == TypeKind.DECLARED) {
        enclType = types.erasure(enclType);
    }
    while (type != null && type.getKind() == TypeKind.DECLARED) {
        if ((enclType.getKind() != TypeKind.DECLARED || ((DeclaredType) enclType).asElement().getSimpleName().length() > 0) && types.isSubtype(type, enclType)) {
            ret = types.asMemberOf((DeclaredType) type, element);
            break;
        }
        type = ((DeclaredType) type).getEnclosingType();
    }
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:BaseTask.java

示例5: asMemberOf

import javax.lang.model.util.Types; //导入方法依赖的package包/类
private static TypeMirror asMemberOf(Element element, TypeMirror type, Types types) {
    TypeMirror ret = element.asType();
    TypeMirror enclType = element.getEnclosingElement().asType();
    if (enclType.getKind() == TypeKind.DECLARED)
        enclType = types.erasure(enclType);
    while(type != null && type.getKind() == TypeKind.DECLARED) {
        if (types.isSubtype(type, enclType)) {
            ret = types.asMemberOf((DeclaredType)type, element);
            break;
        }
        type = ((DeclaredType)type).getEnclosingType();
    }
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:JavadocCompletionQuery.java

示例6: buildConstructors

import javax.lang.model.util.Types; //导入方法依赖的package包/类
/**
 * Build all constructors as they appear on the ArezComponent class.
 * Arez Observable fields are populated as required and parameters are passed up to superclass.
 */
private void buildConstructors( @Nonnull final TypeSpec.Builder builder,
                                @Nonnull final Types typeUtils )
{
  final boolean requiresDeprecatedSuppress = hasDeprecatedElements();
  for ( final ExecutableElement constructor : ProcessorUtil.getConstructors( getElement() ) )
  {
    final ExecutableType methodType =
      (ExecutableType) typeUtils.asMemberOf( (DeclaredType) _element.asType(), constructor );
    builder.addMethod( buildConstructor( constructor, methodType, requiresDeprecatedSuppress ) );
  }
}
 
开发者ID:arez,项目名称:arez,代码行数:16,代码来源:ComponentDescriptor.java

示例7: checkMimeLocation

import javax.lang.model.util.Types; //导入方法依赖的package包/类
private void checkMimeLocation(TypeElement clazz, AnnotationMirror am) {
    for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : am.getElementValues().entrySet()) {
        if (!e.getKey().getSimpleName().contentEquals("instanceProviderClass")) continue;

        TypeMirror ipc = (TypeMirror) e.getValue().getValue();

        if (ipc == null || ipc.getKind() != TypeKind.DECLARED) continue; //the compiler should have given the error

        TypeElement instanceProvider = processingEnv.getElementUtils().getTypeElement("org.netbeans.spi.editor.mimelookup.InstanceProvider");

        if (instanceProvider == null) {
            return ;
        }
        
        ExecutableElement createInstance = null;

        for (ExecutableElement ee : ElementFilter.methodsIn(instanceProvider.getEnclosedElements())) {
            if (ee.getSimpleName().contentEquals("createInstance")) { //TODO: check parameters
                createInstance = ee;
                break;
            }
        }

        if (createInstance == null) {
            throw new IllegalStateException("No instanceCreate in InstanceProvider!");
        }

        DeclaredType dipc = (DeclaredType) ipc;

        Types tu = processingEnv.getTypeUtils();
        ExecutableType member = (ExecutableType) tu.asMemberOf(dipc, createInstance);
        TypeMirror result = member.getReturnType();
        TypeMirror jlObject = processingEnv.getElementUtils().getTypeElement("java.lang.Object").asType();

        if (!tu.isSameType(tu.erasure(result), jlObject)) {
            if (!tu.isSubtype(tu.erasure(result), tu.erasure(clazz.asType()))) {
                processingEnv.getMessager().printMessage(Kind.ERROR, "The InstanceProvider does not create instances of type " + clazz.getQualifiedName(), clazz, am, e.getValue());
            }
        }

        TypeElement tipc = (TypeElement) dipc.asElement();

        if (!tipc.getModifiers().contains(Modifier.PUBLIC)) {
            processingEnv.getMessager().printMessage(Kind.ERROR, "The InstanceProvider implementation is not public.", clazz, am, e.getValue());
        }

        for (ExecutableElement c : ElementFilter.constructorsIn(tipc.getEnclosedElements())) {
            if (c.getParameters().isEmpty() && c.getModifiers().contains(Modifier.PUBLIC)) {
                //OK
                return;
            }
        }

        processingEnv.getMessager().printMessage(Kind.ERROR, "The InstanceProvider implementation does not provide a public no-arg constructor.", clazz, am, e.getValue());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:57,代码来源:CreateRegistrationProcessor.java

示例8: analyzeCandidateMethods

import javax.lang.model.util.Types; //导入方法依赖的package包/类
void analyzeCandidateMethods( @Nonnull final List<ExecutableElement> methods,
                              @Nonnull final Types typeUtils )
  throws ArezProcessorException
{
  final Map<String, CandidateMethod> getters = new HashMap<>();
  final Map<String, CandidateMethod> setters = new HashMap<>();
  final Map<String, CandidateMethod> trackeds = new HashMap<>();
  final Map<String, CandidateMethod> onDepsChangeds = new HashMap<>();
  for ( final ExecutableElement method : methods )
  {
    final ExecutableType methodType =
      (ExecutableType) typeUtils.asMemberOf( (DeclaredType) _element.asType(), method );
    if ( !analyzeMethod( method, methodType ) )
    {
      /*
       * If we get here the method was not annotated so we can try to detect if it is a
       * candidate @Observable in case some @Observables are not fully specified.
       */
      if ( method.getModifiers().contains( Modifier.FINAL ) )
      {
        continue;
      }
      else if ( method.getModifiers().contains( Modifier.STATIC ) )
      {
        continue;
      }

      final CandidateMethod candidateMethod = new CandidateMethod( method, methodType );
      final boolean voidReturn = method.getReturnType().getKind() == TypeKind.VOID;
      final int parameterCount = method.getParameters().size();
      String name;

      name = ProcessorUtil.deriveName( method, SETTER_PATTERN, ProcessorUtil.SENTINEL_NAME );
      if ( voidReturn && 1 == parameterCount && null != name )
      {
        setters.put( name, candidateMethod );
        continue;
      }
      name = ProcessorUtil.deriveName( method, ISSER_PATTERN, ProcessorUtil.SENTINEL_NAME );
      if ( !voidReturn && 0 == parameterCount && null != name )
      {
        getters.put( name, candidateMethod );
        continue;
      }
      name = ProcessorUtil.deriveName( method, GETTER_PATTERN, ProcessorUtil.SENTINEL_NAME );
      if ( !voidReturn && 0 == parameterCount && null != name )
      {
        getters.put( name, candidateMethod );
        continue;
      }
      name =
        ProcessorUtil.deriveName( method, TrackedDescriptor.ON_DEPS_CHANGED_PATTERN, ProcessorUtil.SENTINEL_NAME );
      if ( voidReturn && 0 == parameterCount && null != name )
      {
        onDepsChangeds.put( name, candidateMethod );
        continue;
      }

      final String methodName = method.getSimpleName().toString();
      if ( !OBJECT_METHODS.contains( methodName ) )
      {
        trackeds.put( methodName, candidateMethod );
      }
    }
  }

  linkUnAnnotatedObservables( getters, setters );
  linkUnAnnotatedTracked( trackeds, onDepsChangeds );
  linkObserverRefs();
}
 
开发者ID:arez,项目名称:arez,代码行数:71,代码来源:ComponentDescriptor.java


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