From 7d035f2da414c81b6a7c34b4f2d946303e59dcee Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 26 Nov 2009 00:44:25 +0000 Subject: Call all of visitXXX methods on the visitors one by one so that a visitor is always invoked before the other one git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@884348 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/impl/JavaClassIntrospectorImpl.java | 74 +++++++++------------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java index 6cb5e3730b..ff41517862 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java @@ -70,72 +70,60 @@ public class JavaClassIntrospectorImpl { */ public void introspectClass(JavaImplementation type, Class clazz) throws IntrospectionException { - for (JavaClassVisitor extension : visitors) { - extension.visitClass(clazz, type); - } - - for (Constructor constructor : clazz.getConstructors()) { - for (JavaClassVisitor extension : visitors) { - extension.visitConstructor(constructor, type); + for (JavaClassVisitor visitor : visitors) { + visitor.visitClass(clazz, type); + for (Constructor constructor : clazz.getConstructors()) { + visitor.visitConstructor(constructor, type); // Assuming the visitClass or visitConstructor will populate the // type.getConstructors JavaConstructorImpl definition = type.getConstructors().get(constructor); if (definition != null) { for (JavaParameterImpl p : definition.getParameters()) { - extension.visitConstructorParameter(p, type); + visitor.visitConstructorParameter(p, type); } } } - } - Set fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(clazz, true); - for (Field field : fields) { - for (JavaClassVisitor extension : visitors) { - extension.visitField(field, type); + Set fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(clazz, true); + for (Field field : fields) { + visitor.visitField(field, type); } - } - // Check if any private fields have illegal annotations that should be raised as errors - Set privateFields = JavaIntrospectionHelper.getPrivateFields(clazz); - for (Field field : privateFields) { - for (JavaClassVisitor processor : visitors) { - processor.visitField(field, type); + // Check if any private fields have illegal annotations that should be raised as errors + Set privateFields = JavaIntrospectionHelper.getPrivateFields(clazz); + for (Field field : privateFields) { + visitor.visitField(field, type); } - } - - Set methods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(clazz, true); - for (Method method : methods) { - for (JavaClassVisitor processor : visitors) { - processor.visitMethod(method, type); + + Set methods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(clazz, true); + for (Method method : methods) { + visitor.visitMethod(method, type); } - } - // Check if any private methods have illegal annotations that should be raised as errors - Set privateMethods = JavaIntrospectionHelper.getPrivateMethods(clazz); - for (Method method : privateMethods) { - for (JavaClassVisitor processor : visitors) { - processor.visitMethod(method, type); + // Check if any private methods have illegal annotations that should be raised as errors + Set privateMethods = JavaIntrospectionHelper.getPrivateMethods(clazz); + for (Method method : privateMethods) { + visitor.visitMethod(method, type); } - } - Class superClass = clazz.getSuperclass(); - if (superClass != null) { - visitSuperClass(superClass, type); - } + Class superClass = clazz.getSuperclass(); + if (superClass != null) { + visitSuperClass(superClass, type, visitor); + } + + visitor.visitEnd(clazz, type); - for (JavaClassVisitor extension : visitors) { - extension.visitEnd(clazz, type); } + } - private void visitSuperClass(Class clazz, JavaImplementation type) throws IntrospectionException { + private void visitSuperClass(Class clazz, JavaImplementation type, JavaClassVisitor visitor) + throws IntrospectionException { if (!Object.class.equals(clazz)) { - for (JavaClassVisitor extension : visitors) { - extension.visitSuperClass(clazz, type); - } + visitor.visitSuperClass(clazz, type); clazz = clazz.getSuperclass(); if (clazz != null) { - visitSuperClass(clazz, type); + visitSuperClass(clazz, type, visitor); } } } -- cgit v1.2.3