Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.tuscany.sca.implementation.java.impl;
 
 import java.util.List;
 import java.util.Set;
 
An extensible Java class introspector implementation.

Version:
$Rev: 957343 $ $Date: 2010-06-24 00:07:57 +0300 (Thu, 24 Jun 2010) $
 
 public class JavaClassIntrospectorImpl {
     
     private List<JavaClassVisitorvisitors;
 
     public JavaClassIntrospectorImpl(List<JavaClassVisitorvisitors) {
         this. = visitors;
     }

    
JSR-250 PFD recommends the following guidelines for how annotations interact with inheritance in order to keep the resulting complexity in control:
  1. Class-level annotations only affect the class they annotate and their members, that is, its methods and fields. They never affect a member declared by a superclass, even if it is not hidden or overridden by the class in question.
  2. In addition to affecting the annotated class, class-level annotations may act as a shorthand for member-level annotations. If a member carries a specific member-level annotation, any annotations of the same type implied by a class-level annotation are ignored. In other words, explicit member-level annotations have priority over member-level annotations implied by a class-level annotation.
  3. The interfaces implemented by a class never contribute annotations to the class itself or any of its members.
  4. Members inherited from a superclass and which are not hidden or overridden maintain the annotations they had in the class that declared them, including member-level annotations implied by class-level ones.
  5. Member-level annotations on a hidden or overridden member are always ignored.
 
     public void introspectClass(JavaImplementation typeClass<?> clazz)
         throws IntrospectionException {
         for (JavaClassVisitor visitor : ) {
             visitor.visitClass(clazztype);
             for (Constructor<?> constructor : clazz.getConstructors()) {
                 visitor.visitConstructor(constructortype);
                 // Assuming the visitClass or visitConstructor will populate the
                 // type.getConstructors
                 JavaConstructorImpl<?> definition = type.getConstructors().get(constructor);
                 if (definition != null) {
                     for (JavaParameterImpl p : definition.getParameters()) {
                         visitor.visitConstructorParameter(ptype);
                     }
                 }
             }
 
             Set<Fieldfields = JavaIntrospectionHelper.getInjectableFields(clazztrue);
             for (Field field : fields) {
                 visitor.visitField(fieldtype);
             }
 
             Set<Methodmethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(clazztrue);
             for (Method method : methods) {
                 visitor.visitMethod(methodtype);
             }
 
             // Check if any private methods have illegal annotations that should be raised as errors
             Set<MethodprivateMethods = JavaIntrospectionHelper.getPrivateMethods(clazz);
             for (Method method : privateMethods) {
                visitor.visitMethod(methodtype);
            }
            Class<?> superClass = clazz.getSuperclass();
            if (superClass != null) {
                visitSuperClass(superClasstypevisitor);
            }
            visitor.visitEnd(clazztype);
        }
    }
    private void visitSuperClass(Class<?> clazzJavaImplementation typeJavaClassVisitor visitor)
        throws IntrospectionException {
        if (!Object.class.equals(clazz)) {
            visitor.visitSuperClass(clazztype);
            clazz = clazz.getSuperclass();
            if (clazz != null) {
                visitSuperClass(clazztypevisitor);
            }
        }
    }
New to GrepCode? Check out our FAQ X