Formatting cleanup and fixed javadocs.
This commit is contained in:
parent
ce9be291d3
commit
93d0d324ab
|
@ -50,7 +50,6 @@ import org.objectweb.asm.FieldVisitor;
|
|||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
|
||||
/**
|
||||
* AnnotationParser
|
||||
* <p>
|
||||
|
@ -96,8 +95,7 @@ public class AnnotationParser
|
|||
JVM_MAJOR_VER = Integer.parseInt(jvmSpecVer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convert internal name to simple name
|
||||
*
|
||||
|
@ -135,12 +133,8 @@ public class AnnotationParser
|
|||
return normalList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ClassInfo
|
||||
*
|
||||
* Immutable information gathered by parsing class header.
|
||||
*
|
||||
*/
|
||||
public class ClassInfo
|
||||
{
|
||||
|
@ -200,10 +194,7 @@ public class AnnotationParser
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MethodInfo
|
||||
*
|
||||
* Immutable information gathered by parsing a method on a class.
|
||||
*/
|
||||
public class MethodInfo
|
||||
|
@ -256,14 +247,9 @@ public class AnnotationParser
|
|||
return _exceptions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* FieldInfo
|
||||
*
|
||||
* Immutable information gathered by parsing a field on a class.
|
||||
*
|
||||
*/
|
||||
public class FieldInfo
|
||||
{
|
||||
|
@ -317,8 +303,6 @@ public class AnnotationParser
|
|||
}
|
||||
|
||||
/**
|
||||
* Handler
|
||||
*
|
||||
* Signature for all handlers that respond to parsing class files.
|
||||
*/
|
||||
public static interface Handler
|
||||
|
@ -332,13 +316,10 @@ public class AnnotationParser
|
|||
}
|
||||
|
||||
/**
|
||||
* AbstractHandler
|
||||
*
|
||||
* Convenience base class to provide no-ops for all Handler methods.
|
||||
*/
|
||||
public static abstract class AbstractHandler implements Handler
|
||||
{
|
||||
|
||||
@Override
|
||||
public void handle(ClassInfo classInfo)
|
||||
{
|
||||
|
@ -372,15 +353,11 @@ public class AnnotationParser
|
|||
@Override
|
||||
public void handle(FieldInfo info, String annotationName)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* MyMethodVisitor
|
||||
*
|
||||
* ASM Visitor for parsing a method. We are only interested in the annotations on methods.
|
||||
*/
|
||||
public class MyMethodVisitor extends MethodVisitor
|
||||
|
@ -401,11 +378,8 @@ public class AnnotationParser
|
|||
_mi = new MethodInfo(classInfo, name, access, methodDesc,signature, exceptions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We are only interested in finding the annotations on methods.
|
||||
*
|
||||
* @see org.objectweb.asm.MethodVisitor#visitAnnotation(java.lang.String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String desc, boolean visible)
|
||||
|
@ -417,21 +391,15 @@ public class AnnotationParser
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* MyFieldVisitor
|
||||
*
|
||||
* An ASM visitor for parsing Fields.
|
||||
* An ASM visitor for parsing Fields.
|
||||
* We are only interested in visiting annotations on Fields.
|
||||
*
|
||||
*/
|
||||
public class MyFieldVisitor extends FieldVisitor
|
||||
{
|
||||
final FieldInfo _fieldInfo;
|
||||
final Set<? extends Handler> _handlers;
|
||||
|
||||
|
||||
|
||||
public MyFieldVisitor(final Set<? extends Handler> handlers,
|
||||
final ClassInfo classInfo,
|
||||
final int access,
|
||||
|
@ -445,11 +413,8 @@ public class AnnotationParser
|
|||
_fieldInfo = new FieldInfo(classInfo, fieldName, access, fieldType, signature, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse an annotation found on a Field.
|
||||
*
|
||||
* @see org.objectweb.asm.FieldVisitor#visitAnnotation(java.lang.String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String desc, boolean visible)
|
||||
|
@ -462,17 +427,11 @@ public class AnnotationParser
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* MyClassVisitor
|
||||
*
|
||||
* ASM visitor for a class.
|
||||
*/
|
||||
public class MyClassVisitor extends ClassVisitor
|
||||
{
|
||||
|
||||
final Resource _containingResource;
|
||||
final Set<? extends Handler> _handlers;
|
||||
ClassInfo _ci;
|
||||
|
@ -484,7 +443,6 @@ public class AnnotationParser
|
|||
_containingResource = containingResource;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit (final int version,
|
||||
final int access,
|
||||
|
@ -497,12 +455,9 @@ public class AnnotationParser
|
|||
for (Handler h:_handlers)
|
||||
h.handle(_ci);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Visit an annotation on a Class
|
||||
*
|
||||
* @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation (String desc, boolean visible)
|
||||
|
@ -510,15 +465,11 @@ public class AnnotationParser
|
|||
String annotationName = normalize(desc);
|
||||
for (Handler h : _handlers)
|
||||
h.handle(_ci, annotationName);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Visit a method to extract its annotations
|
||||
*
|
||||
* @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public MethodVisitor visitMethod (final int access,
|
||||
|
@ -527,14 +478,11 @@ public class AnnotationParser
|
|||
final String signature,
|
||||
final String[] exceptions)
|
||||
{
|
||||
|
||||
return new MyMethodVisitor(_handlers, _ci, access, name, methodDesc, signature, exceptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit a field to extract its annotations
|
||||
*
|
||||
* @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public FieldVisitor visitField (final int access,
|
||||
|
@ -547,7 +495,6 @@ public class AnnotationParser
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a class as having been parsed.
|
||||
*
|
||||
|
@ -567,9 +514,6 @@ public class AnnotationParser
|
|||
LOG.warn("{} scanned from multiple locations: {}", classname, existing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the locations of the given classname. There may be more than one
|
||||
|
@ -586,7 +530,6 @@ public class AnnotationParser
|
|||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse a given class
|
||||
*
|
||||
|
@ -594,8 +537,7 @@ public class AnnotationParser
|
|||
* @param className the class name to parse
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
public void parse (Set<? extends Handler> handlers, String className)
|
||||
throws Exception
|
||||
public void parse (Set<? extends Handler> handlers, String className) throws Exception
|
||||
{
|
||||
if (className == null)
|
||||
return;
|
||||
|
@ -614,8 +556,6 @@ public class AnnotationParser
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse the given class, optionally walking its inheritance hierarchy
|
||||
*
|
||||
|
@ -624,8 +564,7 @@ public class AnnotationParser
|
|||
* @param visitSuperClasses if true, also visit super classes for parse
|
||||
* @throws Exception if unable to parse class
|
||||
*/
|
||||
public void parse (Set<? extends Handler> handlers, Class<?> clazz, boolean visitSuperClasses)
|
||||
throws Exception
|
||||
public void parse (Set<? extends Handler> handlers, Class<?> clazz, boolean visitSuperClasses) throws Exception
|
||||
{
|
||||
Class<?> cz = clazz;
|
||||
while (cz != Object.class)
|
||||
|
@ -649,8 +588,6 @@ public class AnnotationParser
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse the given classes
|
||||
*
|
||||
|
@ -658,8 +595,7 @@ public class AnnotationParser
|
|||
* @param classNames the class name
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
public void parse (Set<? extends Handler> handlers, String[] classNames)
|
||||
throws Exception
|
||||
public void parse (Set<? extends Handler> handlers, String[] classNames) throws Exception
|
||||
{
|
||||
if (classNames == null)
|
||||
return;
|
||||
|
@ -667,7 +603,6 @@ public class AnnotationParser
|
|||
parse(handlers, Arrays.asList(classNames));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the given classes
|
||||
*
|
||||
|
@ -675,8 +610,7 @@ public class AnnotationParser
|
|||
* @param classNames the class names
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
public void parse (Set<? extends Handler> handlers, List<String> classNames)
|
||||
throws Exception
|
||||
public void parse (Set<? extends Handler> handlers, List<String> classNames) throws Exception
|
||||
{
|
||||
MultiException me = new MultiException();
|
||||
|
||||
|
@ -705,30 +639,20 @@ public class AnnotationParser
|
|||
me.ifExceptionThrow();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse all classes in a directory
|
||||
*
|
||||
* @param handlers the set of handlers to look for classes in
|
||||
* @param dir the resource directory to look for classes
|
||||
* @param root the resource directory to look for classes
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Parse all classes in a directory
|
||||
*
|
||||
* @param handlers the set of handlers to look for classes in
|
||||
* @param dir the resource directory to look for classes
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
protected void parseDir (Set<? extends Handler> handlers, Resource root)
|
||||
throws Exception
|
||||
protected void parseDir (Set<? extends Handler> handlers, Resource root) throws Exception
|
||||
{
|
||||
if (!root.isDirectory() || !root.exists() || root.getName().startsWith("."))
|
||||
return;
|
||||
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning dir {}", root);};
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Scanning dir {}", root);
|
||||
|
||||
File rootFile = root.getFile();
|
||||
|
||||
|
@ -750,7 +674,8 @@ public class AnnotationParser
|
|||
|
||||
try
|
||||
{
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning class {}", r);};
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Scanning class {}", r);
|
||||
addParsedClass(str, r);
|
||||
try (InputStream is=r.getInputStream())
|
||||
{
|
||||
|
@ -772,8 +697,6 @@ public class AnnotationParser
|
|||
|
||||
me.ifExceptionThrow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse classes in the supplied classloader.
|
||||
|
@ -785,8 +708,7 @@ public class AnnotationParser
|
|||
* @param nullInclusive if true, an empty pattern means all names match, if false, none match
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
public void parse (final Set<? extends Handler> handlers, ClassLoader loader, boolean visitParents, boolean nullInclusive)
|
||||
throws Exception
|
||||
public void parse (final Set<? extends Handler> handlers, ClassLoader loader, boolean visitParents, boolean nullInclusive) throws Exception
|
||||
{
|
||||
if (loader==null)
|
||||
return;
|
||||
|
@ -817,7 +739,6 @@ public class AnnotationParser
|
|||
me.ifExceptionThrow();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse classes in the supplied uris.
|
||||
*
|
||||
|
@ -825,8 +746,7 @@ public class AnnotationParser
|
|||
* @param uris the uris for the jars
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
public void parse (final Set<? extends Handler> handlers, final URI[] uris)
|
||||
throws Exception
|
||||
public void parse (final Set<? extends Handler> handlers, final URI[] uris) throws Exception
|
||||
{
|
||||
if (uris==null)
|
||||
return;
|
||||
|
@ -854,8 +774,7 @@ public class AnnotationParser
|
|||
* @param uri the uri for the jar
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
public void parse (final Set<? extends Handler> handlers, URI uri)
|
||||
throws Exception
|
||||
public void parse (final Set<? extends Handler> handlers, URI uri) throws Exception
|
||||
{
|
||||
if (uri == null)
|
||||
return;
|
||||
|
@ -863,7 +782,6 @@ public class AnnotationParser
|
|||
parse (handlers, Resource.newResource(uri));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse a resource
|
||||
*
|
||||
|
@ -871,8 +789,7 @@ public class AnnotationParser
|
|||
* @param r the resource to parse
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
public void parse (final Set<? extends Handler> handlers, Resource r)
|
||||
throws Exception
|
||||
public void parse (final Set<? extends Handler> handlers, Resource r) throws Exception
|
||||
{
|
||||
if (r == null)
|
||||
return;
|
||||
|
@ -902,9 +819,6 @@ public class AnnotationParser
|
|||
if (LOG.isDebugEnabled()) LOG.warn("Resource not scannable for classes: {}", r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse a resource that is a jar file.
|
||||
*
|
||||
|
@ -912,15 +826,15 @@ public class AnnotationParser
|
|||
* @param jarResource the jar resource to parse
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
protected void parseJar (Set<? extends Handler> handlers, Resource jarResource)
|
||||
throws Exception
|
||||
protected void parseJar (Set<? extends Handler> handlers, Resource jarResource) throws Exception
|
||||
{
|
||||
if (jarResource == null)
|
||||
return;
|
||||
|
||||
if (jarResource.toString().endsWith(".jar"))
|
||||
{
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning jar {}", jarResource);};
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Scanning jar {}", jarResource);
|
||||
|
||||
//treat it as a jar that we need to open and scan all entries from
|
||||
InputStream in = jarResource.getInputStream();
|
||||
|
@ -928,30 +842,25 @@ public class AnnotationParser
|
|||
return;
|
||||
|
||||
MultiException me = new MultiException();
|
||||
JarInputStream jar_in = new JarInputStream(in);
|
||||
try
|
||||
{
|
||||
try (JarInputStream jar_in = new JarInputStream(in))
|
||||
{
|
||||
JarEntry entry = jar_in.getNextJarEntry();
|
||||
while (entry!=null)
|
||||
{
|
||||
while (entry != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
parseJarEntry(handlers, jarResource, entry);
|
||||
parseJarEntry(handlers, jarResource, entry);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
me.add(new RuntimeException("Error scanning entry "+entry.getName()+" from jar "+jarResource, e));
|
||||
me.add(new RuntimeException("Error scanning entry " + entry.getName() + " from jar " + jarResource, e));
|
||||
}
|
||||
entry = jar_in.getNextJarEntry();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
me.add(new RuntimeException("Error scanning jar "+jarResource, e));
|
||||
}
|
||||
finally
|
||||
{
|
||||
jar_in.close();
|
||||
me.add(new RuntimeException("Error scanning jar " + jarResource, e));
|
||||
}
|
||||
|
||||
me.ifExceptionThrow();
|
||||
|
@ -966,8 +875,7 @@ public class AnnotationParser
|
|||
* @param entry the entry in the jar resource to parse
|
||||
* @throws Exception if unable to parse
|
||||
*/
|
||||
protected void parseJarEntry (Set<? extends Handler> handlers, Resource jar, JarEntry entry)
|
||||
throws Exception
|
||||
protected void parseJarEntry (Set<? extends Handler> handlers, Resource jar, JarEntry entry) throws Exception
|
||||
{
|
||||
if (jar == null || entry == null)
|
||||
return;
|
||||
|
@ -984,17 +892,15 @@ public class AnnotationParser
|
|||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
Resource clazz = Resource.newResource("jar:"+jar.getURI()+"!/"+name);
|
||||
addParsedClass(shortName, clazz);
|
||||
if (LOG.isDebugEnabled()) {LOG.debug("Scanning class from jar {}", clazz);};
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Scanning class from jar {}", clazz);
|
||||
try (InputStream is = clazz.getInputStream())
|
||||
{
|
||||
scanClass(handlers, jar, is);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Use ASM on a class
|
||||
*
|
||||
|
@ -1003,8 +909,7 @@ public class AnnotationParser
|
|||
* @param is the input stream to parse
|
||||
* @throws IOException if unable to parse
|
||||
*/
|
||||
protected void scanClass (Set<? extends Handler> handlers, Resource containingResource, InputStream is)
|
||||
throws IOException
|
||||
protected void scanClass (Set<? extends Handler> handlers, Resource containingResource, InputStream is) throws IOException
|
||||
{
|
||||
ClassReader reader = new ClassReader(is);
|
||||
reader.accept(new MyClassVisitor(handlers, containingResource), ClassReader.SKIP_CODE|ClassReader.SKIP_DEBUG|ClassReader.SKIP_FRAMES);
|
||||
|
@ -1018,7 +923,6 @@ public class AnnotationParser
|
|||
_parsedClassNames.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that the given path represents a valid class file name.
|
||||
* The check is fairly cursory, checking that:
|
||||
|
@ -1027,8 +931,8 @@ public class AnnotationParser
|
|||
* <li> it isn't a dot file or in a hidden directory </li>
|
||||
* <li> the name of the class at least begins with a valid identifier for a class name </li>
|
||||
* </ul>
|
||||
* @param name
|
||||
* @return
|
||||
* @param name the class file name
|
||||
* @return whether the class file name is valid
|
||||
*/
|
||||
private boolean isValidClassFileName (String name)
|
||||
{
|
||||
|
@ -1062,13 +966,12 @@ public class AnnotationParser
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check that the given path does not contain hidden directories
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
* @param path the class file path
|
||||
* @return whether the class file path is valid
|
||||
*/
|
||||
private boolean isValidClassFilePath (String path)
|
||||
{
|
||||
|
@ -1137,4 +1040,3 @@ public class AnnotationParser
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue