Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Apr 26, 2021
1 parent 4c1552a commit 8ad00fb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 46 deletions.
60 changes: 30 additions & 30 deletions codegen/src/main/java/io/sundr/codegen/functions/ClassTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

package io.sundr.codegen.functions;

import io.sundr.FunctionFactory;
import io.sundr.codegen.DefinitionRepository;
import io.sundr.codegen.model.Method;
import io.sundr.codegen.model.*;

import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.util.*;
Expand All @@ -29,6 +24,11 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.sundr.FunctionFactory;
import io.sundr.codegen.DefinitionRepository;
import io.sundr.codegen.model.*;
import io.sundr.codegen.model.Method;

public class ClassTo {

private static final String ARGUMENT_PREFIX = "arg";
Expand Down Expand Up @@ -121,11 +121,11 @@ public TypeRef apply(Type item) {
});

public static final Function<Class<? extends Annotation>, AnnotationRef> ANNOTATIONTYPEREF = FunctionFactory
.cache(item -> {
//An annotation can't be a primitive or a void type, so its safe to cast.
ClassRef classRef = (ClassRef) TYPEREF.apply(item);
return new AnnotationRefBuilder().withClassRef(classRef).build();
});
.cache(item -> {
//An annotation can't be a primitive or a void type, so its safe to cast.
ClassRef classRef = (ClassRef) TYPEREF.apply(item);
return new AnnotationRefBuilder().withClassRef(classRef).build();
});

private static final Function<Class, TypeDef> INTERNAL_TYPEDEF = new Function<Class, TypeDef>() {
public TypeDef apply(Class item) {
Expand Down Expand Up @@ -246,11 +246,11 @@ private static Set<Property> getProperties(Class item, Set<Class> references) {
.collect(Collectors.toList()));
}
properties.add(new PropertyBuilder()
.withName(field.getName())
.withModifiers(field.getModifiers())
.withAnnotations(annotationRefs)
.withTypeRef(TYPEREF.apply(field.getGenericType()))
.build());
.withName(field.getName())
.withModifiers(field.getModifiers())
.withAnnotations(annotationRefs)
.withTypeRef(TYPEREF.apply(field.getGenericType()))
.build());
}
return properties;
}
Expand Down Expand Up @@ -311,23 +311,23 @@ private static Set<Method> getMethods(Class item, Set<Class> references) {
}

methods.add(new MethodBuilder()
.withName(method.getName())
.withDefaultMethod(method.isDefault())
.withModifiers(method.getModifiers())
.withReturnType(TYPEREF.apply(method.getReturnType()))
.withArguments(arguments)
.withParameters(parameters)
.withExceptions(exceptionRefs)
.withAnnotations(annotationRefs)
.withAttributes(attributes)
.build());
.withName(method.getName())
.withDefaultMethod(method.isDefault())
.withModifiers(method.getModifiers())
.withReturnType(TYPEREF.apply(method.getReturnType()))
.withArguments(arguments)
.withParameters(parameters)
.withExceptions(exceptionRefs)
.withAnnotations(annotationRefs)
.withAttributes(attributes)
.build());
}
return methods;
}

private static void processMethod(Set<Class> references, java.lang.reflect.Executable method,
List<AnnotationRef> annotationRefs, List<ClassRef> exceptionRefs, List<Property> arguments,
List<TypeParamDef> parameters) {
List<AnnotationRef> annotationRefs, List<ClassRef> exceptionRefs, List<Property> arguments,
List<TypeParamDef> parameters) {
processAnnotatedElement(method, annotationRefs);

for (Class exceptionType : method.getExceptionTypes()) {
Expand All @@ -337,9 +337,9 @@ private static void processMethod(Set<Class> references, java.lang.reflect.Execu
for (int i = 1; i <= method.getGenericParameterTypes().length; i++) {
Type argumentType = method.getGenericParameterTypes()[i - 1];
arguments.add(new PropertyBuilder()
.withName(ARGUMENT_PREFIX + i)
.withTypeRef(TYPEREF.apply(argumentType))
.build());
.withName(ARGUMENT_PREFIX + i)
.withTypeRef(TYPEREF.apply(argumentType))
.build());

if (argumentType instanceof Class) {
references.add((Class) argumentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

package io.sundr.codegen.functions;

import io.sundr.codegen.model.*;
import io.sundr.example.*;
import org.junit.Test;
import static org.junit.Assert.*;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.Assert.*;
import org.junit.Test;

import io.sundr.codegen.model.*;
import io.sundr.example.*;

public class ClassToTypeDefTest {

Expand Down Expand Up @@ -84,26 +85,26 @@ public void annotationsShouldHaveParameters() {
final TypeDef typeDef = ClassTo.TYPEDEF.apply(Other.class);
final List<Property> properties = typeDef.getProperties();
final Property foo = properties.stream().filter(p -> p.getName().equals("foo")).findFirst()
.orElseThrow(RuntimeException::new);
.orElseThrow(RuntimeException::new);
List<AnnotationRef> annotations = foo.getAnnotations();
assertEquals(1, annotations.size());
AnnotationRef annotationRef = annotations.get(0);
assertTrue(annotationRef.toString().contains("TestAnnotation"));
assertEquals(Other.FOO_NAME, annotationRef.getParameters().get("name"));
final Method something = typeDef.getMethods().stream().filter(p -> p.getName().equals("something")).findFirst()
.orElseThrow(RuntimeException::new);
.orElseThrow(RuntimeException::new);
annotations = something.getAnnotations();
assertEquals(1, annotations.size());
annotationRef = annotations.get(0);
assertEquals(Other.SOMETHING_NAME, annotationRef.getParameters().get("name"));
assertArrayEquals(new int[]{1, 2, 3, 5, 7}, (int[]) annotationRef.getParameters().get("values"));
assertArrayEquals(new int[] { 1, 2, 3, 5, 7 }, (int[]) annotationRef.getParameters().get("values"));
}

public static Optional<ClassRef> findClassRef(TypeDef def, String propertyName) {
return def.getProperties().stream()
.filter(p -> propertyName.equals(p.getName()))
.filter(p -> p.getTypeRef() instanceof ClassRef)
.map(p -> (ClassRef) p.getTypeRef())
.findFirst();
.filter(p -> propertyName.equals(p.getName()))
.filter(p -> p.getTypeRef() instanceof ClassRef)
.map(p -> (ClassRef) p.getTypeRef())
.findFirst();
}
}
2 changes: 1 addition & 1 deletion codegen/src/test/java/io/sundr/example/Other.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Other {
@TestAnnotation(name = FOO_NAME)
private String foo;

@TestAnnotation(name = SOMETHING_NAME, values = {1, 2, 3, 5, 7})
@TestAnnotation(name = SOMETHING_NAME, values = { 1, 2, 3, 5, 7 })
private void something() {
}
}
8 changes: 4 additions & 4 deletions codegen/src/test/java/io/sundr/example/TestAnnotation.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.sundr.example;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target({FIELD, METHOD})
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Target({ FIELD, METHOD })
@Retention(RUNTIME)
public @interface TestAnnotation {
String name();
Expand Down

0 comments on commit 8ad00fb

Please sign in to comment.