Java 类javax.lang.model.type.TypeMirror 实例源码

项目:incubator-netbeans    文件:SuspiciousToArray.java   
private void rewriteNewArrayTree(WorkingCopy copy, TreeMaker mk, TreePath natPath, TypeMirror compType) {
    NewArrayTree nat = (NewArrayTree)natPath.getLeaf();
    TypeMirror existing = copy.getTrees().getTypeMirror(natPath);
    int existingDim = numberOfDimensions(existing);
    int newDim = numberOfDimensions(compType);

    if (existingDim == newDim + 1 /* newDim is counted from component type, lacks the enclosing array */) {
        // simple, number of dimensions does not change
        copy.rewrite(nat.getType(), mk.Type(compType));
        return;
    }
    List<ExpressionTree> l = new ArrayList<ExpressionTree>(nat.getDimensions().subList(
            0, Math.min(newDim + 1, nat.getDimensions().size())));
    Tree replacement = mk.NewArray(mk.Type(compType), l, null);
    GeneratorUtilities.get(copy).copyComments(nat, replacement, true);
    GeneratorUtilities.get(copy).copyComments(nat, replacement, false);

    copy.rewrite(nat, replacement);
}
项目:java-code-templates    文件:AstSubstitutionProcessor.java   
private void handleVarDef(final JCVariableDecl node, final boolean endStatement) {
    final TreePath path = trees.getPath(compilationUnit, node);
    final TypeMirror typeMirror = trees.getElement(path).asType();

    printExpr(node.mods);
    print(substitutionInventory.applyTypeSubstitution(typeMirror));
    print(" ");
    print(node.name); // variable name
    if (node.init != null) {
        print(" = ");
        printExpr(node.init);
    }
    if (endStatement) {
        print(";");
    }
}
项目:incubator-netbeans    文件:MethodExitDetector.java   
private void addToExceptionsMap(TypeMirror key, Tree value) {
    if (key == null || value == null)
        return ;

    Map<TypeMirror, List<Tree>> map = exceptions2HighlightsStack.peek();

    if (map == null) {
        map = new HashMap<TypeMirror, List<Tree>>();
        exceptions2HighlightsStack.pop();
        exceptions2HighlightsStack.push(map);
    }

    List<Tree> l = map.get(key);

    if (l == null) {
        map.put(key, l = new ArrayList<Tree>());
    }

    l.add(value);
}
项目:incubator-netbeans    文件:BeanModelBuilder.java   
private void processGetters() {
    // Check presence !
    TypeMirror listType = compilationInfo.getElements().getTypeElement(LIST_CLASS).asType();
    TypeMirror mapType = compilationInfo.getElements().getTypeElement(MAP_CLASS).asType();
    for (ExecutableElement m : getters) {
        String n = getPropertyName(m.getSimpleName().toString());
        if (allProperties.containsKey(n)) {
            continue;
        }
        TypeMirror retType = m.getReturnType();
        TypeMirror erasure = compilationInfo.getTypes().erasure(retType);
        if (compilationInfo.getTypes().isAssignable(erasure, listType)) {
            addListProperty(m, n);
        } else if (compilationInfo.getTypes().isAssignable(erasure, mapType)) {
            addMapProperty(m, n);
        }
    }
}
项目:javaide    文件:PrintingProcessor.java   
private void printInterfaces(TypeElement e) {
    ElementKind kind = e.getKind();

    if(kind != ANNOTATION_TYPE) {
        List<? extends TypeMirror> interfaces = e.getInterfaces();
        if (interfaces.size() > 0) {
            writer.print((kind.isClass() ? " implements" : " extends"));

            boolean first = true;
            for(TypeMirror interf: interfaces) {
                if (!first)
                    writer.print(",");
                writer.print(" ");
                writer.print(interf.toString());
                first = false;
            }
        }
    }
}
项目:incubator-netbeans    文件:EnumValueCompleter.java   
@Override
public Completer createCompleter(CompletionContext ctx) {
    FxProperty p = ctx.getEnclosingProperty();
    if (p == null || p.getType() == null) {
        return null;
    }
    TypeMirror m = p.getType().resolve(ctx.getCompilationInfo());
    if (m.getKind() == TypeKind.BOOLEAN) {
        return new EnumValueCompleter(ctx);
    }
    if (m.getKind() != TypeKind.DECLARED) {
        return null;
    }
    DeclaredType t = (DeclaredType)m;
    TypeElement tel = (TypeElement)t.asElement();
    if (tel.getQualifiedName().contentEquals("java.lang.Boolean")) {
        return new EnumValueCompleter(ctx);
    }
    if (tel.getKind() == ElementKind.ENUM) {
        return new EnumValueCompleter(ctx, tel);
    } else {
        return null;
    }
}
项目:incubator-netbeans    文件:BeanModelBuilder.java   
private void addDependency(TypeMirror tm) {
    if (tm.getKind() == TypeKind.ARRAY) {
        addDependency(((ArrayType)tm).getComponentType());
    } else if (tm.getKind() == TypeKind.WILDCARD) {
        WildcardType wt = (WildcardType)tm;
        TypeMirror bound = wt.getSuperBound();
        if (bound == null) {
            bound = wt.getExtendsBound();
        }
        addDependency(bound);
    } else if (tm.getKind() == TypeKind.DECLARED) {
        addDependency(
            ((TypeElement)compilationInfo.getTypes().asElement(tm)).getQualifiedName().toString()
        );
    }
}
项目:annotation-processor-toolkit    文件:TypeUtils.java   
/**
 * Checks whether passed typeElement is assignable to passed genericType.
 *
 * @param typeMirror  the type element to check
 * @param genericType the genric type to check
 * @return true if typeElement is assignable to genericType otherwise false.
 */
public boolean genericIsAssignableTo(TypeMirror typeMirror, GenericType genericType) {

    if (typeMirror == null || genericType == null) {
        return false;
    }

    TypeMirror typeMirrorToCompareWith = genericType.getRawType();
    if (typeMirrorToCompareWith == null) {
        return false;
    }

    // Compare raw types - this will not work for super wildcard type since it has Object as raw type
    if (!typeComparison.isAssignableTo(getTypes().erasure(typeMirror), getTypes().erasure(typeMirrorToCompareWith))) {
        return false;
    }

    return isAssignableToGenericTypeRecursively(typeMirror, genericType);
}
项目:incubator-netbeans    文件:MethodExitDetector.java   
@Override
public Boolean visitCatch(CatchTree tree, Stack<Tree> d) {
    TypeMirror type1 = info.getTrees().getTypeMirror(new TreePath(new TreePath(getCurrentPath(), tree.getParameter()), tree.getParameter().getType()));
    Types t = info.getTypes();

    if (type1 != null) {
        Set<TypeMirror> toRemove = new HashSet<TypeMirror>();
        Map<TypeMirror, List<Tree>> exceptions2Highlights = exceptions2HighlightsStack.peek();

        if (exceptions2Highlights != null) {
            for (TypeMirror type2 : exceptions2Highlights.keySet()) {
                if (t.isAssignable(type2, type1)) {
                    toRemove.add(type2);
                }
            }

            for (TypeMirror type : toRemove) {
                exceptions2Highlights.remove(type);
            }
        }

    }

    scan(tree.getParameter(), d);
    return scan(tree.getBlock(), d);
}
项目:GitHub    文件:ButterKnifeProcessor.java   
/**
 * Returns a method name from the {@link android.content.res.Resources} class for array resource
 * binding, null if the element type is not supported.
 */
private static FieldResourceBinding.Type getArrayResourceMethodName(Element element) {
  TypeMirror typeMirror = element.asType();
  if (TYPED_ARRAY_TYPE.equals(typeMirror.toString())) {
    return FieldResourceBinding.Type.TYPED_ARRAY;
  }
  if (TypeKind.ARRAY.equals(typeMirror.getKind())) {
    ArrayType arrayType = (ArrayType) typeMirror;
    String componentType = arrayType.getComponentType().toString();
    if (STRING_TYPE.equals(componentType)) {
      return FieldResourceBinding.Type.STRING_ARRAY;
    } else if ("int".equals(componentType)) {
      return FieldResourceBinding.Type.INT_ARRAY;
    } else if ("java.lang.CharSequence".equals(componentType)) {
      return FieldResourceBinding.Type.TEXT_ARRAY;
    }
  }
  return null;
}
项目:android-auto-mapper    文件:MoreTypes.java   
/**
 * 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();
}
项目:incubator-netbeans    文件:CreateElementUtilities.java   
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    boolean errorInRealArguments = false;

    for (Tree param : nat.getArguments()) {
        errorInRealArguments |= param == error;
    }

    if (errorInRealArguments) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);

        if (ee.isEmpty()) { //cannot be resolved
            return null;
        }

        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);

        return proposedTypes;
    }

    return null;
}
项目:GitHub    文件:Proto.java   
@Value.Lazy
List<TypeElement> builderIncludedTypes() {
  Optional<FIncludeMirror> includes = builderInclude();

  ImmutableList<TypeMirror> typeMirrors = includes.isPresent()
      ? ImmutableList.copyOf(includes.get().valueMirror())
      : ImmutableList.<TypeMirror>of();

  FluentIterable<TypeElement> typeElements = FluentIterable.from(typeMirrors)
      .filter(DeclaredType.class)
      .transform(DeclatedTypeToElement.FUNCTION);

  ImmutableSet<String> uniqueTypeNames = typeElements
      .filter(IsPublic.PREDICATE)
      .transform(ElementToName.FUNCTION)
      .toSet();

  if (uniqueTypeNames.size() != typeMirrors.size()) {
    report().annotationNamed(IncludeMirror.simpleName())
        .warning("Some types were ignored, non-supported for inclusion: duplicates,"
            + " non declared reference types, non-public");
  }

  return typeElements.toList();
}
项目:incubator-netbeans    文件:EntityMappingsUtilitiesTest.java   
public void testGetFirstTypeArgument() throws Exception {
    ClasspathInfo cpi = ClasspathInfo.create(srcFO);
    final AnnotationModelHelper helper = AnnotationModelHelper.create(cpi);
    helper.runJavaSourceTask(new Runnable() {
        public void run() {
            Elements elements = helper.getCompilationController().getElements();
            Types types = helper.getCompilationController().getTypes();
            TypeElement typeElement = elements.getTypeElement("java.util.Collection");
            // Collection<E>
            assertNull(EntityMappingsUtilities.getFirstTypeArgument(typeElement.asType()));
            // Collection
            assertNull(EntityMappingsUtilities.getFirstTypeArgument(types.erasure(typeElement.asType())));
            // Collection<String>
            TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
            TypeElement argTypeElement = EntityMappingsUtilities.getFirstTypeArgument(types.getDeclaredType(typeElement, stringType));
            assertTrue(argTypeElement.getQualifiedName().contentEquals("java.lang.String"));
        }
    });
}
项目:incubator-netbeans    文件:ControllerGenerator.java   
@Override
public TypeMirror visitDeclared(DeclaredType t, CompilationInfo p) {
    if (t.getTypeArguments().isEmpty()) {
        return t;
    }
    List<TypeMirror> newArgs = new ArrayList<TypeMirror>(t.getTypeArguments().size());
    for (TypeMirror tm : t.getTypeArguments()) {
        newArgs.add(visit(tm, p));
    }

    TypeMirror enclosing = t.getEnclosingType();
    if (enclosing != null) {
        enclosing = visit(enclosing, p);
    }

    return p.getTypes().getDeclaredType(
        (DeclaredType)enclosing,
        (TypeElement)t.asElement(), 
        newArgs.toArray(new TypeMirror[newArgs.size()]));
}
项目:incubator-netbeans    文件:MethodExitDetector.java   
@Override
public Boolean visitMethodInvocation(MethodInvocationTree tree, Stack<Tree> d) {
    Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), tree.getMethodSelect()));

    if (el == null) {
        System.err.println("Warning: decl == null");
        System.err.println("tree=" + tree);
    }

    if (el != null && el.getKind() == ElementKind.METHOD) {
        for (TypeMirror m : ((ExecutableElement) el).getThrownTypes()) {
            addToExceptionsMap(m, tree);
        }
    }

    super.visitMethodInvocation(tree, d);
    return null;
}
项目:OpenJSharp    文件:TypeModeler.java   
public static TypeElement getDeclaringClassMethod(TypeElement theClass, String methodName, TypeMirror[] args) {

        TypeElement retClass = null;
        if (theClass.getKind().equals(ElementKind.CLASS)) {
            TypeMirror superClass = theClass.getSuperclass();
            if (!superClass.getKind().equals(TypeKind.NONE))
                retClass = getDeclaringClassMethod(superClass, methodName, args);
        }
        if (retClass == null) {
            for (TypeMirror interfaceType : theClass.getInterfaces()) {
                retClass = getDeclaringClassMethod(interfaceType, methodName, args);
            }
        }
        if (retClass == null) {
            Collection<? extends ExecutableElement> methods = ElementFilter.methodsIn(theClass.getEnclosedElements());
            for (ExecutableElement method : methods) {
                if (method.getSimpleName().toString().equals(methodName)) {
                    retClass = theClass;
                    break;
                }
            }
        }
        return retClass;
    }
项目:GitHub    文件:ViewStateProviderClassGenerator.java   
private String getViewClassFromAnnotationParams(TypeElement typeElement) {
    InjectViewState annotation = typeElement.getAnnotation(InjectViewState.class);
    String mvpViewClassName = "";

    if (annotation != null) {
        TypeMirror value = null;
        try {
            annotation.view();
        } catch (MirroredTypeException mte) {
            value = mte.getTypeMirror();
        }

        mvpViewClassName = Util.getFullClassName(value);
    }

    if (mvpViewClassName.isEmpty() || DefaultView.class.getName().equals(mvpViewClassName)) {
        return null;
    }

    return mvpViewClassName;
}
项目:GitHub    文件:ViewStateProviderClassGenerator.java   
private String getViewStateClassFromAnnotationParams(TypeElement typeElement) {
    InjectViewState annotation = typeElement.getAnnotation(InjectViewState.class);
    String mvpViewStateClassName = "";

    if (annotation != null) {
        TypeMirror value;
        try {
            annotation.value();
        } catch (MirroredTypeException mte) {
            value = mte.getTypeMirror();
            mvpViewStateClassName = value.toString();
        }
    }

    if (mvpViewStateClassName.isEmpty() || DefaultViewState.class.getName().equals(mvpViewStateClassName)) {
        return null;
    }

    return mvpViewStateClassName;
}
项目:inspector    文件:InspectorFactoryProcessor.java   
private boolean searchInterfacesAncestry(TypeMirror rootIface, TypeMirror target) {
  TypeElement rootIfaceElement = (TypeElement) typeUtils.asElement(rootIface);
  // check if it implements valid interfaces
  for (TypeMirror iface : rootIfaceElement.getInterfaces()) {
    TypeElement ifaceElement = (TypeElement) typeUtils.asElement(rootIface);
    while (iface.getKind() != TypeKind.NONE) {
      if (typeUtils.isSameType(iface, target)) {
        return true;
      }
      // go up
      if (searchInterfacesAncestry(iface, target)) {
        return true;
      }
      // then move on
      iface = ifaceElement.getSuperclass();
    }
  }
  return false;
}
项目:butterknife-parent    文件:ButterKnifeProcessor.java   
/**
 * Returns a method name from the {@link android.content.res.Resources} class for array resource
 * binding, null if the element type is not supported.
 */
private static FieldResourceBinding.Type getArrayResourceMethodName(Element element) {
  TypeMirror typeMirror = element.asType();
  if (TYPED_ARRAY_TYPE.equals(typeMirror.toString())) {
    return FieldResourceBinding.Type.TYPED_ARRAY;
  }
  if (TypeKind.ARRAY.equals(typeMirror.getKind())) {
    ArrayType arrayType = (ArrayType) typeMirror;
    String componentType = arrayType.getComponentType().toString();
    if (STRING_TYPE.equals(componentType)) {
      return FieldResourceBinding.Type.STRING_ARRAY;
    } else if ("int".equals(componentType)) {
      return FieldResourceBinding.Type.INT_ARRAY;
    } else if ("java.lang.CharSequence".equals(componentType)) {
      return FieldResourceBinding.Type.TEXT_ARRAY;
    }
  }
  return null;
}
项目:GitHub    文件:PresenterInjectorRules.java   
private void checkEnvironment(final Element annotatedField) {
    if (!(annotatedField.asType() instanceof DeclaredType)) {
        return;
    }

    TypeElement typeElement = (TypeElement) ((DeclaredType) annotatedField.asType()).asElement();
    String viewClassFromGeneric = getViewClassFromGeneric(typeElement, (DeclaredType) annotatedField.asType());

    Collection<TypeMirror> viewsType = getViewsType((TypeElement) ((DeclaredType) annotatedField.getEnclosingElement().asType()).asElement());

    boolean result = false;

    for (TypeMirror typeMirror : viewsType) {
        if (Util.getFullClassName(typeMirror).equals(viewClassFromGeneric) || Util.fillGenerics(Collections.<String, String>emptyMap(), typeMirror).equals(viewClassFromGeneric)) {
            result = true;
            break;
        }
    }
    if (!result) {
        MvpCompiler.getMessager().printMessage(Diagnostic.Kind.ERROR, "You can not use @InjectPresenter in classes that are not View, which is typified target Presenter", annotatedField);
    }
}
项目:easyprefs    文件:ExposedMethod.java   
public ExposedMethod(Element element) {
    ExecutableType method = (ExecutableType) element.asType();
    TypeElement declaringClass = (TypeElement) element.getEnclosingElement();
    this.name = element.getSimpleName().toString();
    this.originalMethod = declaringClass.getQualifiedName().toString() + "." + element.getSimpleName();
    this.returnType = method.getReturnType().toString();
    this.params = new ArrayList<>();
    int count = 0;
    for (TypeMirror param : method.getParameterTypes()) {
        this.params.add(param.toString());
        String[] components = param.toString().toLowerCase().split("\\.");
        String paramName = components[components.length - 1];
        if (paramName.endsWith(">")) {
            paramName = paramName.substring(0, paramName.length() - 1);
        }
        this.params.add(paramName + count);
        count++;
    }
    this.thrown = Stream.of(method.getThrownTypes()).map(new Function<TypeMirror, String>() {
        @Override
        public String apply(TypeMirror typeMirror) {
            return typeMirror.toString();
        }
    }).toList();
}
项目:GitHub    文件:PresenterInjectorRules.java   
private Collection<TypeMirror> getViewsType(TypeElement typeElement) {
    TypeMirror superclass = typeElement.asType();

    List<TypeMirror> result = new ArrayList<>();

    while (superclass.getKind() != TypeKind.NONE) {
        TypeElement superclassElement = (TypeElement) ((DeclaredType) superclass).asElement();
        Collection<? extends TypeMirror> interfaces = new HashSet<>(superclassElement.getInterfaces());
        for (TypeMirror typeMirror : interfaces) {
            if (typeMirror instanceof DeclaredType) {
                result.addAll(getViewsType((TypeElement) ((DeclaredType) typeMirror).asElement()));
            }
        }
        result.addAll(interfaces);
        result.add(superclass);

        superclass = superclassElement.getSuperclass();
    }

    return result;
}
项目:domino    文件:RequestFactorySourceWriter.java   
private TypeSpec makeRequestClass(ExecutableElement method) {

        TypeName requestTypeName = getRequestClassName(method);
        DeclaredType responseReturnType = (DeclaredType) method.getReturnType();
        TypeMirror responseBean = responseReturnType.getTypeArguments().get(0);


        TypeSpec.Builder requestBuilder = TypeSpec.classBuilder(processorElement.simpleName() + "_" + method.getSimpleName())
                .addModifiers(Modifier.PUBLIC)
                .superclass(ParameterizedTypeName.get(ClassName.get(ServerRequest.class),
                        requestTypeName,
                        ClassName.get(responseBean)))
                .addMethod(constructor(requestTypeName));

        requestBuilder.addAnnotation(AnnotationSpec.builder(Request.class).build());
        requestBuilder.addAnnotation(pathAnnotation(method.getAnnotation(Path.class)));

        return requestBuilder.build();
    }
项目:affinechecker    文件:AffinePointerValue.java   
private AnnotatedTypeVariable getEffectTypeVar(TypeMirror typeMirror) {
    if (typeMirror == null) {
        return null;
    } else if (typeMirror.getKind() == TypeKind.WILDCARD) {
        return getEffectTypeVar(((WildcardType) typeMirror).getExtendsBound());

    } else if (typeMirror.getKind() == TypeKind.TYPEVAR) {
        TypeVariable typevar = ((TypeVariable) typeMirror);
        AnnotatedTypeMirror atm =
                analysis.getTypeFactory().getAnnotatedType(typevar.asElement());
        return (AnnotatedTypeVariable) atm;
    } else {
        return null;
    }
}
项目:incubator-netbeans    文件:JDIWrappersTest.java   
private TypeMirror adjustTypeMirror(TypeMirror tm) {
    if (tm.getKind() == TypeKind.EXECUTABLE) {
        tm = ((ExecutableType) tm).getReturnType();
        tm = adjustTypeMirror(tm);
    } else if (tm.getKind() == TypeKind.ARRAY) {
        tm = ((ArrayType) tm).getComponentType();
        tm = adjustTypeMirror(tm);
    }
    return tm;
}
项目:data-mediator    文件:ElementHandle.java   
public static Method create(ExecutableElement elt) { 
  TypeElement typeElt = (TypeElement)elt.getEnclosingElement(); 
  String name = elt.getSimpleName().toString(); 
  FQN fqn = new FQN(typeElt.getQualifiedName().toString()); 
  ArrayList<String> parameterTypes = new ArrayList<String>(); 
  for (TypeMirror parameterType : ((ExecutableType)elt.asType()).getParameterTypes()) {
    parameterTypes.add(parameterType.toString()); 
  } 

  return new Method(fqn, name, parameterTypes); 
}
项目:incubator-netbeans    文件:ExpectedTypeResolver.java   
@Override
public List<? extends TypeMirror> visitDoWhileLoop(DoWhileLoopTree node, Object p) {
    if (theExpression == null) {
        initExpression(node.getCondition());
    } else if (theExpression.getLeaf() != node.getCondition()) {
        return null;
    }
    return booleanType();
}
项目:Witch-Android    文件:AnnotationUtils.java   
public static TypeMirror getOnBindTypeMirror(Element action) {
    TypeMirror bindClass;
    try {
        action.getAnnotation(se.snylt.witch.annotations.OnBind.class).value();
        return null;
    } catch (MirroredTypeException mte) {
        bindClass = mte.getTypeMirror();
    }
    return bindClass;
}
项目:OpenJSharp    文件:JavacTrees.java   
/**
 * Gets the original type from the ErrorType object.
 * @param errorType The errorType for which we want to get the original type.
 * @returns TypeMirror corresponding to the original type, replaced by the ErrorType.
 *          noType (type.tag == NONE) is returned if there is no original type.
 */
public TypeMirror getOriginalType(javax.lang.model.type.ErrorType errorType) {
    if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType) {
        return ((com.sun.tools.javac.code.Type.ErrorType)errorType).getOriginalType();
    }

    return com.sun.tools.javac.code.Type.noType;
}
项目:incubator-netbeans    文件:ExtractSuperclassRefactoringPlugin.java   
private static MethodTree removeRuntimeExceptions(final WorkingCopy javac, ExecutableElement superclassConstr, final TreeMaker make, MethodTree newConstr) {
    int i = 0;
    TypeMirror rte = javac.getElements().getTypeElement("java.lang.RuntimeException").asType(); //NOI18N
    ArrayList<Integer> rtes = new ArrayList<Integer>();
    for (TypeMirror throwz : superclassConstr.getThrownTypes()) {
        if (javac.getTypes().isSubtype(throwz, rte)) {
            rtes.add(i);
        }
        i++;
    }
    for (int j = rtes.size()-1; j >= 0; j--) {
        newConstr = make.removeMethodThrows(newConstr, rtes.get(j));
    }
    return newConstr;
}
项目:openjdk-jdk10    文件:JavacTrees.java   
/**
 * Returns the original type from the ErrorType object.
 * @param errorType The errorType for which we want to get the original type.
 * @return TypeMirror corresponding to the original type, replaced by the ErrorType.
 *         noType (type.tag == NONE) is returned if there is no original type.
 */
@Override @DefinedBy(Api.COMPILER_TREE)
public TypeMirror getOriginalType(javax.lang.model.type.ErrorType errorType) {
    if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType) {
        return ((com.sun.tools.javac.code.Type.ErrorType)errorType).getOriginalType();
    }

    return com.sun.tools.javac.code.Type.noType;
}
项目:incubator-netbeans    文件:ResourceStringFoldProvider.java   
private void processGetBundleCall(MethodInvocationTree node) {
    TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
    if (resourceBundleType == null ||tm == null || tm.getKind() != TypeKind.DECLARED) {
        return;
    }
    if (!info.getTypes().isAssignable(tm, resourceBundleType)) {
        return;
    }

    // OK, get the parameter said to describe the bundle name
    exprBundleName = getBundleName(node, messageMethod.getBundleParam(), messageMethod.getBundleFile());
}
项目:incubator-netbeans    文件:LookupProviderAnnotationProcessor.java   
private List<TypeMirror> findServiceAnnotation(Element e) throws LayerGenerationException {
    for (AnnotationMirror ann : e.getAnnotationMirrors()) {
        if (!ProjectServiceProvider.class.getName().equals(ann.getAnnotationType().toString())) {
            continue;
        }
        for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> attr : ann.getElementValues().entrySet()) {
            if (!attr.getKey().getSimpleName().contentEquals("service")) {
                continue;
            }
            List<TypeMirror> r = new ArrayList<TypeMirror>();
            for (Object item : (List<?>) attr.getValue().getValue()) {
                TypeMirror type = (TypeMirror) ((AnnotationValue) item).getValue();
                Types typeUtils = processingEnv.getTypeUtils();
                for (TypeMirror otherType : r) {
                    for (boolean swap : new boolean[] {false, true}) {
                        TypeMirror t1 = swap ? type : otherType;
                        TypeMirror t2 = swap ? otherType : type;
                        if (typeUtils.isSubtype(t1, t2)) {
                            processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "registering under both " + typeUtils.asElement(t2).getSimpleName() + " and its subtype " + typeUtils.asElement(t1).getSimpleName() + " will not work if LookupMerger<" + typeUtils.asElement(t2).getSimpleName() + "> is used (#205151)", e, ann, attr.getValue());
                        }
                    }
                }
                r.add(type);
            }
            return r;
        }
        throw new LayerGenerationException("No service attr found", e);
    }
    throw new LayerGenerationException("No @ProjectServiceProvider found", e);
}
项目:incubator-netbeans    文件:MethodExitDetector.java   
private void doPopup() {
    Map<TypeMirror, List<Tree>> top = exceptions2HighlightsStack.pop();

    if (top == null)
        return ;

    Map<TypeMirror, List<Tree>> result = exceptions2HighlightsStack.pop();

    if (result == null) {
        exceptions2HighlightsStack.push(top);
        return ;
    }

    for (TypeMirror key : top.keySet()) {
        List<Tree> topKey    = top.get(key);
        List<Tree> resultKey = result.get(key);

        if (topKey == null)
            continue;

        if (resultKey == null) {
            result.put(key, topKey);
            continue;
        }

        resultKey.addAll(topKey);
    }

    exceptions2HighlightsStack.push(result);
}
项目:RapidRouter    文件:RouterProcessor.java   
private static TypeMirror getParamTypeMirror(RRParam rrParam) {
    try {
        rrParam.type();
    } catch (MirroredTypeException mte) {
        return mte.getTypeMirror();
    }
    return null;
}
项目:incubator-netbeans    文件:TransformationSupport.java   
/**
 * Performs transformation described by transformationJackpotPattern on all occurences described by inputJackpotPattern.
 * @param inputJackpotPattern
 * @param transformationJackpotPattern
 * @param cancel 
 * @return
 */
private static Collection<? extends ModificationResult> performTransformation(String inputJackpotPattern, final String transformationJackpotPattern, AtomicBoolean cancel) {
    return performTransformation(inputJackpotPattern, new Transformer() {

        @Override
        public void transform(WorkingCopy copy, Occurrence occurrence) {
            try {
                Fix toFix = TransformationSupport.rewriteFix(copy, "whatever", occurrence.getOccurrenceRoot(), transformationJackpotPattern, occurrence.getVariables(), occurrence.getMultiVariables(), occurrence.getVariables2Names(), Collections.<String, TypeMirror>emptyMap(), Collections.<String, String>emptyMap());
                TransformationSupport.process(((JavaFixImpl) toFix).jf, copy, false, null, new ArrayList<RefactoringElementImplementation>());
            } catch (Exception ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }, cancel);
}
项目:dataenum    文件:ValueParser.java   
private static boolean isValueSpecMarker(
    TypeMirror returnType, ProcessingEnvironment processingEnvironment) {
  Types types = processingEnvironment.getTypeUtils();
  Elements elements = processingEnvironment.getElementUtils();

  return types.isSameType(
      returnType, elements.getTypeElement(dataenum_case.class.getCanonicalName()).asType());
}
项目:incubator-netbeans    文件:TypeUtilitiesTest.java   
public void testSubstitute() throws Exception {
    JavaSource js = JavaSource.create(ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])), ClassPathSupport.createClassPath(new URL[0]), ClassPathSupport.createClassPath(new URL[0])));

    js.runUserActionTask(new Task<CompilationController>() {
        public void run(CompilationController info)  {
            TypeElement jlStringElement = info.getElements().getTypeElement("java.lang.String");
            TypeMirror jlString = info.getTypes().getDeclaredType(jlStringElement);
            TypeElement juListElement = info.getElements().getTypeElement("java.util.List");
            TypeMirror juListString = info.getTypes().getDeclaredType(juListElement, jlString);

            DeclaredType juListType = (DeclaredType) juListElement.asType();
            TypeMirror substituted = info.getTypeUtilities().substitute(juListType, juListType.getTypeArguments(), Collections.singletonList(jlString));

            assertTrue(info.getTypes().isSameType(juListString, substituted));

            boolean wasThrown = false;

            try {
                info.getTypeUtilities().substitute(juListType, juListType.getTypeArguments(), Collections.<TypeMirror>emptyList());
            } catch (IllegalArgumentException ex) {
                wasThrown = true;
            }

            assertTrue(wasThrown);
        }
    }, true);

}