io.norberg.automatter.AutoMatter Java Examples
The following examples show how to use
io.norberg.automatter.AutoMatter.
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: Descriptor.java From auto-matter with Apache License 2.0 | 6 votes |
private ExecutableElement findToStringMethod(final TypeElement element) { final List<ExecutableElement> matches = new ArrayList<>(); for (final Element member : element.getEnclosedElements()) { if (member.getKind() == ElementKind.METHOD && member.getAnnotation(AutoMatter.ToString.class) != null) { if (!member.getModifiers().contains(STATIC) && !member.getModifiers().contains(DEFAULT)) { throw new AutoMatterProcessorException( "Method annotated with @AutoMatter.ToString must be static or default", valueTypeElement); } matches.add((ExecutableElement) member); } } if (matches.size() == 1) { return matches.get(0); } else if (matches.size() > 1) { throw new AutoMatterProcessorException( "There must only be one @AutoMatter.ToString annotated method on a type", valueTypeElement); } for (final TypeMirror interfaceType : element.getInterfaces()) { final TypeElement interfaceElement = (TypeElement) ((DeclaredType) interfaceType).asElement(); final ExecutableElement method = findToStringMethod(interfaceElement); if (method != null) { return method; } } return null; }
Example #2
Source File: GenericNestedBuilder.java From auto-matter with Apache License 2.0 | 6 votes |
private Value(@AutoMatter.Field("baz2") GenericNested.Baz<GenericNested.Baz<Q>> baz2, @AutoMatter.Field("baz3") GenericNested.Baz<GenericNested.Baz<GenericNested.Baz<Q>>> baz3, @AutoMatter.Field("mapBaz") Map<Q, GenericNested.Baz<W>> mapBaz, @AutoMatter.Field("quuxBaz") GenericNested.Quux<Q, GenericNested.Baz<W>> quuxBaz, @AutoMatter.Field("quuxQuuxBaz") GenericNested.Quux<GenericNested.Quux<String, Integer>, GenericNested.Quux<W, GenericNested.Baz<Q>>> quuxQuuxBaz, @AutoMatter.Field("bazBaz") GenericNested.Baz<GenericNested.Baz<Q>> bazBaz) { if (baz2 == null) { throw new NullPointerException("baz2"); } if (baz3 == null) { throw new NullPointerException("baz3"); } if (quuxBaz == null) { throw new NullPointerException("quuxBaz"); } if (quuxQuuxBaz == null) { throw new NullPointerException("quuxQuuxBaz"); } if (bazBaz == null) { throw new NullPointerException("bazBaz"); } this.baz2 = baz2; this.baz3 = baz3; this.mapBaz = (mapBaz != null) ? mapBaz : Collections.<Q, GenericNested.Baz<W>>emptyMap(); this.quuxBaz = quuxBaz; this.quuxQuuxBaz = quuxQuuxBaz; this.bazBaz = bazBaz; }
Example #3
Source File: GenericMultipleBuilder.java From auto-matter with Apache License 2.0 | 6 votes |
private Value(@AutoMatter.Field("field1") T1 field1, @AutoMatter.Field("field2") T2 field2, @AutoMatter.Field("field3") T3 field3, @AutoMatter.Field("field4") T4 field4, @AutoMatter.Field("plain") String plain) { if (field1 == null) { throw new NullPointerException("field1"); } if (field2 == null) { throw new NullPointerException("field2"); } if (field3 == null) { throw new NullPointerException("field3"); } if (field4 == null) { throw new NullPointerException("field4"); } if (plain == null) { throw new NullPointerException("plain"); } this.field1 = field1; this.field2 = field2; this.field3 = field3; this.field4 = field4; this.plain = plain; }
Example #4
Source File: NullableCollectionFieldsBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value(@AutoMatter.Field("strings") List<String> strings, @AutoMatter.Field("integers") Map<String,Integer> integers, @AutoMatter.Field("numbers") Set<Long> numbers) { this.strings = strings; this.integers = integers; this.numbers = numbers; }
Example #5
Source File: GenericFoobarBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value(@AutoMatter.Field("foo") String foo, @AutoMatter.Field("bar") T bar, @AutoMatter.Field("baz") int baz) { if (foo == null) { throw new NullPointerException("foo"); } if (bar == null) { throw new NullPointerException("bar"); } this.foo = foo; this.bar = bar; this.baz = baz; }
Example #6
Source File: CollectionFieldsBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value(@AutoMatter.Field("strings") List<String> strings, @AutoMatter.Field("integers") Map<String, Integer> integers, @AutoMatter.Field("sortedIntegers") SortedMap<String, Integer> sortedIntegers, @AutoMatter.Field("navigableIntegers") NavigableMap<String, Integer> navigableIntegers, @AutoMatter.Field("numbers") Set<Long> numbers, @AutoMatter.Field("sortedNumbers") SortedSet<Long> sortedNumbers, @AutoMatter.Field("navigableNumbers") NavigableSet<Long> navigableNumbers) { this.strings = (strings != null) ? strings : Collections.<String>emptyList(); this.integers = (integers != null) ? integers : Collections.<String, Integer>emptyMap(); this.sortedIntegers = (sortedIntegers != null) ? sortedIntegers : Collections.<String, Integer>emptySortedMap(); this.navigableIntegers = (navigableIntegers != null) ? navigableIntegers : Collections.<String, Integer>emptyNavigableMap(); this.numbers = (numbers != null) ? numbers : Collections.<Long>emptySet(); this.sortedNumbers = (sortedNumbers != null) ? sortedNumbers : Collections.<Long>emptySortedSet(); this.navigableNumbers = (navigableNumbers != null) ? navigableNumbers : Collections.<Long>emptyNavigableSet(); }
Example #7
Source File: FoobarBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value(@AutoMatter.Field("foo") String foo, @AutoMatter.Field("bar") Integer bar, @AutoMatter.Field("baz") int baz) { if (foo == null) { throw new NullPointerException("foo"); } if (bar == null) { throw new NullPointerException("bar"); } this.foo = foo; this.bar = bar; this.baz = baz; }
Example #8
Source File: FooBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value( @AutoMatter.Field("aBoolean") boolean aBoolean, @AutoMatter.Field("aByte") byte aByte, @AutoMatter.Field("aShort") short aShort, @AutoMatter.Field("aInt") int aInt, @AutoMatter.Field("aLong") long aLong, @AutoMatter.Field("aChar") char aChar, @AutoMatter.Field("aFloat") float aFloat, @AutoMatter.Field("aDouble") double aDouble, @AutoMatter.Field("object") Object object, @AutoMatter.Field("array") Object[] array ) { if (object == null) { throw new NullPointerException("object"); } if (array == null) { throw new NullPointerException("array"); } this.aBoolean = aBoolean; this.aByte = aByte; this.aShort = aShort; this.aInt = aInt; this.aLong = aLong; this.aChar = aChar; this.aFloat = aFloat; this.aDouble = aDouble; this.object = object; this.array = array; }
Example #9
Source File: GenericGuavaOptionalFieldsBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value(@AutoMatter.Field("foo") Optional<T> foo, @AutoMatter.Field("bar") Optional<T> bar) { if (foo == null) { throw new NullPointerException("foo"); } this.foo = foo; this.bar = bar; }
Example #10
Source File: GenericJUTOptionalFieldsBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value(@AutoMatter.Field("foo") Optional<T> foo, @AutoMatter.Field("bar") Optional<T> bar) { if (foo == null) { throw new NullPointerException("foo"); } this.foo = foo; this.bar = bar; }
Example #11
Source File: AutoMatterAnnotationIntrospector.java From auto-matter with Apache License 2.0 | 5 votes |
@Override public boolean hasCreatorAnnotation(final Annotated a) { if (!(a instanceof AnnotatedConstructor)) { return false; } final AnnotatedConstructor ctor = (AnnotatedConstructor) a; if (ctor.getParameterCount() == 0) { return true; } final AutoMatter.Field field = ctor.getParameter(0).getAnnotation(AutoMatter.Field.class); return field != null; }
Example #12
Source File: AutoMatterResolver.java From auto-matter with Apache License 2.0 | 5 votes |
private JavaType resolveAbstractType0(final DeserializationConfig config, final Class<?> rawClass) { final AutoMatter annotation = rawClass.getAnnotation(AutoMatter.class); if (annotation == null) { // This was not an @AutoMatter type. return null; } // Return the cached type, if present. final JavaType cached = types.get(rawClass); if (cached != null) { return cached; } // Look up and instantiate the value class final String packageName = rawClass.getPackage().getName(); final String name = rawClass.getSimpleName(); final String valueName = packageName + '.' + name + VALUE_SUFFIX; final Class<?> cls; try { cls = Class.forName(valueName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("No builder found for @AutoMatter type: " + name, e); } final JavaType materialized = config.getTypeFactory().constructType(cls); // Cache the materialized type before returning final JavaType existing = types.putIfAbsent(rawClass, materialized); return (existing != null) ? existing : materialized; }
Example #13
Source File: AutoMatterAnnotationIntrospector.java From auto-matter with Apache License 2.0 | 5 votes |
@Override public String findImplicitPropertyName(final AnnotatedMember member) { final AutoMatter.Field field = member.getAnnotation(AutoMatter.Field.class); if (field == null) { return null; } if (member instanceof AnnotatedParameter) { return field.value(); } if (member instanceof AnnotatedMethod) { return member.getName(); } return null; }
Example #14
Source File: JUTOptionalFieldsBuilder.java From auto-matter with Apache License 2.0 | 5 votes |
private Value(@AutoMatter.Field("foo") Optional<String> foo, @AutoMatter.Field("bar") Optional<String> bar) { if (foo == null) { throw new NullPointerException("foo"); } this.foo = foo; this.bar = bar; }
Example #15
Source File: AutoMatterProcessor.java From auto-matter with Apache License 2.0 | 5 votes |
private MethodSpec valueGetter(final Descriptor d, final ExecutableElement field) { String fieldName = fieldName(field); return MethodSpec.methodBuilder(fieldName) .addAnnotation(AutoMatter.Field.class) .addAnnotation(Override.class) .addModifiers(PUBLIC) .returns(fieldType(d, field)) .addStatement("return $N", fieldName) .build(); }
Example #16
Source File: NullableFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public int nonNullPrimitive() { return nonNullPrimitive; }
Example #17
Source File: CollectionFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public Set<Long> numbers() { return numbers; }
Example #18
Source File: GenericGuavaOptionalFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public Optional<T> foo() { return foo; }
Example #19
Source File: NullableFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public String nonNullQuux() { return nonNullQuux; }
Example #20
Source File: CollectionFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public SortedMap<String, Integer> sortedIntegers() { return sortedIntegers; }
Example #21
Source File: CollectionFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public Map<String, Integer> integers() { return integers; }
Example #22
Source File: OverriddenMethodsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
private Value(@AutoMatter.Field("baz") String baz) { if (baz == null) { throw new NullPointerException("baz"); } this.baz = baz; }
Example #23
Source File: CollectionFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public List<String> strings() { return strings; }
Example #24
Source File: CollectionInterfaceFieldBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public Collection<String> strings() { return strings; }
Example #25
Source File: CollectionInterfaceFieldBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
private Value(@AutoMatter.Field("strings") Collection<String> strings) { this.strings = (strings != null) ? strings : Collections.<String>emptyList(); }
Example #26
Source File: GenericNestedBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public Map<Q, GenericNested.Baz<W>> mapBaz() { return mapBaz; }
Example #27
Source File: NullableFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public String customNullableBar() { return customNullableBar; }
Example #28
Source File: GenericCollectionBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
private Value(@AutoMatter.Field("foos") List<T> foos, @AutoMatter.Field("bars") Map<K, V> bars) { this.foos = (foos != null) ? foos : Collections.<T>emptyList(); this.bars = (bars != null) ? bars : Collections.<K, V>emptyMap(); }
Example #29
Source File: JUTOptionalFieldsBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public Optional<String> foo() { return foo; }
Example #30
Source File: GenericJUTOptionalNestedBuilder.java From auto-matter with Apache License 2.0 | 4 votes |
@AutoMatter.Field @Override public Optional<List<T>> foo() { return foo; }