@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; }
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; }
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; }
@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; }
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) { } } }
/** * 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; }
public Value<TypeMirror> getTypeMirror(final String key) { final AnnotationValue annotationValue = values.get(key); if (annotationValue == null) { throw new IllegalArgumentException(key); } final TypeMirror typeMirror = toTypeMirror(annotationValue); if (typeMirror == null) { throw brokenValue("Could not resolve type", element, annotation, annotationValue); } if (typeMirror instanceof ErrorType) { throw brokenValue("Could not resolve type", element, annotation, annotationValue); } return new Value<>(annotationValue, typeMirror); }
@Override public TypeMirror getOriginalType(ErrorType et) { return delegate.getOriginalType(et); }
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); }
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); }
/** * 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"); }
@Test public void getErrorType() { ErrorType errorType = new DeclaredTypeAsErrorType(getTypes().getDeclaredType(getElement(Set.class))); assertThat(TypeName.get(errorType)).isEqualTo(ClassName.get(Set.class)); }
@Override public Element visitError(ErrorType t, Void p) { return t.asElement(); }
@Override public String visitError(ErrorType t, Void p) { return "/* FIXME MetaGen could not process this type: " + t.toString() + ". Substituting with Object */ " + Object.class.getName(); }
static public TypeMirror resolveType(TypeMirror tm, Map<TypeMirror, TypeMirror> rawTypeMappings) { TypeMirror resolvedType = tm; TypeMirror typeMirror = rawTypeMappings.get(resolvedType); if (typeMirror != null) { resolvedType = typeMirror; } else { Types types = UtilsProvider.getTypes(); if (resolvedType instanceof TypeVariable || resolvedType instanceof ErrorType) { resolvedType = types.getDeclaredType(UtilsProvider.getElements().getTypeElement(Object.class.getCanonicalName())); } else if (resolvedType instanceof ArrayType) { TypeMirror componentType = ((ArrayType)resolvedType).getComponentType(); resolvedType = types.getArrayType(resolveType(componentType, rawTypeMappings)); } else if (resolvedType instanceof DeclaredType) { DeclaredType dt = (DeclaredType) resolvedType; List<? extends TypeMirror> typeArguments = dt.getTypeArguments(); if ( typeArguments != null && !typeArguments.isEmpty() ){ int size = typeArguments.size(); TypeMirror[] bakArguments = new TypeMirror[size]; for(int i=0; i < size; i++){ bakArguments[i] = resolveType(typeArguments.get(i), rawTypeMappings); } resolvedType = types.getDeclaredType((TypeElement)dt.asElement(), bakArguments); } } } return resolvedType; }
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); }
@Override public Type getOperatorType(String operatorSymbol, Type optionalArgument, LocatedElement node) { Type t = super.getOperatorType(operatorSymbol, optionalArgument, node); if ( t == null ) { // This may generate more than one error, but it is the easiest way by now List<Type> types = type.getPossibleTypes().stream().map(possibleType -> { ITypeNamespace ns = (ITypeNamespace) possibleType.getMetamodelRef(); return ns.getOperatorType(operatorSymbol, optionalArgument, node); }).filter(opType -> !(opType instanceof ErrorType)).collect(Collectors.toList()); return AnalyserContext.getTypingModel().getCommonType(types); } return t; }
@Override public TypeElement visitError(ErrorType t, Void aVoid) { return (TypeElement) t.asElement(); }
private boolean checkReturnType(TraitElement element, ExecutableElement exec) { TypeMirror returnType = exec.getReturnType(); if (returnType instanceof ErrorType) { // It may not exist yet return true; } else { return element.getGeneratedInterfaceName().equals(getTypeNameFromTypeMirror(returnType, null)); } }
@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)); } }
@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; }
@Override public Type visitError(ErrorType t, Type.Parameters p) { throw new UnsupportedOperationException("ErrorType type not supported"); }