當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。