Commit 618a81f2 authored by Emmanuel Bourg's avatar Emmanuel Bourg

Merge tag 'upstream/1.3.4'

Upstream version 1.3.4
parents ce4408b4 b2619ac8
# Skip maven 'target' directory
target
# plus eclipse artifacts
.classpath
.project
.settings
# plus intellij files
*.ipr
*.iws
*.iml
.idea
# and emacs temp save files
*~
namespace=com.fasterxml
name=classmate
version=0.5.5-SNAPSHOT
packaging=jar
https://oss.sonatype.org/content/repositories/snapshots=maven
language: java
jdk:
- oraclejdk7
- oraclejdk8
# whitelist
branches:
only:
- master
This diff is collapsed.
Java ClassMate project: licensed under Apache License 2.0
(http://www.apache.org/licenses/LICENSE-2.0.txt)
Release notes:
1.3.4 (09-Sep-2017)
#38: Add `Automatic-Module-Name` for JDK9 interoperability
1.3.3 (28-Sep-2016)
#33: "ghost" type parameter in field
(reported, fix contributed by web-online@github)
1.3.2 (25-Sep-2016)
#30: ArrayIndexOutOfBoundsException when resolving Object.class
(reported by meszibalu@github)
1.3.1 (25-Oct-2015)
- Fix a problem with caching of subtype-extended types, causing problems
due to mutable `TypePlaceHolder`
1.3.0 (16-Sep-2015)
#28: Parametrised classes does not resolve method types properly
(reported by dawrut@github)
1.2.0 (22-May-2015)
#22: ResolvedTypeWithMembers should expose static fields as well
(proposed by arikkfir@github)
- Made `ResolvedMethod`, `ResolvedField` sortable to simplify tests
- More unit tests, from Jackson type resolver fails
1.1.0 (19-Aug-2014)
#16: ClassCastException in TypeResolver (ResolvedRecursiveType cannot be cast to ResolvedObjectType)
(reported by deki@github)
1.0.0 (15-Oct-2013)
The official Big One-Oh version!
(no functional changes since 0.9.0)
0.9.0:
#14: Fixed 2 unit tests that failed with JDK 1.7 (due to addition of members to 'java.lang.Object`
and `java.util.ArrayList`)
#15: ClassMate jar should include LICENSE file
0.8.0:
* Combine various ResolvedType.resolve(...) methods, using `java.lang.reflect.Type`
as common super type
* Changed order arguments for "resolve" that takes TypeBindings and Type, to prevent
problems with overloading: now TypeBindings is the first argument, not second
0.7.0:
#11: ResolvedType uses `java.lang.reflect.Type` to allow combination
of Class<?>, GenericType and ResolvedType.
#12: ResolvedType now implements `java.lang.reflect.Type`
0.6.0:
#5: Make `GenericType` Serializable
(suggested by Yuri S)
#8: Add additional pass-through methods in RawMember for all modifiers
(requested by Phillip S)
0.5.4:
* #4: problems with self-referential type variables
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fasterxml</groupId>
<artifactId>oss-parent</artifactId>
<version>24</version>
</parent>
<artifactId>classmate</artifactId>
<name>ClassMate</name>
<version>1.3.4</version>
<packaging>bundle</packaging>
<description>Library for introspecting types with full generic information
including resolving of field and method types.
</description>
<url>http://github.com/FasterXML/java-classmate</url>
<scm>
<connection>scm:git:git@github.com:FasterXML/java-classmate.git</connection>
<developerConnection>scm:git:git@github.com:FasterXML/java-classmate.git</developerConnection>
<url>http://github.com/FasterXML/java-classmate</url>
<tag>classmate-1.3.4</tag>
</scm>
<developers>
<developer>
<id>tatu</id>
<name>Tatu Saloranta</name>
<email>tatu@fasterxml.com</email>
</developer>
<developer>
<id>blangel</id>
<name>Brian Langel</name>
<email>blangel@ocheyedan.net</email>
</developer>
</developers>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jdk>1.6</version.jdk>
<osgi.export>com.fasterxml.classmate;version=${project.version},
com.fasterxml.classmate.*;version=${project.version}
</osgi.export>
<osgi.private>com.fasterxml.classmate.util.*</osgi.private>
</properties>
<!-- Licensing -->
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<organization>
<name>fasterxml.com</name>
<url>http://fasterxml.com</url>
</organization>
<dependencies>
<!-- and for testing, JUnit is needed -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- As per [#38] add `Automatic-Module-Name` -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions combine.children="merge">
<Automatic-Module-Name>com.fasterxml.classmate</Automatic-Module-Name>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${version.jdk}</source>
<target>${version.jdk}</target>
</configuration>
</plugin>
<plugin><!-- plug-in to attach source bundle in repo -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${version.plugin.javadoc}</version>
<configuration>
<source>${version.jdk}</source>
<target>${version.jdk}</target>
<encoding>UTF-8</encoding>
<maxmemory>512m</maxmemory>
<links>
<link>http://docs.oracle.com/javase/8/docs/api/</link>
</links>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- NOTE: repositories from parent POM -->
</project>
package com.fasterxml.classmate;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.*;
import com.fasterxml.classmate.util.ClassKey;
/**
* Interface for object that determines handling of annotations in regards
* to inheritance, overrides.
*/
@SuppressWarnings("serial")
public abstract class AnnotationConfiguration implements Serializable
{
/**
* Method called to figure out how to handle instances of specified annotation
* type when used as class annotation.
*/
public abstract AnnotationInclusion getInclusionForClass(Class<? extends Annotation> annotationType);
/**
* Method called to figure out how to handle instances of specified annotation
* type when used as constructor annotation.
*<p>
* Note that constructor annotations can never be inherited so this just determines
* between inclusion or non-inclusion.
*/
public abstract AnnotationInclusion getInclusionForConstructor(Class<? extends Annotation> annotationType);
/**
* Method called to figure out how to handle instances of specified annotation
* type when used as field annotation.
*<p>
* Note that field annotations can never be inherited so this just determines
* between inclusion or non-inclusion.
*/
public abstract AnnotationInclusion getInclusionForField(Class<? extends Annotation> annotationType);
/**
* Method called to figure out how to handle instances of specified annotation
* type when used as method annotation.
*<p>
* Note that method annotations can be inherited for member methods, but not for static
* methods; for static methods thereby this just determines between inclusion and
* non-inclusion.
*/
public abstract AnnotationInclusion getInclusionForMethod(Class<? extends Annotation> annotationType);
/**
* Method called to figure out how to handle instances of specified annotation
* type when used as parameter annotation.
*<p>
* Note that parameter annotations can be inherited for member methods, but not for static
* methods; for static methods thereby this just determines between inclusion and
* non-inclusion.
*/
public abstract AnnotationInclusion getInclusionForParameter(Class<? extends Annotation> annotationType);
/**
* Simple implementation that can be configured with default behavior
* for unknown annotations, as well as explicit behaviors for
* enumerated annotation types. Same default is used for both class and
* member method annotations (constructor, field and static method
* annotations are never inherited)
*/
public static class StdConfiguration extends AnnotationConfiguration implements Serializable
{
protected final AnnotationInclusion _defaultInclusion;
protected final HashMap<ClassKey,AnnotationInclusion> _inclusions = new HashMap<ClassKey,AnnotationInclusion>();
public StdConfiguration(AnnotationInclusion defaultBehavior)
{
_defaultInclusion = defaultBehavior;
}
@Override
public AnnotationInclusion getInclusionForClass(Class<? extends Annotation> annotationType) {
return _inclusionFor(annotationType);
}
@Override
public AnnotationInclusion getInclusionForConstructor(Class<? extends Annotation> annotationType) {
return _inclusionFor(annotationType);
}
@Override
public AnnotationInclusion getInclusionForField(Class<? extends Annotation> annotationType) {
return getInclusionForClass(annotationType);
}
@Override
public AnnotationInclusion getInclusionForMethod(Class<? extends Annotation> annotationType) {
return getInclusionForClass(annotationType);
}
@Override
public AnnotationInclusion getInclusionForParameter(Class<? extends Annotation> annotationType) {
return getInclusionForClass(annotationType);
}
public void setInclusion(Class<? extends Annotation> annotationType, AnnotationInclusion incl)
{
_inclusions.put(new ClassKey(annotationType), incl);
}
protected AnnotationInclusion _inclusionFor(Class<? extends Annotation> annotationType)
{
ClassKey key = new ClassKey(annotationType);
AnnotationInclusion beh = _inclusions.get(key);
return (beh == null) ? _defaultInclusion : beh;
}
}
}
package com.fasterxml.classmate;
/**
* Enumeration that defines different settings for handling behavior
* of individual annotations
*/
public enum AnnotationInclusion
{
/**
* Value that indicates that annotation is to be ignored, not included
* in resolved bean information.
* Applicable to all member types.
*/
DONT_INCLUDE,
/**
* Value that indicates that annotation is to be included in results, but
* only if directly associated with included member (or attached mix-in);
* will not inherit from supertypes.
* Applicable only to member methods; if used with other members will
* mean basic inclusion.
*/
INCLUDE_BUT_DONT_INHERIT,
/**
* Value that indicates that annotation is to be included in results, and
* values from overridden members are inherited only if the annotation is
* marked with the {@link java.lang.annotation.Inherited} annotation.
* Applicable only to member methods; if used with other members will
* mean basic inclusion.
*/
INCLUDE_AND_INHERIT_IF_INHERITED,
/**
* Value that indicates that annotation is to be included in results; and
* values from overridden members are also inherited if not overridden
* by members of subtypes.
* Note that inheritance only matters with member methods; for other types
* it just means "include".
*/
INCLUDE_AND_INHERIT
;
}
package com.fasterxml.classmate;
import java.io.Serializable;
import java.util.*;
import com.fasterxml.classmate.util.ClassKey;
/**
* Interface for object that can provide mix-ins to override annotations.
*/
@SuppressWarnings("serial")
public abstract class AnnotationOverrides implements Serializable
{
/*
/**********************************************************************
/* Public API
/**********************************************************************
*/
/**
* Method called to find out which class(es) are to be used as source
* for annotations to mix in for given type.
*
* @return List of mix-in sources (starting with highest priority);
* can be null or empty list if no mix-ins are to be used.
*/
public List<Class<?>> mixInsFor(Class<?> beanClass) {
return mixInsFor(new ClassKey(beanClass));
}
public abstract List<Class<?>> mixInsFor(ClassKey beanClass);
/**
* Method for constructing builder for creating simple overrides provider
* that just uses direct assignments (target-to-override classes)
*/
public static StdBuilder builder() {
return new StdBuilder();
}
/*
/**********************************************************************
/* Helper types
/**********************************************************************
*/
/**
* To make it easy to use simple override implementation (where overrides
* are direct and explicit), here is a build that allow constructing
* such override instance.
*/
public static class StdBuilder
{
protected final HashMap<ClassKey,List<Class<?>>> _targetsToOverrides = new HashMap<ClassKey,List<Class<?>>>();
public StdBuilder() { }
public StdBuilder add(Class<?> target, Class<?> mixin) {
return add(new ClassKey(target), mixin);
}
public StdBuilder add(ClassKey target, Class<?> mixin)
{
List<Class<?>> mixins = _targetsToOverrides.get(target);
if (mixins == null) {
mixins = new ArrayList<Class<?>>();
_targetsToOverrides.put(target, mixins);
}
mixins.add(mixin);
return this;
}
/**
* Method that will construct a {@link AnnotationOverrides} instance using
* mappings that have been added using this builder
*/
public AnnotationOverrides build() {
return new StdImpl(_targetsToOverrides);
}
}
/**
* Simple implementation configured with explicit associations with
* target class as key, and overrides as ordered list of classes
* (with first entry having precedence over later ones).
*/
public static class StdImpl extends AnnotationOverrides
{
protected final HashMap<ClassKey,List<Class<?>>> _targetsToOverrides;
public StdImpl(HashMap<ClassKey,List<Class<?>>> overrides) {
_targetsToOverrides = new HashMap<ClassKey,List<Class<?>>>(overrides);
}
@Override
public List<Class<?>> mixInsFor(ClassKey target) {
return _targetsToOverrides.get(target);
}
}
}
package com.fasterxml.classmate;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.*;
/**
* Container class used for storing set of annotations resolved for types (classes)
* as members (methods, fields, constructors).
*
* @author tatu
*/
@SuppressWarnings("serial")
public class Annotations implements Serializable, Iterable<Annotation>
{
private final Annotation[] NO_ANNOTATIONS = new Annotation[0];
protected LinkedHashMap<Class<? extends Annotation>,Annotation> _annotations;
/*
/**********************************************************************
/* Life-cycle
/**********************************************************************
*/
public Annotations() { }
/**
* Method for adding specified annotation, overriding existing value
* for the annotation type.
*/
public void add(Annotation override)
{
if (_annotations == null) {
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>();
}
_annotations.put(override.annotationType(), override);
}
/**
* Method for adding all annotations from specified set, as overrides
* to annotations this set has
*/
public void addAll(Annotations overrides)
{
if (_annotations == null) {
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>();
}
for (Annotation override : overrides._annotations.values()) {
_annotations.put(override.annotationType(), override);
}
}
/**
* Method for adding specified annotation if and only if no value
* exists for the annotation type.
*/
public void addAsDefault(Annotation defValue)
{
Class<? extends Annotation> type = defValue.annotationType();
if (_annotations == null) {
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>();
_annotations.put(type, defValue);
} else if (!_annotations.containsKey(type)) {
_annotations.put(type, defValue);
}
}
/*
/**********************************************************************
/* Accessors
/**********************************************************************
*/
@Override
public Iterator<Annotation> iterator()
{
if (_annotations == null) {
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>();
}
return _annotations.values().iterator();
}
public int size() {
return (_annotations == null) ? 0 : _annotations.size();
}
@SuppressWarnings("unchecked")
public <A extends Annotation> A get(Class<A> cls)
{
if (_annotations == null) {
return null;
}
return (A) _annotations.get(cls);
}
/**
* @since 1.1.1
*/
public Annotation[] asArray() {
if (_annotations == null || _annotations.isEmpty()) {
return NO_ANNOTATIONS;
}
return _annotations.values().toArray(new Annotation[_annotations.size()]);
}
/**
* @since 1.1.1
*/
public List<Annotation> asList() {
if (_annotations == null || _annotations.isEmpty()) {
return Collections.emptyList();
}
List<Annotation> l = new ArrayList<Annotation>(_annotations.size());
l.addAll(_annotations.values());
return l;
}
/*
/**********************************************************************
/* Standard method overrides
/**********************************************************************
*/
@Override public String toString()
{
if (_annotations == null) {
return "[null]";
}
return _annotations.toString();
}
}
package com.fasterxml.classmate;
/**
* Interface that defines API for basic filtering objects, used to prune set
* of things to include in result sets like flattened member lists.
*/
public interface Filter<T>
{
public boolean include(T element);
}
package com.fasterxml.classmate;
import java.io.Serializable;
/**
* This class is used to pass full generics type information, and
* avoid problems with type erasure (that basically removes most
* usable type references from runtime Class objects).
* It is based on ideas from
* <a href="http://gafter.blogspot.com/2006/12/super-type-tokens.html"
* >http://gafter.blogspot.com/2006/12/super-type-tokens.html</a>,
*<p>
* Usage is by sub-classing: here is one way to instantiate reference
* to generic type <code>List&lt;Integer&gt;</code>:
*<pre>
* GenericType type = new GenericType&lt;List&lt;Integer&gt;&gt;() { };