You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by db...@apache.org on 2012/06/06 05:09:45 UTC
svn commit: r1346722 - in
/commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder:
AnnotationFinder.java model/ClassInfo.java model/InfoHandler.java
Author: dblevins
Date: Wed Jun 6 03:09:45 2012
New Revision: 1346722
URL: http://svn.apache.org/viewvc?rev=1346722&view=rev
Log:
slight introduction of a listener api (incomplete)
Added:
commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/InfoHandler.java
Modified:
commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java
commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/ClassInfo.java
Modified: commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java?rev=1346722&r1=1346721&r2=1346722&view=diff
==============================================================================
--- commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java (original)
+++ commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java Wed Jun 6 03:09:45 2012
@@ -29,6 +29,7 @@ import org.apache.commons.classscan.find
import org.apache.commons.classscan.finder.model.ClassInfo;
import org.apache.commons.classscan.finder.model.FieldInfo;
import org.apache.commons.classscan.finder.model.Info;
+import org.apache.commons.classscan.finder.model.InfoHandler;
import org.apache.commons.classscan.finder.model.MethodInfo;
import org.apache.commons.classscan.finder.model.PackageInfo;
import org.apache.commons.classscan.finder.util.SingleLinkedList;
@@ -69,7 +70,7 @@ import java.util.Set;
*
* @version $Rev$ $Date$
*/
-public class AnnotationFinder implements IAnnotationFinder {
+public class AnnotationFinder implements IAnnotationFinder, InfoHandler {
private final Set<Class<? extends Annotation>> metaroots = new HashSet<Class<? extends Annotation>>();
@@ -1036,6 +1037,28 @@ public class AnnotationFinder implements
initAnnotationInfos(annotationInfo.getName()).add(info);
}
+ @Override
+ public void visit(ClassInfo info) {
+ classInfos.put(info.getName(), info);
+ }
+
+ @Override
+ public void visit(MethodInfo info) {
+ }
+
+ @Override
+ public void visit(FieldInfo info) {
+ }
+
+ @Override
+ public void visit(PackageInfo info) {
+ }
+
+ @Override
+ public void visit(AnnotationInfo annotationInfo, Info info) {
+ index(annotationInfo, info);
+ }
+
protected void readClassDef(String className) {
if (classInfos.containsKey(className)) return;
try {
@@ -1090,6 +1113,16 @@ public class AnnotationFinder implements
// With a cleaned up model, this could easily be abstracted
//
//----------------------------------------------------------------------------
+ public static class AsmParser {
+
+ private final InfoHandler handler;
+
+ public AsmParser(InfoHandler handler) {
+ this.handler = handler;
+ }
+
+ }
+
protected void readClassDef(InputStream in) throws IOException {
try {
final ClassReader classReader = new ClassReader(in);
@@ -1100,7 +1133,10 @@ public class AnnotationFinder implements
}
}
- public class InfoBuildingVisitor extends EmptyVisitor {
+ private final InfoHandler handler = this;
+
+ public class InfoBuildingVisitor extends EmptyVisitor {
+
private Info info;
public InfoBuildingVisitor() {
@@ -1110,10 +1146,12 @@ public class AnnotationFinder implements
this.info = info;
}
+
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
if (name.endsWith("package-info")) {
info = new PackageInfo(archive, javaName(name));
+ handler.visit((PackageInfo) info);
} else {
ClassInfo classInfo = new ClassInfo(archive, javaName(name), javaName(superName));
@@ -1124,7 +1162,7 @@ public class AnnotationFinder implements
info = classInfo;
- classInfos.put(classInfo.getName(), classInfo);
+ handler.visit((ClassInfo) info);
}
}
@@ -1147,7 +1185,9 @@ public class AnnotationFinder implements
final String name = Type.getType(desc).getClassName();
AnnotationInfo annotationInfo = new AnnotationInfo(name);
info.getAnnotations().add(annotationInfo);
- index(annotationInfo, info);
+
+ handler.visit(annotationInfo, info);
+
return new InfoBuildingVisitor(annotationInfo);
}
@@ -1156,6 +1196,9 @@ public class AnnotationFinder implements
ClassInfo classInfo = ((ClassInfo) info);
FieldInfo fieldInfo = new FieldInfo(classInfo, name, desc);
classInfo.getFields().add(fieldInfo);
+
+ handler.visit(fieldInfo);
+
return new InfoBuildingVisitor(fieldInfo);
}
@@ -1169,8 +1212,10 @@ public class AnnotationFinder implements
}
MethodInfo methodInfo = new MethodInfo(classInfo, name, params);
-
classInfo.getMethods().add(methodInfo);
+
+ handler.visit(methodInfo);
+
return new InfoBuildingVisitor(methodInfo);
}
Modified: commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/ClassInfo.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/ClassInfo.java?rev=1346722&r1=1346721&r2=1346722&view=diff
==============================================================================
--- commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/ClassInfo.java (original)
+++ commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/ClassInfo.java Wed Jun 6 03:09:45 2012
@@ -119,6 +119,12 @@ public class ClassInfo extends Annotatab
return subclassInfos;
}
+ /**
+ * Differes from the 'get()' call in
+ * that it does not trigger lazy loading
+ *
+ * @return
+ */
public Class<?> getClazz() {
return clazz;
}
Added: commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/InfoHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/InfoHandler.java?rev=1346722&view=auto
==============================================================================
--- commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/InfoHandler.java (added)
+++ commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/InfoHandler.java Wed Jun 6 03:09:45 2012
@@ -0,0 +1,29 @@
+/*
+ * 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.commons.classscan.finder.model;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface InfoHandler {
+
+ public void visit(ClassInfo info);
+ public void visit(MethodInfo info);
+ public void visit(FieldInfo info);
+ public void visit(PackageInfo info);
+ public void visit(AnnotationInfo annotationInfo, Info info);
+}