Return-Path: X-Original-To: apmail-incubator-deltaspike-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-deltaspike-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1CE8BB43C for ; Wed, 18 Jan 2012 09:39:02 +0000 (UTC) Received: (qmail 99207 invoked by uid 500); 18 Jan 2012 09:39:01 -0000 Delivered-To: apmail-incubator-deltaspike-commits-archive@incubator.apache.org Received: (qmail 99165 invoked by uid 500); 18 Jan 2012 09:38:57 -0000 Mailing-List: contact deltaspike-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: deltaspike-dev@incubator.apache.org Delivered-To: mailing list deltaspike-commits@incubator.apache.org Received: (qmail 99114 invoked by uid 99); 18 Jan 2012 09:38:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2012 09:38:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.114] (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2012 09:38:46 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B5C9E3183B9; Wed, 18 Jan 2012 09:38:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gpetracek@apache.org To: deltaspike-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: DELTASPIKE-45 reduced visibility of internal classes Message-Id: <20120118093825.B5C9E3183B9@tyr.zones.apache.org> Date: Wed, 18 Jan 2012 09:38:25 +0000 (UTC) Updated Branches: refs/heads/master dac181b8e -> 427a51860 DELTASPIKE-45 reduced visibility of internal classes Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/427a5186 Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/427a5186 Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/427a5186 Branch: refs/heads/master Commit: 427a518602fe4642ae213a19107295c3d1266492 Parents: dac181b Author: gpetracek Authored: Wed Jan 18 10:36:32 2012 +0100 Committer: gpetracek Committed: Wed Jan 18 10:36:32 2012 +0100 ---------------------------------------------------------------------- .../core/api/metadata/AnnotatedCallableImpl.java | 87 ------ .../api/metadata/AnnotatedConstructorImpl.java | 64 ---- .../core/api/metadata/AnnotatedFieldImpl.java | 42 --- .../core/api/metadata/AnnotatedImpl.java | 103 ------- .../core/api/metadata/AnnotatedMemberImpl.java | 62 ---- .../core/api/metadata/AnnotatedMethodImpl.java | 43 --- .../core/api/metadata/AnnotatedParameterImpl.java | 58 ---- .../core/api/metadata/AnnotatedTypeImpl.java | 139 --------- .../core/api/metadata/AnnotationRedefiner.java | 6 +- .../core/api/metadata/AnnotationStore.java | 65 ---- .../deltaspike/core/api/metadata/Parameter.java | 232 --------------- .../core/api/metadata/ParameterizedTypeImpl.java | 104 ------- .../core/api/metadata/RedefinitionContext.java | 5 +- .../metadata/builder/AnnotatedCallableImpl.java | 85 ++++++ .../metadata/builder/AnnotatedConstructorImpl.java | 64 ++++ .../api/metadata/builder/AnnotatedFieldImpl.java | 42 +++ .../core/api/metadata/builder/AnnotatedImpl.java | 103 +++++++ .../api/metadata/builder/AnnotatedMemberImpl.java | 62 ++++ .../api/metadata/builder/AnnotatedMethodImpl.java | 43 +++ .../metadata/builder/AnnotatedParameterImpl.java | 58 ++++ .../api/metadata/builder/AnnotatedTypeBuilder.java | 9 +- .../api/metadata/builder/AnnotatedTypeImpl.java | 138 +++++++++ .../api/metadata/builder/AnnotationBuilder.java | 1 - .../core/api/metadata/builder/AnnotationStore.java | 65 ++++ .../core/api/metadata/builder/Parameter.java | 232 +++++++++++++++ .../core/api/util/HierarchyDiscovery.java | 2 - .../core/api/util/ParameterizedTypeImpl.java | 104 +++++++ .../api/metadata/NamedAnnotationRedefiner.java | 4 +- 28 files changed, 1005 insertions(+), 1017 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java deleted file mode 100644 index cd27c95..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedCallableImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.deltaspike.core.api.metadata; - -import org.apache.deltaspike.core.api.metadata.builder.AnnotationBuilder; - -import javax.enterprise.inject.spi.AnnotatedCallable; -import javax.enterprise.inject.spi.AnnotatedParameter; -import javax.enterprise.inject.spi.AnnotatedType; -import java.lang.reflect.Member; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * - */ -abstract class AnnotatedCallableImpl extends AnnotatedMemberImpl - implements AnnotatedCallable -{ - - private final List> parameters; - - protected AnnotatedCallableImpl(AnnotatedType declaringType, Y member, Class memberType, - Class[] parameterTypes, Type[] genericTypes, AnnotationStore annotations, - Map parameterAnnotations, Type genericType, - Map parameterTypeOverrides) - { - super(declaringType, member, memberType, annotations, genericType, null); - this.parameters = getAnnotatedParameters(this, parameterTypes, genericTypes, parameterAnnotations, - parameterTypeOverrides); - } - - public List> getParameters() - { - return Collections.unmodifiableList(parameters); - } - - public AnnotatedParameter getParameter(int index) - { - return parameters.get(index); - - } - - private static List> getAnnotatedParameters(AnnotatedCallableImpl callable, Class[] parameterTypes, Type[] genericTypes, - Map parameterAnnotations, - Map parameterTypeOverrides) - { - List> parameters = new ArrayList>(); - int len = parameterTypes.length; - for (int i = 0; i < len; ++i) - { - AnnotationBuilder builder = new AnnotationBuilder(); - if (parameterAnnotations != null && parameterAnnotations.containsKey(i)) - { - builder.addAll(parameterAnnotations.get(i)); - } - Type over = null; - if (parameterTypeOverrides != null) - { - over = parameterTypeOverrides.get(i); - } - AnnotatedParameterImpl p = new AnnotatedParameterImpl(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over); - parameters.add(p); - } - return parameters; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java deleted file mode 100644 index 9cd1882..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedConstructorImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import javax.enterprise.inject.spi.AnnotatedConstructor; -import java.lang.reflect.Constructor; -import java.lang.reflect.Type; -import java.util.Map; - -/** - * Implementation of {@link AnnotatedConstructor} to be used in {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder} - * and other CDI life cycle events. - */ -class AnnotatedConstructorImpl extends AnnotatedCallableImpl> implements AnnotatedConstructor -{ - - /** - * Constructor - */ - public AnnotatedConstructorImpl(AnnotatedTypeImpl type, Constructor constructor, AnnotationStore annotations, - Map parameterAnnotations, Map typeOverrides) - { - - super(type, (Constructor) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), - getGenericArray(constructor), annotations, parameterAnnotations, null, typeOverrides); - } - - private static Type[] getGenericArray(Constructor constructor) - { - Type[] genericTypes = constructor.getGenericParameterTypes(); - // for inner classes genericTypes and parameterTypes can be different - // length, this is a hack to fix this. - // TODO: investigate this behavior further, on different JVM's and - // compilers - if (genericTypes.length + 1 == constructor.getParameterTypes().length) - { - genericTypes = new Type[constructor.getGenericParameterTypes().length + 1]; - genericTypes[0] = constructor.getParameterTypes()[0]; - for (int i = 0; i < constructor.getGenericParameterTypes().length; ++i) - { - genericTypes[i + 1] = constructor.getGenericParameterTypes()[i]; - } - } - return genericTypes; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java deleted file mode 100644 index 708cad2..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedFieldImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import javax.enterprise.inject.spi.AnnotatedField; -import javax.enterprise.inject.spi.AnnotatedType; -import java.lang.reflect.Field; -import java.lang.reflect.Type; - -/** - * Implementation of {@link AnnotatedField} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. - */ -class AnnotatedFieldImpl extends AnnotatedMemberImpl implements AnnotatedField -{ - - /** - * Constructor. - */ - public AnnotatedFieldImpl(AnnotatedType declaringType, Field field, AnnotationStore annotations, - Type overridenType) - { - super(declaringType, field, field.getType(), annotations, field.getGenericType(), overridenType); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java deleted file mode 100644 index ce9cf9c..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import org.apache.deltaspike.core.api.util.HierarchyDiscovery; - -import javax.enterprise.inject.spi.Annotated; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * The base class for all New Annotated types. - */ -abstract class AnnotatedImpl implements Annotated -{ - - private final Type type; - private final Set typeClosure; - private final AnnotationStore annotations; - - protected AnnotatedImpl(Class type, AnnotationStore annotations, Type genericType, Type overridenType) - { - if (overridenType == null) - { - if (genericType != null) - { - typeClosure = new HierarchyDiscovery(genericType).getTypeClosure(); - this.type = genericType; - } - else - { - typeClosure = new HierarchyDiscovery(type).getTypeClosure(); - this.type = type; - } - } - else - { - this.type = overridenType; - this.typeClosure = Collections.singleton(overridenType); - } - - - if (annotations == null) - { - this.annotations = new AnnotationStore(); - } - else - { - this.annotations = annotations; - } - } - - @Override - public T getAnnotation(Class annotationType) - { - return annotations.getAnnotation(annotationType); - } - - @Override - public Set getAnnotations() - { - return annotations.getAnnotations(); - } - - @Override - public boolean isAnnotationPresent(Class annotationType) - { - return annotations.isAnnotationPresent(annotationType); - } - - @Override - public Set getTypeClosure() - { - return new HashSet(typeClosure); - } - - @Override - public Type getBaseType() - { - return type; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java deleted file mode 100644 index d0f1d19..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMemberImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import javax.enterprise.inject.spi.AnnotatedMember; -import javax.enterprise.inject.spi.AnnotatedType; -import java.lang.reflect.Member; -import java.lang.reflect.Modifier; -import java.lang.reflect.Type; - -/** - * An implementation of {@link AnnotatedMember} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. - */ -abstract class AnnotatedMemberImpl extends AnnotatedImpl implements AnnotatedMember -{ - private final AnnotatedType declaringType; - private final M javaMember; - - protected AnnotatedMemberImpl(AnnotatedType declaringType, M member, Class memberType, - AnnotationStore annotations, Type genericType, Type overridenType) - { - super(memberType, annotations, genericType, overridenType); - this.declaringType = declaringType; - this.javaMember = member; - } - - @Override - public AnnotatedType getDeclaringType() - { - return declaringType; - } - - @Override - public M getJavaMember() - { - return javaMember; - } - - @Override - public boolean isStatic() - { - return Modifier.isStatic(javaMember.getModifiers()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java deleted file mode 100644 index 9db15de..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedMethodImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import javax.enterprise.inject.spi.AnnotatedMethod; -import javax.enterprise.inject.spi.AnnotatedType; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.Map; - -/** - * Implementation of {@link AnnotatedMethod} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. - */ -class AnnotatedMethodImpl extends AnnotatedCallableImpl implements AnnotatedMethod -{ - /** - * Constructor. - */ - public AnnotatedMethodImpl(AnnotatedType type, Method method, AnnotationStore annotations, - Map parameterAnnotations, Map parameterTypeOverrides) - { - super(type, method, method.getReturnType(), method.getParameterTypes(), method.getGenericParameterTypes(), - annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java deleted file mode 100644 index 6f09d32..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedParameterImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import javax.enterprise.inject.spi.AnnotatedCallable; -import javax.enterprise.inject.spi.AnnotatedParameter; -import java.lang.reflect.Type; - -/** - * - */ -class AnnotatedParameterImpl extends AnnotatedImpl implements AnnotatedParameter -{ - - private final int position; - private final AnnotatedCallable declaringCallable; - - /** - * Constructor - */ - public AnnotatedParameterImpl(AnnotatedCallable declaringCallable, Class type, int position, - AnnotationStore annotations, Type genericType, Type typeOverride) - { - super(type, annotations, genericType, typeOverride); - this.declaringCallable = declaringCallable; - this.position = position; - } - - @Override - public AnnotatedCallable getDeclaringCallable() - { - return declaringCallable; - } - - @Override - public int getPosition() - { - return position; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java deleted file mode 100644 index ba28de2..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotatedTypeImpl.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import javax.enterprise.inject.spi.AnnotatedConstructor; -import javax.enterprise.inject.spi.AnnotatedField; -import javax.enterprise.inject.spi.AnnotatedMethod; -import javax.enterprise.inject.spi.AnnotatedType; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * An implementation of {@link AnnotatedType} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. - */ -public class AnnotatedTypeImpl extends AnnotatedImpl implements AnnotatedType -{ - - private final Set> constructors; - private final Set> fields; - private final Set> methods; - - private final Class javaClass; - - /** - * We make sure that there is a NewAnnotatedMember for every public - * method/field/constructor - *

- * If annotation have been added to other methods as well we add them to - */ - public AnnotatedTypeImpl(Class clazz, AnnotationStore typeAnnotations, Map fieldAnnotations, Map methodAnnotations, - Map> methodParameterAnnotations, Map, AnnotationStore> constructorAnnotations, - Map, Map> constructorParameterAnnotations, Map fieldTypes, - Map> methodParameterTypes, Map, Map> constructorParameterTypes) - { - super(clazz, typeAnnotations, null, null); - this.javaClass = clazz; - this.constructors = new HashSet>(); - Set> cset = new HashSet>(); - Set mset = new HashSet(); - Set fset = new HashSet(); - for (Constructor c : clazz.getConstructors()) - { - AnnotatedConstructor nc = new AnnotatedConstructorImpl(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c), - constructorParameterTypes.get(c)); - constructors.add(nc); - cset.add(c); - } - for (Map.Entry, AnnotationStore> c : constructorAnnotations.entrySet()) - { - if (!cset.contains(c.getKey())) - { - AnnotatedConstructor nc = new AnnotatedConstructorImpl(this, c.getKey(), c.getValue(), constructorParameterAnnotations.get(c.getKey()), - constructorParameterTypes.get(c.getKey())); - constructors.add(nc); - } - } - this.methods = new HashSet>(); - for (Method m : clazz.getMethods()) - { - if (!m.getDeclaringClass().equals(Object.class)) - { - AnnotatedMethodImpl met = new AnnotatedMethodImpl(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m), methodParameterTypes.get(m)); - methods.add(met); - mset.add(m); - } - } - for (Map.Entry c : methodAnnotations.entrySet()) - { - if (!c.getKey().getDeclaringClass().equals(Object.class) && !mset.contains(c.getKey())) - { - AnnotatedMethodImpl nc = new AnnotatedMethodImpl(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), - methodParameterTypes.get(c.getKey())); - methods.add(nc); - } - } - this.fields = new HashSet>(); - for (Field f : clazz.getFields()) - { - AnnotatedField b = new AnnotatedFieldImpl(this, f, fieldAnnotations.get(f), fieldTypes.get(f)); - fields.add(b); - fset.add(f); - } - for (Map.Entry e : fieldAnnotations.entrySet()) - { - if (!fset.contains(e.getKey())) - { - fields.add(new AnnotatedFieldImpl(this, e.getKey(), e.getValue(), fieldTypes.get(e.getKey()))); - } - } - } - - @Override - public Set> getConstructors() - { - return Collections.unmodifiableSet(constructors); - } - - @Override - public Set> getFields() - { - return Collections.unmodifiableSet(fields); - } - - @Override - public Class getJavaClass() - { - return javaClass; - } - - @Override - public Set> getMethods() - { - return Collections.unmodifiableSet(methods); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java index c28a95f..1b9c02a 100644 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationRedefiner.java @@ -19,8 +19,6 @@ package org.apache.deltaspike.core.api.metadata; -import java.lang.annotation.Annotation; - /** * An implementation {@link AnnotationRedefiner} can be applied to an * {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}, and receives callbacks for each annotation of @@ -28,7 +26,7 @@ import java.lang.annotation.Annotation; * * @see org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder */ -public interface AnnotationRedefiner +public interface AnnotationRedefiner { /** * Callback invoked for each annotation of the type the @@ -36,6 +34,6 @@ public interface AnnotationRedefiner * * @param ctx */ - public void redefine(RedefinitionContext ctx); + public void redefine(RedefinitionContext ctx); } http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java deleted file mode 100644 index 9594293..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/AnnotationStore.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import java.lang.annotation.Annotation; -import java.util.Map; -import java.util.Set; - -import static java.util.Collections.emptyMap; -import static java.util.Collections.emptySet; -import static java.util.Collections.unmodifiableSet; - -/** - * A helper class used to hold annotations on a type or member. - */ -//X TODO: JavaDoc -public class AnnotationStore -{ - private final Map, Annotation> annotationMap; - private final Set annotationSet; - - public AnnotationStore(Map, Annotation> annotationMap, Set annotationSet) - { - this.annotationMap = annotationMap; - this.annotationSet = unmodifiableSet(annotationSet); - } - - public AnnotationStore() - { - this.annotationMap = emptyMap(); - this.annotationSet = emptySet(); - } - - public T getAnnotation(Class annotationType) - { - return annotationType.cast(annotationMap.get(annotationType)); - } - - public Set getAnnotations() - { - return annotationSet; - } - - public boolean isAnnotationPresent(Class annotationType) - { - return annotationMap.containsKey(annotationType); - } -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java deleted file mode 100644 index 661e151..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/Parameter.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import org.apache.deltaspike.core.api.util.Reflections; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Constructor; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.lang.reflect.Type; - - -/** - * An implementation of Member for parameters - */ -abstract public class Parameter implements AnnotatedElement -{ - - /** - * Creates a new {@link Parameter} using the member and position passed in. - * - * @param declaringMember {@link Method} or {@link Constructor}. - * @param position position of the parameter - * @param Type of the parameter - * @return a new instance of Parameter - */ - public static Parameter create(Member declaringMember, int position) - { - if (declaringMember instanceof Method) - { - return new MethodParameter((Method) declaringMember, position); - } - else if (declaringMember instanceof Constructor) - { - return new ConstructorParameter(Reflections.>cast(declaringMember), position); - } - else - { - throw new IllegalArgumentException("Can only process members of type Method and Constructor, cannot process " + declaringMember); - } - } - - private static class MethodParameter extends Parameter - { - - private final Method declaringMethod; - - private MethodParameter(Method declaringMethod, int position) - { - super(position); - this.declaringMethod = declaringMethod; - } - - @Override - public Method getDeclaringMember() - { - return declaringMethod; - } - - public Annotation[] getAnnotations() - { - if (declaringMethod.getParameterAnnotations().length > getPosition()) - { - return declaringMethod.getParameterAnnotations()[getPosition()]; - } - else - { - return Reflections.EMPTY_ANNOTATION_ARRAY; - } - } - - @Override - public Type getBaseType() - { - if (declaringMethod.getGenericParameterTypes().length > getPosition()) - { - return declaringMethod.getGenericParameterTypes()[getPosition()]; - } - else - { - return declaringMethod.getParameterTypes()[getPosition()]; - } - } - - } - - private static class ConstructorParameter extends Parameter - { - - private final Constructor declaringConstructor; - - private ConstructorParameter(Constructor declaringConstructor, int position) - { - super(position); - this.declaringConstructor = declaringConstructor; - } - - @Override - public Constructor getDeclaringMember() - { - return declaringConstructor; - } - - public Annotation[] getAnnotations() - { - if (declaringConstructor.getParameterAnnotations().length > getPosition()) - { - return declaringConstructor.getParameterAnnotations()[getPosition()]; - } - else - { - return Reflections.EMPTY_ANNOTATION_ARRAY; - } - } - - @Override - public Type getBaseType() - { - if (declaringConstructor.getGenericParameterTypes().length > getPosition()) - { - return declaringConstructor.getGenericParameterTypes()[getPosition()]; - } - else - { - return declaringConstructor.getParameterTypes()[getPosition()]; - } - } - - } - - private final int position; - - Parameter(int position) - { - this.position = position; - } - - /** - * Returns the actual {@link Member} declaring the parameter. - * - * @return Instance of the declaring java member. - */ - public abstract Member getDeclaringMember(); - - /** - * Getter - */ - public int getPosition() - { - return position; - } - - @Override - public int hashCode() - { - int hash = 1; - hash = hash * 31 + getDeclaringMember().hashCode(); - hash = hash * 31 + Integer.valueOf(position).hashCode(); - return hash; - } - - @Override - public boolean equals(Object obj) - { - if (obj instanceof Parameter) - { - Parameter that = (Parameter) obj; - return this.getDeclaringMember().equals(that.getDeclaringMember()) && this.getPosition() == that.getPosition(); - } - else - { - return false; - } - - } - - /** - * Returns the instance of the annotation on the member, or null if not found - */ - public T getAnnotation(Class annotationClass) - { - for (Annotation annotation : getAnnotations()) - { - if (annotation.annotationType().equals(annotationClass)) - { - return annotationClass.cast(annotation); - } - } - return null; - } - - /** - * Getter - */ - public Annotation[] getDeclaredAnnotations() - { - return getAnnotations(); - } - - /** - * Simple test if an annotation is present. - */ - public boolean isAnnotationPresent(Class annotationClass) - { - return getAnnotation(annotationClass) != null; - } - - /** - * Getter - */ - public abstract Type getBaseType(); - -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java deleted file mode 100644 index 445e54d..0000000 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/ParameterizedTypeImpl.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.deltaspike.core.api.metadata; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Arrays; - -/** - * A basic implementation of {@link ParameterizedType}. - */ -public class ParameterizedTypeImpl implements ParameterizedType -{ - private final Type[] actualTypeArguments; - private final Type rawType; - private final Type ownerType; - - public ParameterizedTypeImpl(Type rawType, Type[] actualTypeArguments, Type ownerType) - { - this.actualTypeArguments = actualTypeArguments; - this.rawType = rawType; - this.ownerType = ownerType; - } - - public Type[] getActualTypeArguments() - { - return Arrays.copyOf(actualTypeArguments, actualTypeArguments.length); - } - - public Type getOwnerType() - { - return ownerType; - } - - public Type getRawType() - { - return rawType; - } - - @Override - public int hashCode() - { - return Arrays.hashCode(actualTypeArguments) ^ (ownerType == null ? 0 : ownerType.hashCode()) ^ (rawType == null ? 0 : rawType.hashCode()); - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - else if (obj instanceof ParameterizedType) - { - ParameterizedType that = (ParameterizedType) obj; - Type thatOwnerType = that.getOwnerType(); - Type thatRawType = that.getRawType(); - return (ownerType == null ? thatOwnerType == null : ownerType.equals(thatOwnerType)) - && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) - && Arrays.equals(actualTypeArguments, that.getActualTypeArguments()); - } - else - { - return false; - } - - } - - @Override - public String toString() - { - StringBuilder sb = new StringBuilder(); - sb.append(rawType); - if (actualTypeArguments.length > 0) - { - sb.append("<"); - for (Type actualType : actualTypeArguments) - { - sb.append(actualType); - sb.append(","); - } - sb.delete(sb.length() - 1, sb.length()); - sb.append(">"); - } - return sb.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java index 98fb4f9..9d90a2a 100644 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/RedefinitionContext.java @@ -22,7 +22,6 @@ package org.apache.deltaspike.core.api.metadata; import org.apache.deltaspike.core.api.metadata.builder.AnnotationBuilder; import org.apache.deltaspike.core.api.util.Reflections; -import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Type; @@ -32,7 +31,7 @@ import java.lang.reflect.Type; * @see org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder * @see AnnotationRedefiner */ -public class RedefinitionContext +public class RedefinitionContext { private final AnnotatedElement annotatedElement; @@ -54,7 +53,7 @@ public class RedefinitionContext * {@link java.lang.reflect.Field}, if defined on a method, this may be cast to {@link java.lang.reflect.Method}, * if defined on a constructor, this may be cast to {@link java.lang.reflect.Constructor}, if * defined on a class, this may be cast to {@link Class}, or if - * defined on a parameter, this may be cast to {@link Parameter} + * defined on a parameter, this may be cast to {@link org.apache.deltaspike.core.api.metadata.builder.Parameter} */ public AnnotatedElement getAnnotatedElement() { http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedCallableImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedCallableImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedCallableImpl.java new file mode 100644 index 0000000..578bf95 --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedCallableImpl.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.core.api.metadata.builder; + +import javax.enterprise.inject.spi.AnnotatedCallable; +import javax.enterprise.inject.spi.AnnotatedParameter; +import javax.enterprise.inject.spi.AnnotatedType; +import java.lang.reflect.Member; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * + */ +abstract class AnnotatedCallableImpl extends AnnotatedMemberImpl + implements AnnotatedCallable +{ + + private final List> parameters; + + protected AnnotatedCallableImpl(AnnotatedType declaringType, Y member, Class memberType, + Class[] parameterTypes, Type[] genericTypes, AnnotationStore annotations, + Map parameterAnnotations, Type genericType, + Map parameterTypeOverrides) + { + super(declaringType, member, memberType, annotations, genericType, null); + this.parameters = getAnnotatedParameters(this, parameterTypes, genericTypes, parameterAnnotations, + parameterTypeOverrides); + } + + public List> getParameters() + { + return Collections.unmodifiableList(parameters); + } + + public AnnotatedParameter getParameter(int index) + { + return parameters.get(index); + + } + + private static List> getAnnotatedParameters(AnnotatedCallableImpl callable, Class[] parameterTypes, Type[] genericTypes, + Map parameterAnnotations, + Map parameterTypeOverrides) + { + List> parameters = new ArrayList>(); + int len = parameterTypes.length; + for (int i = 0; i < len; ++i) + { + AnnotationBuilder builder = new AnnotationBuilder(); + if (parameterAnnotations != null && parameterAnnotations.containsKey(i)) + { + builder.addAll(parameterAnnotations.get(i)); + } + Type over = null; + if (parameterTypeOverrides != null) + { + over = parameterTypeOverrides.get(i); + } + AnnotatedParameterImpl p = new AnnotatedParameterImpl(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over); + parameters.add(p); + } + return parameters; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedConstructorImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedConstructorImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedConstructorImpl.java new file mode 100644 index 0000000..24f49bd --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedConstructorImpl.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import javax.enterprise.inject.spi.AnnotatedConstructor; +import java.lang.reflect.Constructor; +import java.lang.reflect.Type; +import java.util.Map; + +/** + * Implementation of {@link AnnotatedConstructor} to be used in {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder} + * and other CDI life cycle events. + */ +class AnnotatedConstructorImpl extends AnnotatedCallableImpl> implements AnnotatedConstructor +{ + + /** + * Constructor + */ + public AnnotatedConstructorImpl(AnnotatedTypeImpl type, Constructor constructor, AnnotationStore annotations, + Map parameterAnnotations, Map typeOverrides) + { + + super(type, (Constructor) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), + getGenericArray(constructor), annotations, parameterAnnotations, null, typeOverrides); + } + + private static Type[] getGenericArray(Constructor constructor) + { + Type[] genericTypes = constructor.getGenericParameterTypes(); + // for inner classes genericTypes and parameterTypes can be different + // length, this is a hack to fix this. + // TODO: investigate this behavior further, on different JVM's and + // compilers + if (genericTypes.length + 1 == constructor.getParameterTypes().length) + { + genericTypes = new Type[constructor.getGenericParameterTypes().length + 1]; + genericTypes[0] = constructor.getParameterTypes()[0]; + for (int i = 0; i < constructor.getGenericParameterTypes().length; ++i) + { + genericTypes[i + 1] = constructor.getGenericParameterTypes()[i]; + } + } + return genericTypes; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedFieldImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedFieldImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedFieldImpl.java new file mode 100644 index 0000000..5fe9f15 --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedFieldImpl.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import javax.enterprise.inject.spi.AnnotatedField; +import javax.enterprise.inject.spi.AnnotatedType; +import java.lang.reflect.Field; +import java.lang.reflect.Type; + +/** + * Implementation of {@link AnnotatedField} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. + */ +class AnnotatedFieldImpl extends AnnotatedMemberImpl implements AnnotatedField +{ + + /** + * Constructor. + */ + public AnnotatedFieldImpl(AnnotatedType declaringType, Field field, AnnotationStore annotations, + Type overridenType) + { + super(declaringType, field, field.getType(), annotations, field.getGenericType(), overridenType); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedImpl.java new file mode 100644 index 0000000..d161835 --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedImpl.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import org.apache.deltaspike.core.api.util.HierarchyDiscovery; + +import javax.enterprise.inject.spi.Annotated; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * The base class for all New Annotated types. + */ +abstract class AnnotatedImpl implements Annotated +{ + + private final Type type; + private final Set typeClosure; + private final AnnotationStore annotations; + + protected AnnotatedImpl(Class type, AnnotationStore annotations, Type genericType, Type overridenType) + { + if (overridenType == null) + { + if (genericType != null) + { + typeClosure = new HierarchyDiscovery(genericType).getTypeClosure(); + this.type = genericType; + } + else + { + typeClosure = new HierarchyDiscovery(type).getTypeClosure(); + this.type = type; + } + } + else + { + this.type = overridenType; + this.typeClosure = Collections.singleton(overridenType); + } + + + if (annotations == null) + { + this.annotations = new AnnotationStore(); + } + else + { + this.annotations = annotations; + } + } + + @Override + public T getAnnotation(Class annotationType) + { + return annotations.getAnnotation(annotationType); + } + + @Override + public Set getAnnotations() + { + return annotations.getAnnotations(); + } + + @Override + public boolean isAnnotationPresent(Class annotationType) + { + return annotations.isAnnotationPresent(annotationType); + } + + @Override + public Set getTypeClosure() + { + return new HashSet(typeClosure); + } + + @Override + public Type getBaseType() + { + return type; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMemberImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMemberImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMemberImpl.java new file mode 100644 index 0000000..886db5e --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMemberImpl.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import javax.enterprise.inject.spi.AnnotatedMember; +import javax.enterprise.inject.spi.AnnotatedType; +import java.lang.reflect.Member; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; + +/** + * An implementation of {@link AnnotatedMember} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. + */ +abstract class AnnotatedMemberImpl extends AnnotatedImpl implements AnnotatedMember +{ + private final AnnotatedType declaringType; + private final M javaMember; + + protected AnnotatedMemberImpl(AnnotatedType declaringType, M member, Class memberType, + AnnotationStore annotations, Type genericType, Type overridenType) + { + super(memberType, annotations, genericType, overridenType); + this.declaringType = declaringType; + this.javaMember = member; + } + + @Override + public AnnotatedType getDeclaringType() + { + return declaringType; + } + + @Override + public M getJavaMember() + { + return javaMember; + } + + @Override + public boolean isStatic() + { + return Modifier.isStatic(javaMember.getModifiers()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMethodImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMethodImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMethodImpl.java new file mode 100644 index 0000000..3c9e156 --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedMethodImpl.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import javax.enterprise.inject.spi.AnnotatedMethod; +import javax.enterprise.inject.spi.AnnotatedType; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.Map; + +/** + * Implementation of {@link AnnotatedMethod} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. + */ +class AnnotatedMethodImpl extends AnnotatedCallableImpl implements AnnotatedMethod +{ + /** + * Constructor. + */ + public AnnotatedMethodImpl(AnnotatedType type, Method method, AnnotationStore annotations, + Map parameterAnnotations, Map parameterTypeOverrides) + { + super(type, method, method.getReturnType(), method.getParameterTypes(), method.getGenericParameterTypes(), + annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedParameterImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedParameterImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedParameterImpl.java new file mode 100644 index 0000000..c9682d2 --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedParameterImpl.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import javax.enterprise.inject.spi.AnnotatedCallable; +import javax.enterprise.inject.spi.AnnotatedParameter; +import java.lang.reflect.Type; + +/** + * + */ +class AnnotatedParameterImpl extends AnnotatedImpl implements AnnotatedParameter +{ + + private final int position; + private final AnnotatedCallable declaringCallable; + + /** + * Constructor + */ + public AnnotatedParameterImpl(AnnotatedCallable declaringCallable, Class type, int position, + AnnotationStore annotations, Type genericType, Type typeOverride) + { + super(type, annotations, genericType, typeOverride); + this.declaringCallable = declaringCallable; + this.position = position; + } + + @Override + public AnnotatedCallable getDeclaringCallable() + { + return declaringCallable; + } + + @Override + public int getPosition() + { + return position; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java index c6b25ff..1df78fc 100644 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeBuilder.java @@ -19,10 +19,7 @@ package org.apache.deltaspike.core.api.metadata.builder; -import org.apache.deltaspike.core.api.metadata.AnnotatedTypeImpl; import org.apache.deltaspike.core.api.metadata.AnnotationRedefiner; -import org.apache.deltaspike.core.api.metadata.AnnotationStore; -import org.apache.deltaspike.core.api.metadata.Parameter; import org.apache.deltaspike.core.api.metadata.RedefinitionContext; import org.apache.deltaspike.core.api.util.Reflections; @@ -522,7 +519,7 @@ public class AnnotatedTypeBuilder * @throws IllegalArgumentException if the annotationType or redefinition is * null */ - public AnnotatedTypeBuilder redefine(Class annotationType, AnnotationRedefiner redefinition) + public AnnotatedTypeBuilder redefine(Class annotationType, AnnotationRedefiner redefinition) { if (annotationType == null) { @@ -571,13 +568,13 @@ public class AnnotatedTypeBuilder } protected void redefineAnnotationBuilder(Class annotationType, - AnnotationRedefiner redefinition, + AnnotationRedefiner redefinition, AnnotatedElement annotated, Type baseType, AnnotationBuilder builder, String elementName) { if (builder.isAnnotationPresent(annotationType)) { - redefinition.redefine(new RedefinitionContext(annotated, baseType, builder, elementName)); + redefinition.redefine(new RedefinitionContext(annotated, baseType, builder, elementName)); } } http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeImpl.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeImpl.java new file mode 100644 index 0000000..1c908af --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotatedTypeImpl.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import javax.enterprise.inject.spi.AnnotatedConstructor; +import javax.enterprise.inject.spi.AnnotatedField; +import javax.enterprise.inject.spi.AnnotatedMethod; +import javax.enterprise.inject.spi.AnnotatedType; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * An implementation of {@link AnnotatedType} to be used in CDI life cycle events and {@link org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder}. + */ +class AnnotatedTypeImpl extends AnnotatedImpl implements AnnotatedType +{ + + private final Set> constructors; + private final Set> fields; + private final Set> methods; + + private final Class javaClass; + + /** + * We make sure that there is a NewAnnotatedMember for every public + * method/field/constructor + *

+ * If annotation have been added to other methods as well we add them to + */ + AnnotatedTypeImpl(Class clazz, AnnotationStore typeAnnotations, Map fieldAnnotations, Map methodAnnotations, + Map> methodParameterAnnotations, Map, AnnotationStore> constructorAnnotations, + Map, Map> constructorParameterAnnotations, Map fieldTypes, + Map> methodParameterTypes, Map, Map> constructorParameterTypes) + { + super(clazz, typeAnnotations, null, null); + this.javaClass = clazz; + this.constructors = new HashSet>(); + Set> cset = new HashSet>(); + Set mset = new HashSet(); + Set fset = new HashSet(); + for (Constructor c : clazz.getConstructors()) + { + AnnotatedConstructor nc = new AnnotatedConstructorImpl(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c), + constructorParameterTypes.get(c)); + constructors.add(nc); + cset.add(c); + } + for (Map.Entry, AnnotationStore> c : constructorAnnotations.entrySet()) + { + if (!cset.contains(c.getKey())) + { + AnnotatedConstructor nc = new AnnotatedConstructorImpl(this, c.getKey(), c.getValue(), constructorParameterAnnotations.get(c.getKey()), + constructorParameterTypes.get(c.getKey())); + constructors.add(nc); + } + } + this.methods = new HashSet>(); + for (Method m : clazz.getMethods()) + { + if (!m.getDeclaringClass().equals(Object.class)) + { + AnnotatedMethodImpl met = new AnnotatedMethodImpl(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m), methodParameterTypes.get(m)); + methods.add(met); + mset.add(m); + } + } + for (Map.Entry c : methodAnnotations.entrySet()) + { + if (!c.getKey().getDeclaringClass().equals(Object.class) && !mset.contains(c.getKey())) + { + AnnotatedMethodImpl nc = new AnnotatedMethodImpl(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), + methodParameterTypes.get(c.getKey())); + methods.add(nc); + } + } + this.fields = new HashSet>(); + for (Field f : clazz.getFields()) + { + AnnotatedField b = new AnnotatedFieldImpl(this, f, fieldAnnotations.get(f), fieldTypes.get(f)); + fields.add(b); + fset.add(f); + } + for (Map.Entry e : fieldAnnotations.entrySet()) + { + if (!fset.contains(e.getKey())) + { + fields.add(new AnnotatedFieldImpl(this, e.getKey(), e.getValue(), fieldTypes.get(e.getKey()))); + } + } + } + + @Override + public Set> getConstructors() + { + return Collections.unmodifiableSet(constructors); + } + + @Override + public Set> getFields() + { + return Collections.unmodifiableSet(fields); + } + + @Override + public Class getJavaClass() + { + return javaClass; + } + + @Override + public Set> getMethods() + { + return Collections.unmodifiableSet(methods); + } +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationBuilder.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationBuilder.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationBuilder.java index e708618..a0ca8d4 100644 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationBuilder.java +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationBuilder.java @@ -19,7 +19,6 @@ package org.apache.deltaspike.core.api.metadata.builder; -import org.apache.deltaspike.core.api.metadata.AnnotationStore; import org.apache.deltaspike.core.api.util.Reflections; import java.lang.annotation.Annotation; http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationStore.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationStore.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationStore.java new file mode 100644 index 0000000..1a6b7fb --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/AnnotationStore.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import java.lang.annotation.Annotation; +import java.util.Map; +import java.util.Set; + +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; +import static java.util.Collections.unmodifiableSet; + +/** + * A helper class used to hold annotations on a type or member. + */ +//X TODO: JavaDoc +class AnnotationStore +{ + private final Map, Annotation> annotationMap; + private final Set annotationSet; + + AnnotationStore(Map, Annotation> annotationMap, Set annotationSet) + { + this.annotationMap = annotationMap; + this.annotationSet = unmodifiableSet(annotationSet); + } + + AnnotationStore() + { + this.annotationMap = emptyMap(); + this.annotationSet = emptySet(); + } + + T getAnnotation(Class annotationType) + { + return annotationType.cast(annotationMap.get(annotationType)); + } + + Set getAnnotations() + { + return annotationSet; + } + + boolean isAnnotationPresent(Class annotationType) + { + return annotationMap.containsKey(annotationType); + } +} http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/427a5186/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/Parameter.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/Parameter.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/Parameter.java new file mode 100644 index 0000000..8006c5d --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/metadata/builder/Parameter.java @@ -0,0 +1,232 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.api.metadata.builder; + +import org.apache.deltaspike.core.api.util.Reflections; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Constructor; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.lang.reflect.Type; + + +/** + * An implementation of Member for parameters + */ +abstract class Parameter implements AnnotatedElement +{ + + /** + * Creates a new {@link Parameter} using the member and position passed in. + * + * @param declaringMember {@link Method} or {@link Constructor}. + * @param position position of the parameter + * @param Type of the parameter + * @return a new instance of Parameter + */ + public static Parameter create(Member declaringMember, int position) + { + if (declaringMember instanceof Method) + { + return new MethodParameter((Method) declaringMember, position); + } + else if (declaringMember instanceof Constructor) + { + return new ConstructorParameter(Reflections.>cast(declaringMember), position); + } + else + { + throw new IllegalArgumentException("Can only process members of type Method and Constructor, cannot process " + declaringMember); + } + } + + private static class MethodParameter extends Parameter + { + + private final Method declaringMethod; + + private MethodParameter(Method declaringMethod, int position) + { + super(position); + this.declaringMethod = declaringMethod; + } + + @Override + public Method getDeclaringMember() + { + return declaringMethod; + } + + public Annotation[] getAnnotations() + { + if (declaringMethod.getParameterAnnotations().length > getPosition()) + { + return declaringMethod.getParameterAnnotations()[getPosition()]; + } + else + { + return Reflections.EMPTY_ANNOTATION_ARRAY; + } + } + + @Override + public Type getBaseType() + { + if (declaringMethod.getGenericParameterTypes().length > getPosition()) + { + return declaringMethod.getGenericParameterTypes()[getPosition()]; + } + else + { + return declaringMethod.getParameterTypes()[getPosition()]; + } + } + + } + + private static class ConstructorParameter extends Parameter + { + + private final Constructor declaringConstructor; + + private ConstructorParameter(Constructor declaringConstructor, int position) + { + super(position); + this.declaringConstructor = declaringConstructor; + } + + @Override + public Constructor getDeclaringMember() + { + return declaringConstructor; + } + + public Annotation[] getAnnotations() + { + if (declaringConstructor.getParameterAnnotations().length > getPosition()) + { + return declaringConstructor.getParameterAnnotations()[getPosition()]; + } + else + { + return Reflections.EMPTY_ANNOTATION_ARRAY; + } + } + + @Override + public Type getBaseType() + { + if (declaringConstructor.getGenericParameterTypes().length > getPosition()) + { + return declaringConstructor.getGenericParameterTypes()[getPosition()]; + } + else + { + return declaringConstructor.getParameterTypes()[getPosition()]; + } + } + + } + + private final int position; + + Parameter(int position) + { + this.position = position; + } + + /** + * Returns the actual {@link Member} declaring the parameter. + * + * @return Instance of the declaring java member. + */ + public abstract Member getDeclaringMember(); + + /** + * Getter + */ + public int getPosition() + { + return position; + } + + @Override + public int hashCode() + { + int hash = 1; + hash = hash * 31 + getDeclaringMember().hashCode(); + hash = hash * 31 + Integer.valueOf(position).hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (obj instanceof Parameter) + { + Parameter that = (Parameter) obj; + return this.getDeclaringMember().equals(that.getDeclaringMember()) && this.getPosition() == that.getPosition(); + } + else + { + return false; + } + + } + + /** + * Returns the instance of the annotation on the member, or null if not found + */ + public T getAnnotation(Class annotationClass) + { + for (Annotation annotation : getAnnotations()) + { + if (annotation.annotationType().equals(annotationClass)) + { + return annotationClass.cast(annotation); + } + } + return null; + } + + /** + * Getter + */ + public Annotation[] getDeclaredAnnotations() + { + return getAnnotations(); + } + + /** + * Simple test if an annotation is present. + */ + public boolean isAnnotationPresent(Class annotationClass) + { + return getAnnotation(annotationClass) != null; + } + + /** + * Getter + */ + public abstract Type getBaseType(); + +}