javax.lang.model.type.ErrorType Java Examples
The following examples show how to use
javax.lang.model.type.ErrorType.
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: TypeSimplifierTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testErrorTypes() { TypeElement extendsUndefinedType = processingEnv.getElementUtils().getTypeElement("ExtendsUndefinedType"); ErrorType errorType = (ErrorType) extendsUndefinedType.getSuperclass(); TypeMirror javaLangObject = typeMirrorOf("java.lang.Object"); TypeElement list = typeElementOf("java.util.List"); TypeMirror listOfError = typeUtil.getDeclaredType(list, errorType); TypeMirror queryExtendsError = typeUtil.getWildcardType(errorType, null); TypeMirror listOfQueryExtendsError = typeUtil.getDeclaredType(list, queryExtendsError); TypeMirror querySuperError = typeUtil.getWildcardType(null, errorType); TypeMirror listOfQuerySuperError = typeUtil.getDeclaredType(list, querySuperError); TypeMirror arrayOfError = typeUtil.getArrayType(errorType); TypeMirror[] typesWithErrors = { errorType, listOfError, listOfQueryExtendsError, listOfQuerySuperError, arrayOfError }; for (TypeMirror typeWithError : typesWithErrors) { try { new TypeSimplifier(typeUtil, "foo.bar", ImmutableSet.of(typeWithError), javaLangObject); fail("Expected exception for type: " + typeWithError); } catch (MissingTypeException expected) { } } }
Example #2
Source File: TypeEncoderTest.java From auto with Apache License 2.0 | 6 votes |
private void test() { TypeElement extendsUndefinedType = elementUtils.getTypeElement("ExtendsUndefinedType"); ErrorType errorType = (ErrorType) extendsUndefinedType.getSuperclass(); TypeElement list = elementUtils.getTypeElement("java.util.List"); TypeMirror listOfError = typeUtils.getDeclaredType(list, errorType); TypeMirror queryExtendsError = typeUtils.getWildcardType(errorType, null); TypeMirror listOfQueryExtendsError = typeUtils.getDeclaredType(list, queryExtendsError); TypeMirror querySuperError = typeUtils.getWildcardType(null, errorType); TypeMirror listOfQuerySuperError = typeUtils.getDeclaredType(list, querySuperError); TypeMirror arrayOfError = typeUtils.getArrayType(errorType); testErrorType(errorType); testErrorType(listOfError); testErrorType(listOfQueryExtendsError); testErrorType(listOfQuerySuperError); testErrorType(arrayOfError); }
Example #3
Source File: TypeSimplifierTest.java From SimpleWeibo with Apache License 2.0 | 6 votes |
public void testErrorTypes() { TypeElement extendsUndefinedType = processingEnv.getElementUtils().getTypeElement("ExtendsUndefinedType"); ErrorType errorType = (ErrorType) extendsUndefinedType.getSuperclass(); TypeMirror javaLangObject = typeMirrorOf("java.lang.Object"); TypeElement list = typeElementOf("java.util.List"); TypeMirror listOfError = typeUtil.getDeclaredType(list, errorType); TypeMirror queryExtendsError = typeUtil.getWildcardType(errorType, null); TypeMirror listOfQueryExtendsError = typeUtil.getDeclaredType(list, queryExtendsError); TypeMirror querySuperError = typeUtil.getWildcardType(null, errorType); TypeMirror listOfQuerySuperError = typeUtil.getDeclaredType(list, querySuperError); TypeMirror arrayOfError = typeUtil.getArrayType(errorType); TypeMirror[] typesWithErrors = { errorType, listOfError, listOfQueryExtendsError, listOfQuerySuperError, arrayOfError }; for (TypeMirror typeWithError : typesWithErrors) { try { new TypeSimplifier(typeUtil, "foo.bar", ImmutableSet.of(typeWithError), javaLangObject); fail("Expected exception for type: " + typeWithError); } catch (MissingTypeException expected) { } } }
Example #4
Source File: TypeSimplifierTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testErrorTypes() { TypeElement extendsUndefinedType = processingEnv.getElementUtils().getTypeElement("ExtendsUndefinedType"); ErrorType errorType = (ErrorType) extendsUndefinedType.getSuperclass(); TypeMirror javaLangObject = typeMirrorOf("java.lang.Object"); TypeElement list = typeElementOf("java.util.List"); TypeMirror listOfError = typeUtil.getDeclaredType(list, errorType); TypeMirror queryExtendsError = typeUtil.getWildcardType(errorType, null); TypeMirror listOfQueryExtendsError = typeUtil.getDeclaredType(list, queryExtendsError); TypeMirror querySuperError = typeUtil.getWildcardType(null, errorType); TypeMirror listOfQuerySuperError = typeUtil.getDeclaredType(list, querySuperError); TypeMirror arrayOfError = typeUtil.getArrayType(errorType); TypeMirror[] typesWithErrors = { errorType, listOfError, listOfQueryExtendsError, listOfQuerySuperError, arrayOfError }; for (TypeMirror typeWithError : typesWithErrors) { try { new TypeSimplifier(typeUtil, "foo.bar", ImmutableSet.of(typeWithError), javaLangObject); fail("Expected exception for type: " + typeWithError); } catch (MissingTypeException expected) { } } }
Example #5
Source File: TypeUtilities.java From netbeans with Apache License 2.0 | 6 votes |
private static TypeMirror resolveCapturedType(CompilationInfo info, TypeMirror tm) { if (tm == null) { return tm; } if (tm.getKind() == TypeKind.ERROR) { tm = info.getTrees().getOriginalType((ErrorType) tm); } TypeMirror type = resolveCapturedTypeInt(info, tm); if (type == null) { return tm; } if (type.getKind() == TypeKind.WILDCARD) { TypeMirror tmirr = ((WildcardType) type).getExtendsBound(); if (tmirr != null) return tmirr; else { //no extends, just '?' TypeElement te = info.getElements().getTypeElement("java.lang.Object"); // NOI18N return te == null ? null : te.asType(); } } return type; }
Example #6
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
public static TypeMirror resolveCapturedType(CompilationInfo info, TypeMirror tm) { if (tm == null) { return tm; } if (tm.getKind() == TypeKind.ERROR) { tm = info.getTrees().getOriginalType((ErrorType) tm); } TypeMirror type = resolveCapturedTypeInt(info, tm); if (type == null) { return tm; } if (type.getKind() == TypeKind.WILDCARD) { TypeMirror tmirr = ((WildcardType) type).getExtendsBound(); if (tmirr != null) return tmirr; else { //no extends, just '?' TypeElement te = info.getElements().getTypeElement("java.lang.Object"); // NOI18N return te == null ? null : te.asType(); } } return type; }
Example #7
Source File: MethodFinderTest.java From FreeBuilder with Apache License 2.0 | 5 votes |
@Test public void testSkipsErrorTypes() { TypeElement testClass = model.newType( "package com.example;", "class TestClass extends MissingType implements OtherMissingType {", " public int foo(short a);", "}"); List<ErrorType> errorTypes = new ArrayList<>(); List<String> methods = toStrings(MethodFinder.methodsOn(testClass, model.elementUtils(), errorTypes::add)); assertThat(methods).containsExactly("int TestClass::foo(short)"); assertThat(errorTypes).hasSize(2); }
Example #8
Source File: ChangeMethodReturnType.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.resolveTypeForDeclaration(info, targetType); }
Example #9
Source File: SignatureFactory.java From buck with Apache License 2.0 | 5 votes |
@Override public Void visitError(ErrorType t, SignatureVisitor visitor) { // We don't really know, but if there's an error type the compilation is going to fail // anyway, so just pretend it's Object. visitor.visitClassType("java/lang/Object"); visitor.visitEnd(); return null; }
Example #10
Source File: TypeUtilities.java From netbeans with Apache License 2.0 | 5 votes |
@Override public StringBuilder visitError(ErrorType t, Boolean p) { Element e = t.asElement(); if (e instanceof TypeElement) { TypeElement te = (TypeElement)e; return DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString()); } return DEFAULT_VALUE; }
Example #11
Source File: JavaSymbolProvider.java From netbeans with Apache License 2.0 | 5 votes |
@Override public StringBuilder visitError(ErrorType t, Boolean p) { Element e = t.asElement(); if (e instanceof TypeElement) { TypeElement te = (TypeElement)e; return DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString()); } return DEFAULT_VALUE; }
Example #12
Source File: AbstractTypesTest.java From javapoet with Apache License 2.0 | 5 votes |
@Test public void errorTypes() { JavaFileObject hasErrorTypes = JavaFileObjects.forSourceLines( "com.squareup.tacos.ErrorTypes", "package com.squareup.tacos;", "", "@SuppressWarnings(\"hook-into-compiler\")", "class ErrorTypes {", " Tacos tacos;", " Ingredients.Guacamole guacamole;", "}"); Compilation compilation = javac().withProcessors(new AbstractProcessor() { @Override public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) { TypeElement classFile = processingEnv.getElementUtils().getTypeElement("com.squareup.tacos.ErrorTypes"); List<VariableElement> fields = fieldsIn(classFile.getEnclosedElements()); ErrorType topLevel = (ErrorType) fields.get(0).asType(); ErrorType member = (ErrorType) fields.get(1).asType(); assertThat(TypeName.get(topLevel)).isEqualTo(ClassName.get("", "Tacos")); assertThat(TypeName.get(member)).isEqualTo(ClassName.get("Ingredients", "Guacamole")); return false; } @Override public Set<String> getSupportedAnnotationTypes() { return Collections.singleton("*"); } }).compile(hasErrorTypes); assertThat(compilation).failed(); }
Example #13
Source File: SpringXMLConfigCompletionItem.java From netbeans with Apache License 2.0 | 5 votes |
@Override public StringBuilder visitError(ErrorType t, Boolean p) { Element e = t.asElement(); if (e instanceof TypeElement) { TypeElement te = (TypeElement)e; return DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString()); } return DEFAULT_VALUE; }
Example #14
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 #15
Source File: AutoImport.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitError(ErrorType type, Void p) { Element e = type.asElement(); if (e instanceof TypeElement) { TypeElement te = (TypeElement)e; builder.append(te.getSimpleName()); } return null; }
Example #16
Source File: MethodModelSupport.java From netbeans with Apache License 2.0 | 5 votes |
@Override public StringBuilder visitError(ErrorType t, Boolean p) { Element e = t.asElement(); if (e instanceof TypeElement) { TypeElement te = (TypeElement)e; return DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString()); } return DEFAULT_VALUE; }
Example #17
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
@Override public StringBuilder visitError(ErrorType t, Boolean p) { Element e = t.asElement(); if (e instanceof TypeElement) { TypeElement te = (TypeElement)e; return DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString()); } return DEFAULT_VALUE; }
Example #18
Source File: StandaloneTypeMirror.java From buck with Apache License 2.0 | 5 votes |
@Override public <R, P> R accept(TypeVisitor<R, P> v, P p) { switch (kind) { case BOOLEAN: case BYTE: case SHORT: case INT: case LONG: case CHAR: case FLOAT: case DOUBLE: return v.visitPrimitive((PrimitiveType) this, p); case PACKAGE: case VOID: case NONE: return v.visitNoType((NoType) this, p); case NULL: return v.visitNull((NullType) this, p); case ARRAY: return v.visitArray((ArrayType) this, p); case DECLARED: return v.visitDeclared((DeclaredType) this, p); case ERROR: return v.visitError((ErrorType) this, p); case TYPEVAR: return v.visitTypeVariable((TypeVariable) this, p); case WILDCARD: return v.visitWildcard((WildcardType) this, p); case EXECUTABLE: return v.visitExecutable((ExecutableType) this, p); case OTHER: return v.visit(this, p); case UNION: return v.visitUnion((UnionType) this, p); case INTERSECTION: return v.visitIntersection((IntersectionType) this, p); default: throw new AssertionError(String.format("Unknown TypeKind: %s", kind)); } }
Example #19
Source File: MoreTypes.java From auto-parcel with Apache License 2.0 | 5 votes |
/** * Returns a {@link ExecutableType} if the {@link TypeMirror} represents an executable type such * as may result from missing code, or bad compiles or throws an {@link IllegalArgumentException}. */ public static ErrorType asError(TypeMirror maybeErrorType) { return maybeErrorType.accept(new CastingTypeVisitor<ErrorType>() { @Override public ErrorType visitError(ErrorType type, String p) { return type; } }, "error type"); }
Example #20
Source File: Util.java From revapi with Apache License 2.0 | 5 votes |
@Override public final T visitError(ErrorType t, StringBuilderAndState<S> st) { try { st.depth++; return doVisitError(t, st); } finally { st.depth--; } }
Example #21
Source File: ModelMethodPlugin.java From squidb with Apache License 2.0 | 5 votes |
private boolean checkFirstArgType(TypeMirror type, DeclaredTypeName generatedClassName) { if (type instanceof ErrorType) { return true; } if (!(type instanceof DeclaredType)) { return false; } DeclaredTypeName typeName = (DeclaredTypeName) utils.getTypeNameFromTypeMirror(type); return typeName.equals(generatedClassName) || typeName.equals(TypeConstants.ABSTRACT_MODEL); }
Example #22
Source File: MethodFinder.java From FreeBuilder with Apache License 2.0 | 5 votes |
private static <E extends Exception> Optional<TypeElement> maybeTypeElement( TypeMirror mirror, ErrorTypeHandling<E> errorTypeHandling) throws E { if (mirror.getKind() == TypeKind.ERROR) { errorTypeHandling.handleErrorType((ErrorType) mirror); } return maybeAsTypeElement(mirror); }
Example #23
Source File: Analyser.java From FreeBuilder with Apache License 2.0 | 5 votes |
/** * Any reference to the as-yet-ungenerated builder should be an unresolved ERROR. * Similarly for many copy-and-paste errors */ @Override public Boolean visitError(ErrorType t, Void p) { if (typeParameters.isEmpty()) { // For non-generic types, the ErrorType will have the correct name. String simpleName = t.toString(); return equal(simpleName, superclass.getSimpleName()); } // For generic types, we'll just have to hope for the best. // TODO: Revalidate in a subsequent round? return true; }
Example #24
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
@Override public StringBuilder visitError(ErrorType t, Void p) { Element e = t.asElement(); if (e instanceof TypeElement) { TypeElement te = (TypeElement) e; return DEFAULT_VALUE.append(te.getQualifiedName().toString()); } return DEFAULT_VALUE; }
Example #25
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public ErrorType getErrorType(ReferenceBinding binding) { return new ErrorTypeImpl(this._env, binding); }
Example #26
Source File: BuilderSpec.java From SimpleWeibo with Apache License 2.0 | 4 votes |
@Override public Element visitError(ErrorType t, Void p) { return t.asElement(); }
Example #27
Source File: SuperficialValidation.java From auto with Apache License 2.0 | 4 votes |
@Override public Boolean visitError(ErrorType t, Void p) { return false; }
Example #28
Source File: TypeSimplifier.java From SimpleWeibo with Apache License 2.0 | 4 votes |
@Override public Void visitError(ErrorType t, Void p) { throw new MissingTypeException(); }
Example #29
Source File: TypeEncoder.java From auto with Apache License 2.0 | 4 votes |
@Override public StringBuilder visitError(ErrorType t, StringBuilder p) { throw new MissingTypeException(t); }
Example #30
Source File: InheritanceChainChanged.java From revapi with Apache License 2.0 | 4 votes |
@Override public Boolean visitError(ErrorType t, Void __) { return true; }