Java Code Examples for javax.lang.model.type.TypeKind#ERROR
The following examples show how to use
javax.lang.model.type.TypeKind#ERROR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeAnnotations.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private void locateNestedTypes(Type type, TypeAnnotationPosition p) { // The number of "steps" to get from the full type to the // left-most outer type. ListBuffer<TypePathEntry> depth = new ListBuffer<>(); Type encl = type.getEnclosingType(); while (encl != null && encl.getKind() != TypeKind.NONE && encl.getKind() != TypeKind.ERROR) { depth = depth.append(TypePathEntry.INNER_TYPE); encl = encl.getEnclosingType(); } if (depth.nonEmpty()) { p.location = p.location.prependList(depth.toList()); } }
Example 2
Source File: AnnotationObjectProvider.java From netbeans with Apache License 2.0 | 6 votes |
static void findQualifiers(Element element , AnnotationModelHelper helper , boolean event , AnnotationHandleStrategy strategy ) { List<? extends AnnotationMirror> allAnnotationMirrors = helper.getCompilationController().getElements(). getAllAnnotationMirrors( element ); for (AnnotationMirror annotationMirror : allAnnotationMirrors) { DeclaredType annotationType = annotationMirror .getAnnotationType(); if ( annotationType == null || annotationType.getKind() == TypeKind.ERROR){ continue; } TypeElement annotationElement = (TypeElement) annotationType .asElement(); if (annotationElement!= null && isQualifier(annotationElement, helper , event )) { strategy.handleAnnotation(annotationMirror , annotationElement ); } } }
Example 3
Source File: TypeAnnotations.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private void locateNestedTypes(Type type, TypeAnnotationPosition p) { // The number of "steps" to get from the full type to the // left-most outer type. ListBuffer<TypePathEntry> depth = new ListBuffer<>(); Type encl = type.getEnclosingType(); while (encl != null && encl.getKind() != TypeKind.NONE && encl.getKind() != TypeKind.ERROR) { depth = depth.append(TypePathEntry.INNER_TYPE); encl = encl.getEnclosingType(); } if (depth.nonEmpty()) { p.location = p.location.prependList(depth.toList()); } }
Example 4
Source File: AccessorAttributesCollector.java From immutables with Apache License 2.0 | 6 votes |
static TypeMirror resolveReturnType( ProcessingEnvironment processing, ExecutableElement method, TypeElement typeElement) { method = CachingElements.getDelegate(method); TypeMirror returnType = method.getReturnType(); // We do not support parametrized accessor methods, // but we do support inheriting parametrized accessors, which // we supposedly parametrized with actual type parameters as // our target class could not define formal type parameters also. if (returnType.getKind() == TypeKind.TYPEVAR) { return asInheritedMemberReturnType(processing, typeElement, method); } else if (returnType.getKind() == TypeKind.DECLARED || returnType.getKind() == TypeKind.ERROR) { if (!((DeclaredType) returnType).getTypeArguments().isEmpty()) { return asInheritedMemberReturnType(processing, typeElement, method); } } return returnType; }
Example 5
Source File: TypeUtils.java From jackdaw with Apache License 2.0 | 6 votes |
public static TypeName getTypeName(final Element element, final boolean wrap) { final TypeMirror typeMirror = getTypeMirror(element); final TypeKind kind = typeMirror.getKind(); if (kind == TypeKind.ERROR) { final ProcessorContext context = ProcessorContextHolder.getContext(); final Collection<ProcessorSourceContext> sourceContexts = context.getSourceContexts(); final String typeName = String.valueOf(typeMirror); final TypeElement originElement = ProcessorSourceContext.guessOriginElement(sourceContexts, typeName); if (originElement != null) { final String packageName = ProcessorUtils.packageName(originElement); return ClassName.get(packageName, typeName); } return ClassName.bestGuess(typeName); } return TypeName.get(wrap ? ProcessorUtils.getWrappedType(typeMirror).asType() : typeMirror); }
Example 6
Source File: ElementUtilities.java From netbeans with Apache License 2.0 | 6 votes |
/** * Checks whether 'e' contains error or is missing. If the passed element is null * it's assumed the element could not be resolved and this method returns true. Otherwise, * the element's type kind is checked against error constants and finally the erroneous * state of the element is checked. * * @param e Element to check or {@code null} * @return true, if the element is missing (is {@code null}) or contains errors. */ public boolean isErroneous(@NullAllowed Element e) { if (e == null) { return true; } if (e.getKind() == ElementKind.MODULE && ((Symbol)e).kind == Kinds.Kind.ERR) { return true; } final TypeMirror type = e.asType(); if (type == null) { return false; } if (type.getKind() == TypeKind.ERROR || type.getKind() == TypeKind.OTHER) { return true; } if (type instanceof Type) { if (((Type)type).isErroneous()) { return true; } } return false; }
Example 7
Source File: TypeErroneous.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Object visitDeclared(DeclaredType t, Object p) { Element e = t.asElement(); if (e == null) { unknownDeclaredTypes.add(t); } else { TypeMirror back = e.asType(); if (back == null || back.getKind() == TypeKind.ERROR) { unknownDeclaredTypes.add(t); } } return super.visitDeclared(t, p); }
Example 8
Source File: SourceUtils.java From netbeans with Apache License 2.0 | 5 votes |
public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) { Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext(); if (from.getKind() == TypeKind.TYPEVAR) { Types types = Types.instance(c); TypeVar t = types.substBound((TypeVar)from, com.sun.tools.javac.util.List.of((Type)from), com.sun.tools.javac.util.List.of(types.boxedTypeOrType((Type)to))); return info.getTypes().isAssignable(t.getUpperBound(), to) || info.getTypes().isAssignable(to, t.getUpperBound()); } if (from.getKind() == TypeKind.WILDCARD) { from = Types.instance(c).wildUpperBound((Type)from); } return Check.instance(c).checkType(null, (Type)from, (Type)to).getKind() != TypeKind.ERROR; }
Example 9
Source File: CompletionTestBase.java From netbeans with Apache License 2.0 | 5 votes |
@Override public CI createArrayItem(CompilationInfo info, ArrayType type, int substitutionOffset, ReferencesCount referencesCount, Elements elements) { int dim = 0; TypeMirror tm = type; while(tm.getKind() == TypeKind.ARRAY) { tm = ((ArrayType)tm).getComponentType(); dim++; } if (tm.getKind().isPrimitive()) { String kwd = tm.toString(); StringBuilder sb = new StringBuilder(kwd); for(int i = 0; i < dim; i++) { sb.append("[]"); //NOI18N } return new CI(sb.toString(), 670 - SMART_TYPE, kwd); } if (tm.getKind() == TypeKind.DECLARED || tm.getKind() == TypeKind.ERROR) { DeclaredType dt = (DeclaredType)tm; TypeElement elem = (TypeElement)dt.asElement(); String simpleName = elem.getSimpleName().toString(); String fqn = elem.getQualifiedName().toString(); int weight = 50; if (fqn.startsWith("java.lang") || fqn.startsWith("java.util")) { // NOI18N weight -= 10; } else if (fqn.startsWith("org.omg") || fqn.startsWith("org.apache")) { // NOI18N weight += 10; } else if (fqn.startsWith("com.sun") || fqn.startsWith("com.ibm") || fqn.startsWith("com.apple")) { // NOI18N weight += 20; } else if (fqn.startsWith("sun") || fqn.startsWith("sunw") || fqn.startsWith("netscape")) { // NOI18N weight += 30; } return new CI(simpleName, 800 - SMART_TYPE, referencesCount != null ? simpleName + '#' + weight + '#' + info.getElementUtilities().getElementName(elem.getEnclosingElement(), true) : simpleName); } throw new IllegalArgumentException("array element kind=" + tm.getKind()); }
Example 10
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 5 votes |
private TypeMirror purify(CompilationInfo info, TypeMirror targetType) { if (targetType != null && targetType.getKind() == TypeKind.ERROR) { targetType = info.getTrees().getOriginalType((ErrorType) targetType); } if (targetType == null || targetType.getKind() == /*XXX:*/TypeKind.ERROR || targetType.getKind() == TypeKind.NONE || targetType.getKind() == TypeKind.NULL) return null; return Utilities.resolveCapturedType(info, targetType); }
Example 11
Source File: Utilities.java From netbeans with Apache License 2.0 | 4 votes |
private static boolean isError(TypeMirror type) { return type == null || type.getKind() == TypeKind.ERROR; }
Example 12
Source File: TurbineTypeMirror.java From turbine with Apache License 2.0 | 4 votes |
@Override public TypeKind getKind() { return TypeKind.ERROR; }
Example 13
Source File: ButterKnifeProcessor.java From butterknife with Apache License 2.0 | 4 votes |
private void parseBindView(Element element, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) { TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); // Start by verifying common generated code restrictions. boolean hasError = isInaccessibleViaGeneratedCode(BindView.class, "fields", element) || isBindingInWrongPackage(BindView.class, element); // Verify that the target type extends from View. TypeMirror elementType = element.asType(); if (elementType.getKind() == TypeKind.TYPEVAR) { TypeVariable typeVariable = (TypeVariable) elementType; elementType = typeVariable.getUpperBound(); } Name qualifiedName = enclosingElement.getQualifiedName(); Name simpleName = element.getSimpleName(); if (!isSubtypeOfType(elementType, VIEW_TYPE) && !isInterface(elementType)) { if (elementType.getKind() == TypeKind.ERROR) { note(element, "@%s field with unresolved type (%s) " + "must elsewhere be generated as a View or interface. (%s.%s)", BindView.class.getSimpleName(), elementType, qualifiedName, simpleName); } else { error(element, "@%s fields must extend from View or be an interface. (%s.%s)", BindView.class.getSimpleName(), qualifiedName, simpleName); hasError = true; } } if (hasError) { return; } // Assemble information on the field. int id = element.getAnnotation(BindView.class).value(); BindingSet.Builder builder = builderMap.get(enclosingElement); Id resourceId = elementToId(element, BindView.class, id); if (builder != null) { String existingBindingName = builder.findExistingBindingName(resourceId); if (existingBindingName != null) { error(element, "Attempt to use @%s for an already bound ID %d on '%s'. (%s.%s)", BindView.class.getSimpleName(), id, existingBindingName, enclosingElement.getQualifiedName(), element.getSimpleName()); return; } } else { builder = getOrCreateBindingBuilder(builderMap, enclosingElement); } String name = simpleName.toString(); TypeName type = TypeName.get(elementType); boolean required = isFieldRequired(element); builder.addField(resourceId, new FieldViewBinding(name, type, required)); // Add the type-erased version to the valid binding targets set. erasedTargetNames.add(enclosingElement); }
Example 14
Source File: VanillaCompileWorker.java From netbeans with Apache License 2.0 | 4 votes |
private boolean isErroneousClass(Element el) { return el instanceof ClassSymbol && (((ClassSymbol) el).asType() == null || ((ClassSymbol) el).asType().getKind() == TypeKind.ERROR); }
Example 15
Source File: HintsInvoker.java From netbeans with Apache License 2.0 | 4 votes |
private Map<HintDescription, List<ErrorDescription>> doComputeHints(CompilationInfo info, Map<String, Collection<TreePath>> occurringPatterns, Map<String, List<PatternDescription>> patterns, Map<PatternDescription, List<HintDescription>> patternHints, Collection<? super MessageImpl> problems) throws IllegalStateException { Map<HintDescription, List<ErrorDescription>> errors = new HashMap<HintDescription, List<ErrorDescription>>(); for (Entry<String, Collection<TreePath>> occ : occurringPatterns.entrySet()) { PATTERN_LOOP: for (PatternDescription d : patterns.get(occ.getKey())) { if (cancel.get()) return null; Map<String, TypeMirror> constraints = new HashMap<String, TypeMirror>(); for (Entry<String, String> e : d.getConstraints().entrySet()) { TypeMirror designedType = Hacks.parseFQNType(info, e.getValue()); if (designedType == null || designedType.getKind() == TypeKind.ERROR) { //will not bind to anything anyway (#190449), skip pattern: continue PATTERN_LOOP; } constraints.put(e.getKey(), designedType); } Pattern pattern = PatternCompiler.compile(info, occ.getKey(), constraints, d.getImports()); for (TreePath candidate : occ.getValue()) { if (cancel.get()) return null; Iterator<? extends Occurrence> verified = Matcher.create(info).setCancel(cancel).setSearchRoot(candidate).setTreeTopSearch().setKeepSyntheticTrees().match(pattern).iterator(); if (!verified.hasNext()) { continue; } Set<String> suppressedWarnings = new HashSet<String>(Utilities.findSuppressedWarnings(info, candidate)); Occurrence verifiedVariables = verified.next(); boolean guarded = isInGuarded(info, candidate); for (HintDescription hd : patternHints.get(d)) { HintMetadata hm = hd.getMetadata(); // skip guarded sections if (guarded && !hd.getTrigger().hasOption(TriggerOptions.PROCESS_GUARDED)) { continue; } HintContext c = SPIAccessor.getINSTANCE().createHintContext(info, settings, hm, candidate, verifiedVariables.getVariables(), verifiedVariables.getMultiVariables(), verifiedVariables.getVariables2Names(), constraints, problems, bulkMode, cancel, caret); if (!Collections.disjoint(suppressedWarnings, hm.suppressWarnings)) continue; Collection<? extends ErrorDescription> workerErrors = runHint(hd, c); if (workerErrors != null) { merge(errors, hd, workerErrors); } } } } } return errors; }
Example 16
Source File: SourceCodeAnalysisImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private List<Documentation> documentationImpl(String code, int cursor, boolean computeJavadoc) { code = code.substring(0, cursor); if (code.trim().isEmpty()) { //TODO: comment handling code += ";"; } if (guessKind(code) == Kind.IMPORT) return Collections.emptyList(); OuterWrap codeWrap = proc.outerMap.wrapInTrialClass(Wrap.methodWrap(code)); AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap, keepParameterNames); SourcePositions sp = at.trees().getSourcePositions(); CompilationUnitTree topLevel = at.firstCuTree(); TreePath tp = pathFor(topLevel, sp, codeWrap.snippetIndexToWrapIndex(cursor)); if (tp == null) return Collections.emptyList(); TreePath prevPath = null; while (tp != null && tp.getLeaf().getKind() != Kind.METHOD_INVOCATION && tp.getLeaf().getKind() != Kind.NEW_CLASS && tp.getLeaf().getKind() != Kind.IDENTIFIER && tp.getLeaf().getKind() != Kind.MEMBER_SELECT) { prevPath = tp; tp = tp.getParentPath(); } if (tp == null) return Collections.emptyList(); Stream<Element> elements; Iterable<Pair<ExecutableElement, ExecutableType>> candidates; List<? extends ExpressionTree> arguments; if (tp.getLeaf().getKind() == Kind.METHOD_INVOCATION || tp.getLeaf().getKind() == Kind.NEW_CLASS) { if (tp.getLeaf().getKind() == Kind.METHOD_INVOCATION) { MethodInvocationTree mit = (MethodInvocationTree) tp.getLeaf(); candidates = methodCandidates(at, tp); arguments = mit.getArguments(); } else { NewClassTree nct = (NewClassTree) tp.getLeaf(); candidates = newClassCandidates(at, tp); arguments = nct.getArguments(); } if (!isEmptyArgumentsContext(arguments)) { List<TypeMirror> actuals = computeActualInvocationTypes(at, arguments, prevPath); List<TypeMirror> fullActuals = actuals != null ? actuals : Collections.emptyList(); candidates = this.filterExecutableTypesByArguments(at, candidates, fullActuals) .stream() .filter(method -> parameterType(method.fst, method.snd, fullActuals.size(), true).findAny().isPresent()) .collect(Collectors.toList()); } elements = Util.stream(candidates).map(method -> method.fst); } else if (tp.getLeaf().getKind() == Kind.IDENTIFIER || tp.getLeaf().getKind() == Kind.MEMBER_SELECT) { Element el = at.trees().getElement(tp); if (el == null || el.asType().getKind() == TypeKind.ERROR || (el.getKind() == ElementKind.PACKAGE && el.getEnclosedElements().isEmpty())) { //erroneous element: return Collections.emptyList(); } elements = Stream.of(el); } else { return Collections.emptyList(); } List<Documentation> result = Collections.emptyList(); try (JavadocHelper helper = JavadocHelper.create(at.task, findSources())) { result = elements.map(el -> constructDocumentation(at, helper, el, computeJavadoc)) .filter(Objects::nonNull) .collect(Collectors.toList()); } catch (IOException ex) { proc.debug(ex, "JavadocHelper.close()"); } return result; }
Example 17
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 4 votes |
private List<? extends TypeMirror> visitMethodOrNew(Tree node, Object p, List<? extends ExpressionTree> args, ExecutableType execType) { List<TypeMirror> proposed = new ArrayList<TypeMirror>(); int[] index = new int[1]; if (theExpression == null) { List<ExecutableElement> methods = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(info, getCurrentPath(), proposed, index); if (methods.isEmpty()) { return null; } else { initExpression(args.get(index[0])); return proposed; } } else { Element el = info.getTrees().getElement(getCurrentPath()); if (el == null) { return null; } if (theExpression.getLeaf() != node && (el.getKind() == ElementKind.METHOD || el.getKind() == ElementKind.CONSTRUCTOR)) { int argIndex = args.indexOf(theExpression.getLeaf()); this.parentExecutable = getCurrentPath(); TypeMirror argm; ExecutableElement ee = (ExecutableElement)el; boolean allowEntireVararg = false; boolean varargPosition = false; if (ee.isVarArgs() && (varargPosition = argIndex >= ee.getParameters().size() -1)) { // all parameters after the vararg will be reported at the varargs position. allowEntireVararg = argIndex == ee.getParameters().size() -1; argIndex = ee.getParameters().size() - 1; if (allowEntireVararg) { this.argIndex = ee.getParameters().size() - 1; } else { this.argIndex = ee.getParameters().size(); } } else { this.argIndex = argIndex; } if (execType != null) { // handle varargs arguments; if the argtype is a vararg, then either array of the type (reported in argm), // or the component can be passed. argm = execType.getParameterTypes().get(argIndex); // XXX hack argm = decapture(argm); } else { argm = ((ExecutableElement)el).getParameters().get(argIndex).asType(); } if (argm == null || argm.getKind() == TypeKind.ERROR) { targetArgType = null; return null; } if (varargPosition && argm.getKind() == TypeKind.ARRAY) { TypeMirror ctype = ((ArrayType)argm).getComponentType(); if (allowEntireVararg) { targetArgType = argm; return Arrays.asList(new TypeMirror[] { argm, ctype }); } argm = ctype; } targetArgType = argm; return Collections.singletonList(argm); } } return null; }
Example 18
Source File: Type.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
public TypeKind getKind() { return TypeKind.ERROR; }
Example 19
Source File: GoToSupport.java From netbeans with Apache License 2.0 | 4 votes |
private static boolean isError(Element el) { return el == null || el.asType() == null || el.asType().getKind() == TypeKind.ERROR; }
Example 20
Source File: CheckBase.java From revapi with Apache License 2.0 | 2 votes |
/** * The element is deemed missing if its type kind ({@link javax.lang.model.type.TypeMirror#getKind()}) is * {@link TypeKind#ERROR}. * * @param e the element * * @return true if the element is missing, false otherwise */ public boolean isMissing(@Nonnull Element e) { return e.asType().getKind() == TypeKind.ERROR; }