Browse Source

refactoring

tags/V1_6_6
aclement 14 years ago
parent
commit
e7a87072d7

+ 25
- 24
bcel-builder/src/org/aspectj/apache/bcel/Repository.java View File

@@ -67,7 +67,7 @@ import org.aspectj.apache.bcel.util.SyntheticRepository;
* @see org.aspectj.apache.bcel.util.Repository
* @see org.aspectj.apache.bcel.util.SyntheticRepository
*
* @version $Id: Repository.java,v 1.5 2008/08/28 15:36:59 aclement Exp $
* @version $Id: Repository.java,v 1.6 2009/09/09 22:18:20 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class Repository {
@@ -166,29 +166,30 @@ public abstract class Repository {
// getRepository().removeClass(clazz);
// }

/**
* @return list of super classes of clazz in ascending order, i.e., Object is always the last element
*/
public static JavaClass[] getSuperClasses(JavaClass clazz) {
return clazz.getSuperClasses();
}

/**
* @return list of super classes of clazz in ascending order, i.e., Object is always the last element. return "null", if class
* cannot be found.
*/
public static JavaClass[] getSuperClasses(String class_name) {
JavaClass jc = lookupClass(class_name);
return jc == null ? null : getSuperClasses(jc);
}

/**
* @return all interfaces implemented by class and its super classes and the interfaces that those interfaces extend, and so on.
* (Some people call this a transitive hull).
*/
public static JavaClass[] getInterfaces(JavaClass clazz) {
return clazz.getAllInterfaces();
}
// /**
// * @return list of super classes of clazz in ascending order, i.e., Object is always the last element
// */
// public static JavaClass[] getSuperClasses(JavaClass clazz) {
// return clazz.getSuperClasses();
// }
//
// /**
// * @return list of super classes of clazz in ascending order, i.e., Object is always the last element. return "null", if class
// * cannot be found.
// */
// public static JavaClass[] getSuperClasses(String class_name) {
// JavaClass jc = lookupClass(class_name);
// return jc == null ? null : getSuperClasses(jc);
// }
//
// /**
// * @return all interfaces implemented by class and its super classes and the interfaces that those interfaces extend, and so
// on.
// * (Some people call this a transitive hull).
// */
// public static JavaClass[] getInterfaces(JavaClass clazz) {
// return clazz.getAllInterfaces();
// }

// /**
// * @return all interfaces implemented by class and its super classes and the interfaces that extend those interfaces, and so

+ 26
- 22
bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java View File

@@ -61,15 +61,16 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;

import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.apache.bcel.util.ClassQueue;
import org.aspectj.apache.bcel.util.ClassVector;
import org.aspectj.apache.bcel.util.SyntheticRepository;

/**
@@ -79,7 +80,7 @@ import org.aspectj.apache.bcel.util.SyntheticRepository;
* The intent of this class is to represent a parsed or otherwise existing class file. Those interested in programatically
* generating classes should see the <a href="../generic/ClassGen.html">ClassGen</a> class.
*
* @version $Id: JavaClass.java,v 1.16 2009/09/09 21:26:54 aclement Exp $
* @version $Id: JavaClass.java,v 1.17 2009/09/09 22:18:20 aclement Exp $
* @see org.aspectj.apache.bcel.generic.ClassGen
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
@@ -789,13 +790,18 @@ public class JavaClass extends Modifiers implements Cloneable, Node {
return true;
}

JavaClass[] super_interfaces = getAllInterfaces();
Collection<JavaClass> superInterfaces = getAllInterfaces();

for (int i = 0; i < super_interfaces.length; i++) {
if (super_interfaces[i].equals(inter)) {
for (JavaClass superInterface : superInterfaces) {
if (superInterface.equals(inter)) {
return true;
}
}
// for (int i = 0; i < super_interfaces.length; i++) {
// if (super_interfaces[i].equals(inter)) {
// return true;
// }
// }

return false;
}
@@ -821,13 +827,11 @@ public class JavaClass extends Modifiers implements Cloneable, Node {
*/
public JavaClass[] getSuperClasses() {
JavaClass clazz = this;
ClassVector vec = new ClassVector();

List<JavaClass> vec = new ArrayList<JavaClass>();
for (clazz = clazz.getSuperClass(); clazz != null; clazz = clazz.getSuperClass()) {
vec.addElement(clazz);
vec.add(clazz);
}

return vec.toArray();
return vec.toArray(new JavaClass[vec.size()]);
}

/**
@@ -852,33 +856,33 @@ public class JavaClass extends Modifiers implements Cloneable, Node {
/**
* Get all interfaces implemented by this JavaClass (transitively).
*/
// OPTIMIZE get rid of ClassQueue and ClassVector
public JavaClass[] getAllInterfaces() {
ClassQueue queue = new ClassQueue();
ClassVector vec = new ClassVector();
public Collection<JavaClass> getAllInterfaces() {
Queue<JavaClass> queue = new LinkedList<JavaClass>();
List<JavaClass> interfaceList = new ArrayList<JavaClass>();

queue.enqueue(this);
queue.add(this);

while (!queue.empty()) {
JavaClass clazz = queue.dequeue();
while (!queue.isEmpty()) {
JavaClass clazz = queue.remove();

JavaClass souper = clazz.getSuperClass();
JavaClass[] interfaces = clazz.getInterfaces();

if (clazz.isInterface()) {
vec.addElement(clazz);
interfaceList.add(clazz);
} else {
if (souper != null) {
queue.enqueue(souper);
queue.add(souper);
}
}

for (int i = 0; i < interfaces.length; i++) {
queue.enqueue(interfaces[i]);
queue.add(interfaces[i]);
}
}

return vec.toArray();
return interfaceList;
// return interfaceList.toArray(new JavaClass[interfaceList.size()]);
}

/**

+ 1008
- 954
bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java
File diff suppressed because it is too large
View File


+ 652
- 597
bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGen.java
File diff suppressed because it is too large
View File


+ 16
- 14
bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java View File

@@ -55,27 +55,28 @@ package org.aspectj.apache.bcel.generic;
*/

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.aspectj.apache.bcel.classfile.Modifiers;
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.Modifiers;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;

/**
* Super class for FieldGen and MethodGen objects, since they have some methods
* in common!
* Super class for FieldGen and MethodGen objects, since they have some methods in common!
*
* @version $Id: FieldGenOrMethodGen.java,v 1.5 2009/09/09 19:56:20 aclement Exp $
* @version $Id: FieldGenOrMethodGen.java,v 1.6 2009/09/09 22:18:20 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable {
protected String name;
protected Type type;
protected ConstantPool cp;
private ArrayList/*<Attribute>*/<Attribute> attributeList = new ArrayList<Attribute>();
private ArrayList/* <Attribute> */<Attribute> attributeList = new ArrayList<Attribute>();
private ArrayList<AnnotationGen> annotationList = new ArrayList<AnnotationGen>();

protected FieldGenOrMethodGen() {
@@ -129,10 +130,10 @@ public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable
annotationList.clear();
}

public List/*<Attribute>*/<Attribute> getAttributes() {
public List/* <Attribute> */<Attribute> getAttributes() {
return attributeList;
}
public Attribute[] getAttributesImmutable() {
Attribute[] attributes = new Attribute[attributeList.size()];
attributeList.toArray(attributes);
@@ -140,12 +141,12 @@ public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable
}

protected void addAnnotationsAsAttribute(ConstantPool cp) {
Attribute[] attrs = Utility.getAnnotationAttributes(cp,annotationList);
if (attrs!=null) {
for (int i = 0; i < attrs.length; i++) {
addAttribute(attrs[i]);
}
}
Collection<RuntimeAnnotations> attrs = Utility.getAnnotationAttributes(cp, annotationList);
if (attrs != null) {
for (Attribute attr : attrs) {
addAttribute(attr);
}
}
}

public AnnotationGen[] getAnnotations() {
@@ -157,6 +158,7 @@ public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable
public abstract String getSignature();

// OPTIMIZE clone any use???
@Override
public Object clone() {
try {
return super.clone();

+ 3
- 3
bcel-builder/src/org/aspectj/apache/bcel/generic/ReferenceType.java View File

@@ -61,7 +61,7 @@ import org.aspectj.apache.bcel.classfile.JavaClass;
/**
* Super class for object and array types.
*
* @version $Id: ReferenceType.java,v 1.5 2008/08/28 15:36:59 aclement Exp $
* @version $Id: ReferenceType.java,v 1.6 2009/09/09 22:18:20 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class ReferenceType extends Type {
@@ -265,8 +265,8 @@ public abstract class ReferenceType extends Type {
// this and t are ObjectTypes, see above.
ObjectType thiz = (ObjectType) this;
ObjectType other = (ObjectType) t;
JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());
JavaClass[] thiz_sups = Repository.lookupClass(thiz.getClassName()).getSuperClasses();// getSuperClasses(thiz.getClassName());
JavaClass[] other_sups = Repository.lookupClass(other.getClassName()).getSuperClasses();// getSuperClasses(other.getClassName());

if (thiz_sups == null || other_sups == null) {
return null;

+ 0
- 81
bcel-builder/src/org/aspectj/apache/bcel/util/ClassQueue.java View File

@@ -1,81 +0,0 @@
package org.aspectj.apache.bcel.util;

/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache BCEL" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache BCEL", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.LinkedList;
import org.aspectj.apache.bcel.classfile.JavaClass;

/**
* Utility class implementing a (typesafe) queue of JavaClass
* objects.
*
* @version $Id: ClassQueue.java,v 1.4 2009/09/09 19:56:20 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see ClassVector
*/
public class ClassQueue implements java.io.Serializable {
protected LinkedList<JavaClass> vec = new LinkedList<JavaClass>();

public void enqueue(JavaClass clazz) { vec.addLast(clazz); }

public JavaClass dequeue() {
return vec.removeFirst();
}

public boolean empty() { return vec.isEmpty(); }

public String toString() {
return vec.toString();
}
}

+ 0
- 79
bcel-builder/src/org/aspectj/apache/bcel/util/ClassVector.java View File

@@ -1,79 +0,0 @@
package org.aspectj.apache.bcel.util;

/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache BCEL" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache BCEL", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.ArrayList;
import org.aspectj.apache.bcel.classfile.JavaClass;

/**
* Utility class implementing a (typesafe) collection of JavaClass
* objects. Contains the most important methods of a Vector.
*
* @version $Id: ClassVector.java,v 1.4 2009/09/09 19:56:20 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see ClassQueue
*/
public class ClassVector implements java.io.Serializable {
protected ArrayList<JavaClass> vec = new ArrayList<JavaClass>();
public void addElement(JavaClass clazz) { vec.add(clazz); }
public JavaClass elementAt(int index) { return vec.get(index); }
public void removeElementAt(int index) { vec.remove(index); }

public JavaClass[] toArray() {
JavaClass[] classes = new JavaClass[vec.size()];
vec.toArray(classes);
return classes;
}
}

Loading…
Cancel
Save