Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up code

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1553012 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 5a597c2ebf415f48ace3ae5f285cc368662c6892 1 parent 167e741
@krosenvold krosenvold authored
View
100 ...er/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DefaultClassVisitor.java
@@ -23,13 +23,11 @@
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
-import java.util.HashSet;
-import java.util.Set;
/**
* Computes the set of classes referenced by visited code.
* Inspired by <code>org.objectweb.asm.depend.DependencyVisitor</code> in the ASM dependencies example.
- *
+ *
* @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
* @version $Id$
*/
@@ -37,7 +35,7 @@
{
// fields -----------------------------------------------------------------
- private final ResultCollector classes;
+ private final ResultCollector resultCollector;
private final SignatureVisitor signatureVisitor;
@@ -56,7 +54,7 @@ public DefaultClassVisitor(SignatureVisitor signatureVisitor, AnnotationVisitor
this.annotationVisitor = annotationVisitor;
this.fieldVisitor = fieldVisitor;
this.methodVisitor = methodVisitor;
- this.classes = resultCollector;
+ this.resultCollector = resultCollector;
}
public void visit( final int version, final int access, final String name, final String signature,
@@ -64,8 +62,8 @@ public void visit( final int version, final int access, final String name, final
{
if ( signature == null )
{
- addName( superName );
- addNames( interfaces );
+ resultCollector.addName(superName);
+ resultCollector.addNames(interfaces);
}
else
{
@@ -73,57 +71,46 @@ public void visit( final int version, final int access, final String name, final
}
}
- /*
- * @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean)
- */
public AnnotationVisitor visitAnnotation( final String desc, final boolean visible )
{
- addDesc( desc );
+ resultCollector.addDesc(desc);
return annotationVisitor;
}
- /*
- * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String,
- * java.lang.Object)
- */
public FieldVisitor visitField( final int access, final String name, final String desc, final String signature,
final Object value )
{
if ( signature == null )
{
- addDesc( desc );
+ resultCollector.addDesc(desc);
}
else
{
- addTypeSignature( signature );
+ addTypeSignature(signature);
}
if ( value instanceof Type )
{
- addType( (Type) value );
+ resultCollector.addType((Type) value);
}
return fieldVisitor;
}
- /*
- * @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String, java.lang.String, java.lang.String,
- * java.lang.String[])
- */
public MethodVisitor visitMethod( final int access, final String name, final String desc, final String signature,
final String[] exceptions )
{
if ( signature == null )
{
- addMethodDesc( desc );
+ resultCollector.addMethodDesc(desc);
}
else
{
- addSignature( signature );
+ addSignature(signature);
}
- addNames( exceptions );
+ resultCollector.addNames( exceptions );
return methodVisitor;
}
@@ -131,69 +118,6 @@ public MethodVisitor visitMethod( final int access, final String name, final Str
// private methods --------------------------------------------------------
- private void addName( String name )
- {
- if ( name == null )
- {
- return;
- }
-
- // decode arrays
- if ( name.startsWith( "[L" ) && name.endsWith( ";" ) )
- {
- name = name.substring( 2, name.length() - 1 );
- }
-
- // decode internal representation
- name = name.replace( '/', '.' );
-
- classes.add( name );
- }
-
- private void addNames( final String[] names )
- {
- if ( names == null )
- {
- return;
- }
-
- for ( String name : names )
- {
- addName( name );
- }
- }
-
- private void addDesc( final String desc )
- {
- addType( Type.getType( desc ) );
- }
-
- private void addMethodDesc( final String desc )
- {
- addType( Type.getReturnType( desc ) );
-
- Type[] types = Type.getArgumentTypes( desc );
-
- for ( Type type : types )
- {
- addType( type );
- }
- }
-
- private void addType( final Type t )
- {
- switch ( t.getSort() )
- {
- case Type.ARRAY:
- addType( t.getElementType() );
- break;
-
- case Type.OBJECT:
- addName( t.getClassName().replace( '.', '/' ) );
- break;
- }
- }
-
private void addSignature( final String signature )
{
if ( signature != null )
View
44 ...alyzer/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollector.java
@@ -1,5 +1,24 @@
package org.apache.maven.shared.dependency.analyzer.asm;
+/*
+ * 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.
+ */
+
import org.objectweb.asm.Type;
import java.util.HashSet;
@@ -59,4 +78,29 @@ void addType(final Type t)
public void add(String name) {
classes.add( name);
}
+
+ void addNames(final String[] names)
+ {
+ if ( names == null )
+ {
+ return;
+ }
+
+ for ( String name : names )
+ {
+ addName(name);
+ }
+ }
+
+ void addMethodDesc(final String desc)
+ {
+ addType(Type.getReturnType(desc));
+
+ Type[] types = Type.getArgumentTypes( desc );
+
+ for ( Type type : types )
+ {
+ addType(type);
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.