Search in sources :

Example 31 with TypeMirror

use of javax.lang.model.type.TypeMirror in project neo4j by neo4j.

the class AllowedTypesValidator method isValidErasedType.

private boolean isValidErasedType(TypeMirror actualType) {
    return whitelistedTypes.stream().anyMatch(type -> {
        TypeMirror erasedAllowedType = typeUtils.erasure(type);
        TypeMirror map = typeUtils.erasure(typeMirrors.typeMirror(Map.class));
        TypeMirror list = typeUtils.erasure(typeMirrors.typeMirror(List.class));
        if (typeUtils.isSameType(erasedAllowedType, map) || typeUtils.isSameType(erasedAllowedType, list)) {
            return typeUtils.isSubtype(actualType, erasedAllowedType);
        }
        return typeUtils.isSameType(actualType, erasedAllowedType);
    });
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) List(java.util.List) Map(java.util.Map)

Example 32 with TypeMirror

use of javax.lang.model.type.TypeMirror in project neo4j by neo4j.

the class RecordTypeVisitorTest method validates_supported_record.

@Test
public void validates_supported_record() throws Exception {
    TypeMirror recordStreamType = typeMirrorTestUtils.typeOf(Stream.class, ValidRecord.class);
    assertThat(visitor.visit(recordStreamType)).isEmpty();
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Example 33 with TypeMirror

use of javax.lang.model.type.TypeMirror in project neo4j by neo4j.

the class RecordTypeVisitorTest method does_not_validate_record_with_nonpublic_fields.

@Test
public void does_not_validate_record_with_nonpublic_fields() throws Exception {
    TypeMirror recordStreamType = typeMirrorTestUtils.typeOf(Stream.class, InvalidRecord.class);
    assertThat(visitor.visit(recordStreamType)).hasSize(1).extracting(CompilationMessage::getCategory, CompilationMessage::getContents).containsExactly(tuple(Diagnostic.Kind.ERROR, "Record definition error: field InvalidRecord#foo must" + " be public"));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Example 34 with TypeMirror

use of javax.lang.model.type.TypeMirror in project storio by pushtorefresh.

the class JavaTypeTest method fromBoolean.

@Test
public void fromBoolean() {
    final TypeMirror typeMirror = mockTypeMirror(TypeKind.BOOLEAN, null);
    assertThat(JavaType.from(typeMirror)).isEqualTo(BOOLEAN);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Example 35 with TypeMirror

use of javax.lang.model.type.TypeMirror in project storio by pushtorefresh.

the class JavaTypeTest method fromLong.

@Test
public void fromLong() {
    final TypeMirror typeMirror = mockTypeMirror(TypeKind.LONG, null);
    assertThat(JavaType.from(typeMirror)).isEqualTo(LONG);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)475 TypeElement (javax.lang.model.element.TypeElement)197 ExecutableElement (javax.lang.model.element.ExecutableElement)105 Test (org.junit.Test)90 VariableElement (javax.lang.model.element.VariableElement)88 DeclaredType (javax.lang.model.type.DeclaredType)76 Element (javax.lang.model.element.Element)61 ArrayList (java.util.ArrayList)36 Expression (com.google.devtools.j2objc.ast.Expression)32 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)28 Elements (javax.lang.model.util.Elements)28 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)24 AbstractJClass (com.helger.jcodemodel.AbstractJClass)24 List (java.util.List)23 Types (javax.lang.model.util.Types)22 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)21 TypeParameterElement (javax.lang.model.element.TypeParameterElement)21 ArrayType (javax.lang.model.type.ArrayType)21 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)20 IJExpression (com.helger.jcodemodel.IJExpression)20