@@ -1,5 +1,6 @@ | |||
Manifest-Version: 1.0 | |||
Main-Class: org.aspectj.tools.ajbrowser.Main | |||
Automatic-Module-Name: org.aspectj.tools | |||
Name: org/aspectj/tools/ | |||
Specification-Title: AspectJ Tools Classes |
@@ -124,4 +124,14 @@ public class BrowserCompilerConfiguration implements ICompilerConfiguration { | |||
return null; | |||
} | |||
@Override | |||
public String getModulepath() { | |||
return null; | |||
} | |||
@Override | |||
public String getModuleSourcepath() { | |||
return null; | |||
} | |||
} |
@@ -61,10 +61,11 @@ public interface ICompilerConfiguration extends CompilerConfigurationChangeFlags | |||
*/ | |||
public List<File> getProjectSourceFilesChanged(); | |||
/** | |||
* @return the classpath to use | |||
*/ | |||
public String getClasspath(); | |||
public String getModulepath(); | |||
public String getModuleSourcepath(); | |||
/** | |||
* @return the IOutputLocationManager associated with this compiler configuration |
@@ -37,6 +37,7 @@ import org.aspectj.bridge.ISourceLocation; | |||
import org.aspectj.bridge.Message; | |||
import org.aspectj.bridge.SourceLocation; | |||
import org.aspectj.bridge.context.CompilationAndWeavingContext; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions; | |||
import org.aspectj.util.LangUtil; | |||
@@ -277,6 +278,14 @@ public class AjdeCoreBuildManager { | |||
both.addAll(configClasspath); | |||
both.addAll(toAdd); | |||
config.setClasspath(both); | |||
Classpath[] checkedClasspaths = config.getCheckedClasspaths(); | |||
ArrayList<Classpath> cps = parser.handleClasspath(toAdd, compilerConfig.getProjectEncoding()); | |||
Classpath[] newCheckedClasspaths = new Classpath[checkedClasspaths.length+cps.size()]; | |||
System.arraycopy(checkedClasspaths, 0, newCheckedClasspaths, 0, checkedClasspaths.length); | |||
for (int i=0;i<cps.size();i++) { | |||
newCheckedClasspaths[checkedClasspaths.length+i] = cps.get(i); | |||
} | |||
config.setCheckedClasspaths(newCheckedClasspaths); | |||
} | |||
} | |||
@@ -295,18 +304,18 @@ public class AjdeCoreBuildManager { | |||
} | |||
// Process the INPATH | |||
mergeInto(config.getInpath(), compilerConfig.getInpath()); | |||
config.addToInpath(compilerConfig.getInpath()); | |||
// bug 168840 - calling 'setInPath(..)' creates BinarySourceFiles which | |||
// are used to see if there have been changes in classes on the inpath | |||
if (config.getInpath() != null) { | |||
config.setInPath(config.getInpath()); | |||
config.processInPath(); | |||
} | |||
// Process the SOURCE PATH RESOURCES | |||
config.setSourcePathResources(compilerConfig.getSourcePathResources()); | |||
// Process the ASPECTPATH | |||
mergeInto(config.getAspectpath(), compilerConfig.getAspectPath()); | |||
config.addToAspectpath(compilerConfig.getAspectPath()); | |||
// Process the JAVA OPTIONS MAP | |||
Map<String,String> jom = compilerConfig.getJavaOptionsMap(); | |||
@@ -347,17 +356,6 @@ public class AjdeCoreBuildManager { | |||
return config; | |||
} | |||
private <T> void mergeInto(Collection<T> target, Collection<T> source) { | |||
if ((null == target) || (null == source)) { | |||
return; | |||
} | |||
for (T next : source) { | |||
if (!target.contains(next)) { | |||
target.add(next); | |||
} | |||
} | |||
} | |||
/** | |||
* Helper method for configure build options. This reads all command-line options specified in the non-standard options text | |||
* entry and sets any corresponding unset values in config. |
@@ -22,6 +22,7 @@ import java.util.Set; | |||
import org.aspectj.tools.ajc.AjcTests; | |||
import org.aspectj.util.FileUtil; | |||
import org.aspectj.util.LangUtil; | |||
/** | |||
* Test implementation of ICompilerConfiguration. Allows users to configure the settings via setter methods. By default returns null | |||
@@ -58,8 +59,15 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
} | |||
public String getClasspath() { | |||
return projectPath + File.pathSeparator + System.getProperty("sun.boot.class.path") + File.pathSeparator | |||
+ AjcTests.aspectjrtClasspath(); | |||
StringBuilder classpath = new StringBuilder(); | |||
classpath.append(projectPath); | |||
if (LangUtil.is19VMOrGreater()) { | |||
classpath.append(File.pathSeparator).append(LangUtil.getJrtFsFilePath()); | |||
} else { | |||
classpath.append(File.pathSeparator).append(System.getProperty("sun.boot.class.path")); | |||
} | |||
classpath.append(File.pathSeparator).append(AjcTests.aspectjrtClasspath()); | |||
return classpath.toString(); | |||
} | |||
public Set<File> getInpath() { | |||
@@ -179,4 +187,14 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
return null; | |||
} | |||
@Override | |||
public String getModulepath() { | |||
return null; | |||
} | |||
@Override | |||
public String getModuleSourcepath() { | |||
return null; | |||
} | |||
} |
@@ -25,6 +25,7 @@ import org.aspectj.ajde.core.IOutputLocationManager; | |||
import org.aspectj.ajde.core.JavaOptions; | |||
import org.aspectj.tools.ajc.AjcTests; | |||
import org.aspectj.util.FileUtil; | |||
import org.aspectj.util.LangUtil; | |||
/** | |||
* Test implementation of ICompilerConfiguration. Allows users to configure the settings via setter methods. By default returns null | |||
@@ -64,8 +65,12 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
} | |||
public String getClasspath() { | |||
return projectPath + File.pathSeparator + System.getProperty("sun.boot.class.path") + File.pathSeparator | |||
String cp = projectPath + File.pathSeparator + System.getProperty("sun.boot.class.path") + File.pathSeparator | |||
+ AjcTests.aspectjrtClasspath(); | |||
if (LangUtil.is19VMOrGreater()) { | |||
cp = LangUtil.getJrtFsFilePath()+File.pathSeparator+cp; | |||
} | |||
return cp; | |||
} | |||
public Set getInpath() { | |||
@@ -184,4 +189,14 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
return null; | |||
} | |||
@Override | |||
public String getModulepath() { | |||
return null; | |||
} | |||
@Override | |||
public String getModuleSourcepath() { | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
eclipse.preferences.version=1 | |||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | |||
org.eclipse.jdt.core.compiler.compliance=1.7 | |||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | |||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | |||
org.eclipse.jdt.core.compiler.source=1.7 |
@@ -1,5 +1,6 @@ | |||
Manifest-Version: 1.0 | |||
Main-Class: org.aspectj.tools.ajdoc.Main | |||
Automatic-Module-Name: org.aspectj.tools | |||
Name: org/aspectj/tools/ | |||
Specification-Title: AspectJ Tools Classes |
@@ -48,7 +48,7 @@ class HtmlDecorator { | |||
private static final String ITD_FIELD_SUMMARY = "Inter-Type Field Summary"; | |||
private static final String ITD_CONSTRUCTOR_SUMMARY = "Inter-Type Constructor Summary"; | |||
static List visibleFileList = new ArrayList(); | |||
static List<String> visibleFileList = new ArrayList<String>(); | |||
static Hashtable declIDTable = null; | |||
static File rootDir = null; | |||
static String docVisibilityModifier; | |||
@@ -291,22 +291,22 @@ class HtmlDecorator { | |||
} | |||
static void addAspectDocumentation(IProgramElement node, StringBuffer fileBuffer, int index) { | |||
List pointcuts = new ArrayList(); | |||
List advice = new ArrayList(); | |||
List declares = new ArrayList(); | |||
List methodsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_METHOD); | |||
List<IProgramElement> pointcuts = new ArrayList<IProgramElement>(); | |||
List<IProgramElement> advice = new ArrayList<IProgramElement>(); | |||
List<IProgramElement> declares = new ArrayList<IProgramElement>(); | |||
List<IProgramElement> methodsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_METHOD); | |||
if (methodsDeclaredOn != null && !methodsDeclaredOn.isEmpty()) { | |||
insertDeclarationsSummary(fileBuffer, methodsDeclaredOn, ITD_METHOD_SUMMARY, index); | |||
} | |||
List fieldsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_FIELD); | |||
List<IProgramElement> fieldsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_FIELD); | |||
if (fieldsDeclaredOn != null && !fieldsDeclaredOn.isEmpty()) { | |||
insertDeclarationsSummary(fileBuffer, fieldsDeclaredOn, ITD_FIELD_SUMMARY, index); | |||
} | |||
List constDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); | |||
List<IProgramElement> constDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); | |||
if (fieldsDeclaredOn != null && !constDeclaredOn.isEmpty()) { | |||
insertDeclarationsSummary(fileBuffer, constDeclaredOn, ITD_CONSTRUCTOR_SUMMARY, index); | |||
} | |||
for (Iterator it = node.getChildren().iterator(); it.hasNext();) { | |||
for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) { | |||
IProgramElement member = (IProgramElement) it.next(); | |||
if (member.getKind().equals(IProgramElement.Kind.POINTCUT)) { | |||
pointcuts.add(member); | |||
@@ -329,17 +329,17 @@ class HtmlDecorator { | |||
insertDeclarationsDetails(fileBuffer, advice, ADVICE_DETAIL, index); | |||
} | |||
// add the 'aspect declarations' information against the type | |||
List parentsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.DECLARE_PARENTS); | |||
List<IProgramElement> parentsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.DECLARE_PARENTS); | |||
if (parentsDeclaredOn != null && parentsDeclaredOn.size() > 0) { | |||
decorateDocWithRel(node, fileBuffer, index, parentsDeclaredOn, HtmlRelationshipKind.ASPECT_DECLARATIONS); | |||
} | |||
// add the 'annotated by' information against the type | |||
List annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); | |||
List<String> annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); | |||
if (annotatedBy != null && annotatedBy.size() > 0) { | |||
decorateDocWithRel(node, fileBuffer, index, annotatedBy, HtmlRelationshipKind.ANNOTATED_BY); | |||
} | |||
// add the 'advised by' information against the type | |||
List advisedBy = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); | |||
List<String> advisedBy = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); | |||
if (advisedBy != null && advisedBy.size() > 0) { | |||
decorateDocWithRel(node, fileBuffer, index, advisedBy, HtmlRelationshipKind.ADVISED_BY); | |||
} | |||
@@ -621,16 +621,16 @@ class HtmlDecorator { | |||
} | |||
static void decorateMemberDocumentation(IProgramElement node, StringBuffer fileContentsBuffer, int index) { | |||
List targets = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); | |||
List<String> targets = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); | |||
decorateDocWithRel(node, fileContentsBuffer, index, targets, HtmlRelationshipKind.ADVISED_BY); | |||
List warnings = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "matches declare"); | |||
List<String> warnings = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "matches declare"); | |||
decorateDocWithRel(node, fileContentsBuffer, index, warnings, HtmlRelationshipKind.MATCHES_DECLARE); | |||
List softenedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "softened by"); | |||
List<String> softenedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "softened by"); | |||
decorateDocWithRel(node, fileContentsBuffer, index, softenedBy, HtmlRelationshipKind.SOFTENED_BY); | |||
List annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); | |||
List<String> annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); | |||
decorateDocWithRel(node, fileContentsBuffer, index, annotatedBy, HtmlRelationshipKind.ANNOTATED_BY); | |||
} | |||
@@ -14,9 +14,12 @@ | |||
package org.aspectj.tools.ajdoc; | |||
import java.io.IOException; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.lang.reflect.Method; | |||
import org.aspectj.util.LangUtil; | |||
/** | |||
* @author Mik Kersten | |||
*/ | |||
@@ -62,7 +65,12 @@ class JavadocRunner { | |||
// defaultSecurityManager.checkPermission( permission, context ); | |||
// } | |||
// } ); | |||
// Need to do something different on Java > 9 due to removal of standard doclet I think | |||
// if (LangUtil.is19VMOrGreater()) { | |||
// // Not visible according to module rules... | |||
// clazz = Class.forName("jdk.javadoc.internal.tool.Main"); | |||
// } | |||
try { | |||
// for JDK 1.4 and above call the execute method... | |||
Class jdMainClass = com.sun.tools.javadoc.Main.class; |
@@ -47,24 +47,24 @@ public class Main implements Config { | |||
private static final String FAIL_MESSAGE = "> compile failed, exiting ajdoc"; | |||
/** Command line options. */ | |||
static Vector options; | |||
static Vector<String> options; | |||
/** Options to pass to ajc. */ | |||
static Vector ajcOptions; | |||
static Vector<String> ajcOptions; | |||
/** All of the files to be processed by ajdoc. */ | |||
static Vector filenames; | |||
static Vector<String> filenames; | |||
/** List of files to pass to javadoc. */ | |||
static Vector fileList; | |||
static Vector<String> fileList; | |||
/** List of packages to pass to javadoc. */ | |||
static Vector packageList; | |||
static Vector<String> packageList; | |||
/** Default to package visiblity. */ | |||
static String docModifier = "package"; | |||
static Vector sourcepath; | |||
static Vector<String> sourcepath; | |||
static boolean verboseMode = false; | |||
static boolean packageMode = false; | |||
@@ -85,13 +85,13 @@ public class Main implements Config { | |||
private static String outputWorkingDir = Config.WORKING_DIR; | |||
public static void clearState() { | |||
options = new Vector(); | |||
ajcOptions = new Vector(); | |||
filenames = new Vector(); | |||
fileList = new Vector(); | |||
packageList = new Vector(); | |||
options = new Vector<String>(); | |||
ajcOptions = new Vector<String>(); | |||
filenames = new Vector<String>(); | |||
fileList = new Vector<String>(); | |||
packageList = new Vector<String>(); | |||
docModifier = "package"; | |||
sourcepath = new Vector(); | |||
sourcepath = new Vector<String>(); | |||
verboseMode = false; | |||
packageMode = false; | |||
rootDir = null; | |||
@@ -169,7 +169,7 @@ public class Main implements Config { | |||
* package-summary properly. | |||
*/ | |||
private static void packageHTML(AsmManager model, File[] inputFiles) throws IOException { | |||
ArrayList dirList = new ArrayList(); | |||
ArrayList<String> dirList = new ArrayList<String>(); | |||
for (int i = 0; i < inputFiles.length; i++) { | |||
String packageName = StructureUtil.getPackageDeclarationFromFile(model, inputFiles[i]); | |||
// Only copy the package.html file once. | |||
@@ -192,7 +192,7 @@ public class Main implements Config { | |||
String pathName = outputWorkingDir + File.separator + packageName.replace('.', File.separatorChar); | |||
File packageDir = new File(pathName); | |||
if (!packageDir.exists()) { | |||
dirList.add(packageDir); | |||
dirList.add(packageName); | |||
continue; | |||
} | |||
packageName = packageName.replace('.', '/'); // !!! | |||
@@ -273,7 +273,6 @@ public class Main implements Config { | |||
javadocargs[options.size() + k] = StructureUtil.translateAjPathName(signatureFiles[k].getCanonicalPath()); | |||
} | |||
} | |||
JavadocRunner.callJavadoc(javadocargs); | |||
} | |||
@@ -345,8 +344,8 @@ public class Main implements Config { | |||
} | |||
} | |||
static Vector getSourcePath() { | |||
Vector sourcePath = new Vector(); | |||
static Vector<String> getSourcePath() { | |||
Vector<String> sourcePath = new Vector<String>(); | |||
boolean found = false; | |||
for (int i = 0; i < options.size(); i++) { | |||
String currOption = (String) options.elementAt(i); | |||
@@ -455,14 +454,14 @@ public class Main implements Config { | |||
String line = ""; | |||
line = br.readLine(); | |||
StringTokenizer st = new StringTokenizer(line, " "); | |||
List argList = new ArrayList(); | |||
List<String> argList = new ArrayList<String>(); | |||
while (st.hasMoreElements()) { | |||
argList.add(st.nextElement()); | |||
argList.add(st.nextToken()); | |||
} | |||
// System.err.println(argList); | |||
args = new String[argList.size()]; | |||
int counter = 0; | |||
for (Iterator it = argList.iterator(); it.hasNext();) { | |||
for (Iterator<String> it = argList.iterator(); it.hasNext();) { | |||
args[counter] = (String) it.next(); | |||
counter++; | |||
} | |||
@@ -474,7 +473,7 @@ public class Main implements Config { | |||
ioe.printStackTrace(); | |||
} | |||
} | |||
List vargs = new LinkedList(Arrays.asList(args)); | |||
List<String> vargs = new LinkedList<String>(Arrays.asList(args)); | |||
vargs.add("-Xset:minimalModel=false"); | |||
parseArgs(vargs, new File(".")); // !!! | |||
@@ -488,7 +487,7 @@ public class Main implements Config { | |||
arg = arg + File.pathSeparator; // makes things easier for ourselves | |||
StringTokenizer tokenizer = new StringTokenizer(arg, File.pathSeparator); | |||
while (tokenizer.hasMoreElements()) { | |||
sourcepath.addElement(tokenizer.nextElement()); | |||
sourcepath.addElement(tokenizer.nextToken()); | |||
} | |||
} | |||
@@ -705,7 +704,7 @@ public class Main implements Config { | |||
} | |||
static void expandAtSignFile(String filename, File currentWorkingDir) { | |||
List result = new LinkedList(); | |||
List<String> result = new LinkedList<String>(); | |||
File atFile = qualifiedFile(filename, currentWorkingDir); | |||
String atFileParent = atFile.getParent(); | |||
@@ -730,6 +729,7 @@ public class Main implements Config { | |||
continue; | |||
result.add(line); | |||
} | |||
stream.close(); | |||
} catch (IOException e) { | |||
System.err.println("Error while reading the @ file " + atFile.getPath() + ".\n" + e); | |||
System.exit(-1); |
@@ -31,7 +31,7 @@ public class StructureUtil { | |||
* | |||
* @return null if a relationship of that kind is not found | |||
*/ | |||
public static List /* String */getTargets(IProgramElement node, IRelationship.Kind kind) { | |||
public static List<String> getTargets(IProgramElement node, IRelationship.Kind kind) { | |||
return getTargets(node, kind, null); | |||
} | |||
@@ -41,21 +41,21 @@ public class StructureUtil { | |||
* | |||
* @return null if a relationship of that kind is not found | |||
*/ | |||
public static List /* String */getTargets(IProgramElement node, IRelationship.Kind kind, String relName) { | |||
List relations = new ArrayList(); | |||
List rels = node.getModel().getRelationshipMap().get(node); | |||
public static List<String> getTargets(IProgramElement node, IRelationship.Kind kind, String relName) { | |||
List<IRelationship> relations = new ArrayList<IRelationship>(); | |||
List<IRelationship> rels = node.getModel().getRelationshipMap().get(node); | |||
if (rels != null) { | |||
relations.addAll(rels); | |||
} | |||
for (Iterator iter = node.getChildren().iterator(); iter.hasNext();) { | |||
for (Iterator<IProgramElement> iter = node.getChildren().iterator(); iter.hasNext();) { | |||
IProgramElement child = (IProgramElement) iter.next(); | |||
// if we're not a type, or if we are and the child is code, then | |||
// we want to get the relationships for this child - this means that the | |||
// correct relationships appear against the type in the ajdoc | |||
if (!node.getKind().isType() || child.getKind().equals(IProgramElement.Kind.CODE)) { | |||
List childRelations = node.getModel().getRelationshipMap().get(child); | |||
List<IRelationship> childRelations = node.getModel().getRelationshipMap().get(child); | |||
if (childRelations != null) { | |||
for (Iterator iterator = childRelations.iterator(); iterator.hasNext();) { | |||
for (Iterator<IRelationship> iterator = childRelations.iterator(); iterator.hasNext();) { | |||
IRelationship rel = (IRelationship) iterator.next(); | |||
if (!relations.contains(rel)) { | |||
relations.add(rel); | |||
@@ -66,13 +66,12 @@ public class StructureUtil { | |||
} | |||
if (relations == null || relations.isEmpty()) | |||
return null; | |||
List targets = new ArrayList(); | |||
for (Iterator it = relations.iterator(); it.hasNext();) { | |||
List<String> targets = new ArrayList<String>(); | |||
for (Iterator<IRelationship> it = relations.iterator(); it.hasNext();) { | |||
IRelationship rtn = (IRelationship) it.next(); | |||
if (rtn.getKind().equals(kind) && ((relName != null && relName.equals(rtn.getName())) || relName == null)) { | |||
List targs = rtn.getTargets(); | |||
for (Iterator iter = targs.iterator(); iter.hasNext();) { | |||
String element = (String) iter.next(); | |||
List<String> targs = rtn.getTargets(); | |||
for (String element: targs) { | |||
if (!targets.contains(element)) { | |||
targets.add(element); | |||
} | |||
@@ -82,14 +81,13 @@ public class StructureUtil { | |||
return targets; | |||
} | |||
static List /* IProgramElement */getDeclareInterTypeTargets(IProgramElement node, IProgramElement.Kind kind) { | |||
List targets = new ArrayList(); | |||
List stringTargets = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE); | |||
static List<IProgramElement> getDeclareInterTypeTargets(IProgramElement node, IProgramElement.Kind kind) { | |||
List<IProgramElement> targets = new ArrayList<IProgramElement>(); | |||
List<String> stringTargets = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE); | |||
if (stringTargets == null) { | |||
return null; | |||
} | |||
for (Iterator iter = stringTargets.iterator(); iter.hasNext();) { | |||
String element = (String) iter.next(); | |||
for (String element: stringTargets) { | |||
IProgramElement ipe = node.getModel().getHierarchy().findElementForHandle(element); | |||
if (ipe != null && ipe.getKind().equals(kind)) { | |||
targets.add(ipe); | |||
@@ -98,13 +96,12 @@ public class StructureUtil { | |||
return targets; | |||
} | |||
public static List/* String */getDeclareTargets(IProgramElement node) { | |||
List relations = node.getModel().getRelationshipMap().get(node); | |||
List targets = null; | |||
public static List<String> getDeclareTargets(IProgramElement node) { | |||
List<IRelationship> relations = node.getModel().getRelationshipMap().get(node); | |||
List<String> targets = null; | |||
if (relations == null) | |||
return null; | |||
for (Iterator it = relations.iterator(); it.hasNext();) { | |||
IRelationship rtn = (IRelationship) it.next(); | |||
for (IRelationship rtn: relations) { | |||
if (rtn.getKind().isDeclareKind()) { | |||
targets = rtn.getTargets(); | |||
} |
@@ -19,6 +19,7 @@ import junit.framework.AssertionFailedError; | |||
import junit.framework.TestCase; | |||
import org.aspectj.tools.ajc.Ajc; | |||
import org.aspectj.util.LangUtil; | |||
/** | |||
* This class is the super class of all Ajdoc tests. It creates a sandbox directory and provides utility methods for copying over | |||
@@ -159,8 +160,14 @@ public class AjdocTestCase extends TestCase { | |||
if (inputFiles.length == 0) { | |||
fail("need to pass some files into ajdoc"); | |||
} | |||
if (!sourceLevel.equals("1.3") && !sourceLevel.equals("1.4") && !sourceLevel.equals("1.5")) { | |||
fail("need to pass ajdoc '1.3', '1.4', or '1.5' as the source level"); | |||
if (!sourceLevel.equals("1.3") && | |||
!sourceLevel.equals("1.4") && | |||
!sourceLevel.equals("1.5") && | |||
!sourceLevel.equals("1.6") && | |||
!sourceLevel.equals("1.7") && | |||
!sourceLevel.equals("1.8") && | |||
!sourceLevel.equals("1.9")) { | |||
fail("need to pass ajdoc '1.3' > '1.9' as the source level"); | |||
} | |||
String[] args = new String[6 + inputFiles.length + ajOptions.length]; | |||
args[0] = "-source"; | |||
@@ -185,8 +192,16 @@ public class AjdocTestCase extends TestCase { | |||
if (!visibility.equals("public") && !visibility.equals("protected") && !visibility.equals("private")) { | |||
fail("need to pass 'public','protected' or 'private' visibility to ajdoc"); | |||
} | |||
if (!sourceLevel.equals("1.3") && !sourceLevel.equals("1.4") && !sourceLevel.equals("1.5")) { | |||
fail("need to pass ajdoc '1.3', '1.4', or '1.5' as the source level"); | |||
if (!sourceLevel.equals("1.3") && | |||
!sourceLevel.equals("1.4") && | |||
!sourceLevel.equals("1.5") && | |||
!sourceLevel.equals("1.6") && | |||
!sourceLevel.equals("1.7") && | |||
!sourceLevel.equals("1.8") && | |||
!sourceLevel.equals("1.9") && | |||
!sourceLevel.startsWith("9") && | |||
!sourceLevel.startsWith("10")) { | |||
fail("need to pass suitable version to ajdoc as the source level"); | |||
} | |||
if (inputFiles.length == 0) { | |||
fail("need to pass some files into ajdoc"); | |||
@@ -202,7 +217,12 @@ public class AjdocTestCase extends TestCase { | |||
args[1] = "-source"; | |||
args[2] = sourceLevel; | |||
args[3] = "-classpath"; | |||
args[4] = AjdocTests.ASPECTJRT_PATH.getPath(); | |||
StringBuilder classpath = new StringBuilder(); | |||
if (LangUtil.is19VMOrGreater()) { | |||
classpath.append(LangUtil.getJrtFsFilePath()).append(File.pathSeparator); | |||
} | |||
classpath.append(AjdocTests.ASPECTJRT_PATH.getPath()); | |||
args[4] = classpath.toString(); | |||
args[5] = "-d"; | |||
args[6] = getAbsolutePathOutdir(); | |||
// args[7] = "-Xset:minimalModel=false"; |
@@ -69,7 +69,7 @@ public class BugTests extends AjdocTestCase { | |||
initialiseProject("pr148906"); | |||
File[] files = {new File(getAbsoluteProjectDir() + "/C.java")}; | |||
String[] ajOptions = {new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")}; | |||
runAjdoc(files,"1.5",ajOptions); | |||
runAjdoc(files,"1.6",ajOptions); | |||
assertFalse("expected clean build of project but found that build aborted",Main.hasAborted()); | |||
File html = new File(getAbsolutePathOutdir() + File.separator + "C.html"); | |||
if (!html.exists()) { | |||
@@ -90,7 +90,7 @@ public class BugTests extends AjdocTestCase { | |||
initialiseProject("pr148906"); | |||
File[] files = {new File(getAbsoluteProjectDir() + "/C.java")}; | |||
String[] ajOptions = {new String("-outxml"),new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")}; | |||
runAjdoc(files,"1.5",ajOptions); | |||
runAjdoc(files,"1.6",ajOptions); | |||
assertFalse("expected clean build of project but found that build aborted",Main.hasAborted()); | |||
File html = new File(getAbsolutePathOutdir() + File.separator + "C.html"); | |||
if (!html.exists()) { |
@@ -16,7 +16,6 @@ import java.util.List; | |||
import org.aspectj.util.LangUtil; | |||
/** | |||
* A long way to go until full coverage, but this is the place to add more. | |||
* | |||
@@ -56,7 +55,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testCoveragePublicMode() throws Exception { | |||
File[] files = {file3,file9}; | |||
runAjdoc("public","1.4",files); | |||
runAjdoc("public","9",files); | |||
// have passed the "public" modifier as well as | |||
// one public and one package visible class. There | |||
@@ -88,7 +87,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAJdocHasAspectTitle() throws Exception { | |||
File[] files = {new File(getAbsoluteProjectDir() + "/pkg/A.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/A.html"); | |||
if (!htmlFile.exists()) { | |||
fail("couldn't find " + htmlFile.getAbsolutePath()+ " - were there compilation errors?"); | |||
@@ -102,7 +101,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAJdocHasClassTitle() throws Exception { | |||
File[] files = {new File(getAbsoluteProjectDir() + "/pkg/C.java")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/C.html"); | |||
if (!htmlFile.exists()) { | |||
fail("couldn't find " + htmlFile.getAbsolutePath()+ " - were there compilation errors?"); | |||
@@ -118,7 +117,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testInnerAspect() throws Exception { | |||
File[] files = {file1, file2}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/ClassA.InnerAspect.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -206,7 +205,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdviceNamingCoverage() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdviceNamingCoverage.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -238,7 +237,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisesRelationshipCoverage() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdvisesRelationshipCoverage.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -291,7 +290,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByMethodExecution() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -322,7 +321,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByConstructorExecution() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -353,7 +352,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByMethodCall() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -384,7 +383,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByConstructorCall() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -415,7 +414,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByGet() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -446,7 +445,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedBySet() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -495,7 +494,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByInitialization() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -523,7 +522,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByStaticInitialization() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -544,7 +543,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByHandler() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -582,7 +581,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testTwoBeforeAdvice() throws Exception { | |||
File[] files = {new File(getAbsoluteProjectDir() + "/pkg/A2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/C2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -628,7 +627,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testNoSpuriousAdvisedByRels() throws Exception { | |||
File[] files = {file4}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdvisesRelationshipCoverage.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -647,7 +646,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
public void testCoverage() { | |||
File[] files = {aspect1,file0,file1,file2,file3,file4,file5,file6, | |||
file7,file8,file9,file10}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
} | |||
/** | |||
@@ -657,7 +656,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testNestedAspect() throws Exception { | |||
File[] files = {file9}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.NestedAspect.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -739,7 +738,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testNestedAspectWithSimilarName() throws Exception { | |||
File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -820,7 +819,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdviceInNestedAspect() throws Exception { | |||
File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -851,7 +850,7 @@ public class CoverageTestCase extends AjdocTestCase { | |||
*/ | |||
public void testAdvisedByInNestedAspect() throws Exception { | |||
File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html"); | |||
if (!htmlFile.exists()) { |
@@ -39,7 +39,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testCoverage() { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage.java")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
} | |||
/** | |||
@@ -49,7 +49,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testDeclareStatments() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/DeclareCoverage2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -84,7 +84,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testDeclareWarning() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/DeclareCoverage2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -116,7 +116,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testMatchesDeclareCall() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Main2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -149,7 +149,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testMatchesDeclareExecution() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -180,7 +180,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testDeclareParents() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/DeclareCoverage2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -211,7 +211,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testAspectDeclarations() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Point2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -234,7 +234,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testDeclareSoft() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/DeclareCoverage2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -265,7 +265,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testSoftenedBy() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareCoverage2.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Main2.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -304,7 +304,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testDeclareAnnotation() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareAtType.aj")}; | |||
runAjdoc("private","1.5",files); | |||
runAjdoc("private","1.6",files); | |||
// Aspect AnnotationTest should contain within it's declare | |||
// detail and summary the declare annotation statement. | |||
@@ -350,7 +350,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testMethodAnnotatedBy() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareAtMethod.aj")}; | |||
runAjdoc("private","1.5",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/C.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -383,7 +383,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testConstructorAnnotatedBy() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareAtConstructor.aj")}; | |||
runAjdoc("private","1.5",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/C.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -417,7 +417,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testFieldAnnotatedBy() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareAtField.aj")}; | |||
runAjdoc("private","1.5",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/C.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -451,7 +451,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testTypeAnnotatedBy() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareAtType.aj")}; | |||
runAjdoc("private","1.5",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/C.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -474,7 +474,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testMatchesDeclareAndAdvisedBy() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "A.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/C.html"); | |||
if (!htmlFile.exists()) { | |||
@@ -520,7 +520,7 @@ public class DeclareFormsTest extends AjdocTestCase { | |||
public void testTwoDeclareParents() throws Exception { | |||
initialiseProject("declareForms"); | |||
File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "DeclareParents.aj")}; | |||
runAjdoc("private","1.4",files); | |||
runAjdoc("private","1.6",files); | |||
File htmlFile = new File(getAbsolutePathOutdir() + "/foo/DeclareParents.html"); | |||
if (!htmlFile.exists()) { |
@@ -1,4 +1,3 @@ | |||
#Tue Jan 16 09:21:46 GMT 2007 | |||
eclipse.preferences.version=1 | |||
org.eclipse.jdt.core.builder.cleanOutputFolder=clean | |||
org.eclipse.jdt.core.builder.duplicateResourceTask=warning | |||
@@ -8,9 +7,9 @@ org.eclipse.jdt.core.circularClasspath=error | |||
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled | |||
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled | |||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | |||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | |||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |||
org.eclipse.jdt.core.compiler.compliance=1.5 | |||
org.eclipse.jdt.core.compiler.compliance=1.7 | |||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | |||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |||
@@ -58,6 +57,6 @@ org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore | |||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled | |||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled | |||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore | |||
org.eclipse.jdt.core.compiler.source=1.5 | |||
org.eclipse.jdt.core.compiler.source=1.7 | |||
org.eclipse.jdt.core.incompatibleJDKLevel=ignore | |||
org.eclipse.jdt.core.incompleteClasspath=error |
@@ -1,4 +1,5 @@ | |||
Manifest-Version: 1.0 | |||
Automatic-Module-Name: org.aspectj.runtime | |||
Name: org/aspectj/lang/ | |||
Specification-Title: AspectJ Runtime Classes |
@@ -1,9 +1,9 @@ | |||
#Tue Sep 08 17:08:00 PDT 2009 | |||
eclipse.preferences.version=1 | |||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | |||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate | |||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | |||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |||
org.eclipse.jdt.core.compiler.compliance=1.5 | |||
org.eclipse.jdt.core.compiler.compliance=1.7 | |||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | |||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |||
@@ -54,4 +54,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di | |||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled | |||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore | |||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning | |||
org.eclipse.jdt.core.compiler.source=1.5 | |||
org.eclipse.jdt.core.compiler.source=1.7 |
@@ -80,6 +80,8 @@ public interface Constants { | |||
public final static short MINOR_1_7 = 0; | |||
public final static short MAJOR_1_8 = 52; | |||
public final static short MINOR_1_8 = 0; | |||
public final static short MAJOR_1_9 = 53; | |||
public final static short MINOR_1_9 = 0; | |||
// Defaults | |||
public final static short MAJOR = MAJOR_1_1; | |||
public final static short MINOR = MINOR_1_1; | |||
@@ -107,11 +109,27 @@ public interface Constants { | |||
public final static short ACC_STRICT = 0x0800; | |||
public final static short ACC_SYNTHETIC = 0x1000; | |||
public final static short ACC_ANNOTATION = 0x2000; | |||
public final static short ACC_ENUM = 0x4000; | |||
public final static int ACC_MODULE = 0x8000; | |||
public final static short ACC_BRIDGE = 0x0040; | |||
public final static short ACC_VARARGS = 0x0080; | |||
// Module related | |||
// Indicates that any module which depends on the current module, | |||
// implicitly declares a dependence on the module indicated by this entry. | |||
public final static int MODULE_ACC_TRANSITIVE = 0x0020; | |||
// Indicates that this dependence is mandatory in the static phase, i.e., at | |||
// compile time, but is optional in the dynamic phase, i.e., at run time. | |||
public final static int MODULE_ACC_STATIC_PHASE = 0x0040; | |||
// Indicates that this dependence was not explicitly or implicitly declared | |||
// in the source of the module declaration. | |||
public final static int MODULE_ACC_SYNTHETIC = 0x1000; | |||
// Indicates that this dependence was implicitly declared in the source of | |||
// the module declaration | |||
public final static int MODULE_ACC_MANDATED = 0x8000; | |||
// Applies to classes compiled by new compilers only | |||
public final static short ACC_SUPER = 0x0020; | |||
@@ -136,10 +154,17 @@ public interface Constants { | |||
public final static byte CONSTANT_MethodHandle = 15; | |||
public final static byte CONSTANT_MethodType = 16; | |||
public final static byte CONSTANT_InvokeDynamic = 18; | |||
// J9: | |||
public final static byte CONSTANT_Module = 19; | |||
public final static byte CONSTANT_Package = 20; | |||
public final static String[] CONSTANT_NAMES = { "", "CONSTANT_Utf8", "", "CONSTANT_Integer", "CONSTANT_Float", "CONSTANT_Long", | |||
"CONSTANT_Double", "CONSTANT_Class", "CONSTANT_String", "CONSTANT_Fieldref", "CONSTANT_Methodref", | |||
"CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType","","","CONSTANT_MethodHandle","CONSTANT_MethodType","","CONSTANT_InvokeDynamic" }; | |||
"CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType","","","CONSTANT_MethodHandle","CONSTANT_MethodType","","CONSTANT_InvokeDynamic", | |||
// J9: | |||
"CONSTANT_Module", "CONSTANT_Package"}; | |||
/** | |||
* The name of the static initializer, also called "class initialization method" or "interface initialization | |||
@@ -617,8 +642,13 @@ public interface Constants { | |||
public static final byte ATTR_RUNTIME_VISIBLE_TYPE_ANNOTATIONS = 20; | |||
public static final byte ATTR_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = 21; | |||
public static final byte ATTR_METHOD_PARAMETERS = 22; | |||
public static final short KNOWN_ATTRIBUTES = 23; | |||
// J9: | |||
public static final byte ATTR_MODULE = 23; | |||
public static final byte ATTR_MODULE_PACKAGES = 24; | |||
public static final byte ATTR_MODULE_MAIN_CLASS = 25; | |||
public static final short KNOWN_ATTRIBUTES = 26; | |||
public static final String[] ATTRIBUTE_NAMES = { | |||
"SourceFile", "ConstantValue", "Code", "Exceptions", "LineNumberTable", "LocalVariableTable", | |||
@@ -626,7 +656,7 @@ public interface Constants { | |||
"RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations", "RuntimeVisibleParameterAnnotations", | |||
"RuntimeInvisibleParameterAnnotations", "LocalVariableTypeTable", "EnclosingMethod", | |||
"AnnotationDefault","BootstrapMethods", "RuntimeVisibleTypeAnnotations", "RuntimeInvisibleTypeAnnotations", | |||
"MethodParameters" | |||
"MethodParameters", "Module", "ModulePackages", "ModuleMainClass" | |||
}; | |||
/** |
@@ -167,6 +167,12 @@ public abstract class Attribute implements Cloneable, Node, Serializable { | |||
return new RuntimeInvisTypeAnnos(idx, len, file, cpool); | |||
case Constants.ATTR_METHOD_PARAMETERS: | |||
return new MethodParameters(idx, len, file, cpool); | |||
case Constants.ATTR_MODULE: | |||
return new Module(idx, len, file, cpool); | |||
case Constants.ATTR_MODULE_PACKAGES: | |||
return new ModulePackages(idx, len, file, cpool); | |||
case Constants.ATTR_MODULE_MAIN_CLASS: | |||
return new ModuleMainClass(idx, len, file, cpool); | |||
default: | |||
throw new IllegalStateException(); | |||
} |
@@ -180,7 +180,6 @@ public final class ClassParser { | |||
superclassnameIndex = file.readUnsignedShort(); | |||
} | |||
/** Read constant pool entries */ | |||
private final void readConstantPool() throws IOException { | |||
try { | |||
cpool = new ConstantPool(file); |
@@ -103,6 +103,10 @@ public interface ClassVisitor { | |||
public void visitConstantString(ConstantString obj); | |||
public void visitConstantModule(ConstantModule obj); | |||
public void visitConstantPackage(ConstantPackage obj); | |||
public void visitConstantUtf8(ConstantUtf8 obj); | |||
public void visitConstantValue(ConstantValue obj); | |||
@@ -162,4 +166,9 @@ public interface ClassVisitor { | |||
public void visitLocalVariableTypeTable(LocalVariableTypeTable obj); | |||
public void visitMethodParameters(MethodParameters methodParameters); | |||
// J9: | |||
public void visitModule(Module module); | |||
public void visitModulePackages(ModulePackages modulePackage); | |||
public void visitModuleMainClass(ModuleMainClass moduleMainClass); | |||
} |
@@ -135,6 +135,8 @@ public abstract class Constant implements Cloneable, Node { | |||
return new ConstantMethodType(dis); | |||
case Constants.CONSTANT_InvokeDynamic: | |||
return new ConstantInvokeDynamic(dis); | |||
case Constants.CONSTANT_Module: return new ConstantModule(dis); | |||
case Constants.CONSTANT_Package: return new ConstantPackage(dis); | |||
default: | |||
throw new ClassFormatException("Invalid byte tag in constant pool: " + b); | |||
} |
@@ -0,0 +1,111 @@ | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2017 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/>. | |||
*/ | |||
package org.aspectj.apache.bcel.classfile; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Represents a module. | |||
* | |||
* See http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jvms-diffs.pdf 4.4.11 | |||
* | |||
* @author Andy Clement | |||
*/ | |||
public final class ConstantModule extends Constant { | |||
private int nameIndex; | |||
ConstantModule(DataInputStream file) throws IOException { | |||
this(file.readUnsignedShort()); | |||
} | |||
public ConstantModule(int nameIndex) { | |||
super(Constants.CONSTANT_Module); | |||
this.nameIndex = nameIndex; | |||
} | |||
@Override | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantModule(this); | |||
} | |||
@Override | |||
public final void dump(DataOutputStream file) throws IOException { | |||
file.writeByte(tag); | |||
file.writeShort(nameIndex); | |||
} | |||
@Override | |||
public Integer getValue() { | |||
return nameIndex; | |||
} | |||
public final int getNameIndex() { | |||
return nameIndex; | |||
} | |||
@Override | |||
public final String toString() { | |||
return super.toString() + "(name_index = " + nameIndex + ")"; | |||
} | |||
public String getModuleName(ConstantPool cpool) { | |||
Constant c = cpool.getConstant(nameIndex, Constants.CONSTANT_Utf8); | |||
return ((ConstantUtf8) c).getValue(); | |||
} | |||
} |
@@ -0,0 +1,111 @@ | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2017 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/>. | |||
*/ | |||
package org.aspectj.apache.bcel.classfile; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Represents a module. | |||
* | |||
* See http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jvms-diffs.pdf 4.4.12 | |||
* | |||
* @author Andy Clement | |||
*/ | |||
public final class ConstantPackage extends Constant { | |||
private int nameIndex; | |||
ConstantPackage(DataInputStream file) throws IOException { | |||
this(file.readUnsignedShort()); | |||
} | |||
public ConstantPackage(int nameIndex) { | |||
super(Constants.CONSTANT_Package); | |||
this.nameIndex = nameIndex; | |||
} | |||
@Override | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantPackage(this); | |||
} | |||
@Override | |||
public final void dump(DataOutputStream file) throws IOException { | |||
file.writeByte(tag); | |||
file.writeShort(nameIndex); | |||
} | |||
@Override | |||
public Integer getValue() { | |||
return nameIndex; | |||
} | |||
public final int getNameIndex() { | |||
return nameIndex; | |||
} | |||
@Override | |||
public final String toString() { | |||
return super.toString() + "(name_index = " + nameIndex + ")"; | |||
} | |||
public String getPackageName(ConstantPool cpool) { | |||
Constant c = cpool.getConstant(nameIndex, Constants.CONSTANT_Utf8); | |||
return ((ConstantUtf8) c).getValue(); | |||
} | |||
} |
@@ -275,6 +275,20 @@ public class ConstantPool implements Node { | |||
assert c.tag == Constants.CONSTANT_Utf8; | |||
return (ConstantUtf8) c; | |||
} | |||
public ConstantModule getConstantModule(int index) { | |||
Constant c = getConstant(index); | |||
assert c != null; | |||
assert c.tag == Constants.CONSTANT_Module; | |||
return (ConstantModule)c; | |||
} | |||
public ConstantPackage getConstantPackage(int index) { | |||
Constant c = getConstant(index); | |||
assert c != null; | |||
assert c.tag == Constants.CONSTANT_Package; | |||
return (ConstantPackage)c; | |||
} | |||
public String getConstantString_CONSTANTClass(int index) { | |||
ConstantClass c = (ConstantClass) getConstant(index, Constants.CONSTANT_Class); | |||
@@ -770,4 +784,12 @@ public class ConstantPool implements Node { | |||
System.arraycopy(pool, 0, cs, 0, poolSize); | |||
return new ConstantPool(cs); | |||
} | |||
public String getModuleName(int moduleIndex) { | |||
return getConstantModule(moduleIndex).getModuleName(this); | |||
} | |||
public String getPackageName(int packageIndex) { | |||
return getConstantPackage(packageIndex).getPackageName(this); | |||
} | |||
} |
@@ -0,0 +1,664 @@ | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2016-17 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/>. | |||
*/ | |||
package org.aspectj.apache.bcel.classfile; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* This class is derived from <em>Attribute</em> and represents the module | |||
* information captured in a class file. | |||
* http://cr.openjdk.java.net/~mr/jigsaw/spec/lang-vm.html | |||
* http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jvms-diffs.pdf 4.7.25 | |||
* | |||
* @author Andy Clement | |||
*/ | |||
public final class Module extends Attribute { | |||
private static final String[] NO_MODULE_NAMES = {}; | |||
private int moduleNameIndex; // u2 module_name_index | |||
private int moduleFlags; // u2 module_flags | |||
private int moduleVersionIndex; // u2 module_version_index | |||
private Require[] requires; | |||
private Export[] exports; | |||
private Open[] opens; | |||
private Uses[] uses; | |||
private Provide[] provides; | |||
private byte[] moduleInfo; | |||
private int ptr; | |||
private boolean unpacked = false; | |||
public Module(Module module) { | |||
super(module.getTag(), module.getNameIndex(), module.getLength(), module.getConstantPool()); | |||
moduleInfo = module.getBytes(); | |||
} | |||
public Module(int nameIndex, int length, byte[] data, ConstantPool cp) { | |||
super(Constants.ATTR_MODULE, nameIndex, length, cp); | |||
} | |||
Module(int nameIndex, int length, DataInputStream stream, ConstantPool cp) throws IOException { | |||
this(nameIndex, length, (byte[])null, cp); | |||
moduleInfo = new byte[length]; | |||
stream.read(moduleInfo); | |||
unpacked = false; | |||
} | |||
public class Require { | |||
private final int moduleIndex; | |||
private final int flags; | |||
private final int versionIndex; | |||
public Require(int moduleIndex, int flags, int versionIndex) { | |||
this.moduleIndex = moduleIndex; | |||
this.flags = flags; | |||
this.versionIndex = versionIndex; | |||
} | |||
public String getModuleName() { | |||
return cpool.getModuleName(moduleIndex); | |||
} | |||
public int getFlags() { | |||
return flags; | |||
} | |||
public int getVersionIndex() { | |||
return versionIndex; | |||
} | |||
public String getVersionString() { | |||
if (versionIndex == 0) { | |||
return null; | |||
} else { | |||
return cpool.getConstantUtf8(versionIndex).getValue(); | |||
} | |||
} | |||
public String getFlagsAsString() { | |||
StringBuilder s = new StringBuilder(); | |||
if ((flags & Constants.MODULE_ACC_TRANSITIVE)!=0) { | |||
s.append(" transitive"); | |||
} | |||
if ((flags & Constants.MODULE_ACC_STATIC_PHASE)!=0) { | |||
s.append(" static"); | |||
} | |||
if ((flags & Constants.MODULE_ACC_SYNTHETIC)!=0) { | |||
s.append(" synthetic"); | |||
} | |||
if ((flags & Constants.MODULE_ACC_MANDATED)!=0) { | |||
s.append(" mandated"); | |||
} | |||
return s.toString(); | |||
} | |||
public String toString() { | |||
return "requires"+getFlagsAsString()+" "+getModuleName()+(versionIndex==0?"":" "+getVersionString()); | |||
} | |||
} | |||
public class Export { | |||
private final int packageIndex; | |||
private final int flags; | |||
private final int[] toModuleIndices; | |||
public Export(int packageIndex, int flags, int[] toModuleIndices) { | |||
this.packageIndex = packageIndex; | |||
this.flags = flags; | |||
this.toModuleIndices = toModuleIndices; | |||
} | |||
public int getPackageIndex() { | |||
return packageIndex; | |||
} | |||
public int getFlags() { | |||
return flags; | |||
} | |||
public int[] getToModuleIndices() { | |||
return toModuleIndices; | |||
} | |||
public String getPackage() { | |||
return cpool.getPackageName(packageIndex); | |||
} | |||
public String getFlagsAsString() { | |||
StringBuilder s = new StringBuilder(); | |||
if ((flags & Constants.MODULE_ACC_SYNTHETIC)!=0) { | |||
s.append(" synthetic"); | |||
} | |||
if ((flags & Constants.MODULE_ACC_MANDATED)!=0) { | |||
s.append(" synthetic"); | |||
} | |||
return s.toString(); | |||
} | |||
public String[] getToModuleNames() { | |||
if (toModuleIndices==null) { | |||
return NO_MODULE_NAMES; | |||
} | |||
String[] toModuleNames = new String[toModuleIndices.length]; | |||
for (int i=0;i<toModuleIndices.length;i++) { | |||
toModuleNames[i] = cpool.getModuleName(toModuleIndices[i]); | |||
} | |||
return toModuleNames; | |||
} | |||
public String toString() { | |||
StringBuilder s =new StringBuilder(); | |||
s.append("exports").append(getFlagsAsString()).append(" ").append(getPackage().replace('/', '.')); | |||
String[] toModules = getToModuleNames(); | |||
if (toModules.length!=0) { | |||
s.append(" to "); | |||
for (int i=0;i<toModules.length;i++) { | |||
if (i>0) { | |||
s.append(", "); | |||
} | |||
s.append(toModules[i]); | |||
} | |||
} | |||
return s.toString().trim(); | |||
} | |||
} | |||
public class Open { | |||
private final int packageIndex; | |||
private final int flags; | |||
private final int[] toModuleIndices; | |||
public Open(int packageIndex, int flags, int[] toModuleIndices) { | |||
this.packageIndex = packageIndex; | |||
this.flags = flags; | |||
this.toModuleIndices = toModuleIndices; | |||
} | |||
public int getPackageIndex() { | |||
return packageIndex; | |||
} | |||
public int getFlags() { | |||
return flags; | |||
} | |||
public int[] getToModuleIndices() { | |||
return toModuleIndices; | |||
} | |||
public String getPackage() { | |||
return cpool.getPackageName(packageIndex); | |||
} | |||
public String getFlagsAsString() { | |||
StringBuilder s = new StringBuilder(); | |||
if ((flags & Constants.MODULE_ACC_SYNTHETIC)!=0) { | |||
s.append(" synthetic"); | |||
} | |||
if ((flags & Constants.MODULE_ACC_MANDATED)!=0) { | |||
s.append(" synthetic"); | |||
} | |||
return s.toString(); | |||
} | |||
public String[] getToModuleNames() { | |||
if (toModuleIndices==null) { | |||
return NO_MODULE_NAMES; | |||
} | |||
String[] toModuleNames = new String[toModuleIndices.length]; | |||
for (int i=0;i<toModuleIndices.length;i++) { | |||
toModuleNames[i] = cpool.getModuleName(toModuleIndices[i]); | |||
} | |||
return toModuleNames; | |||
} | |||
public String toString() { | |||
StringBuilder s =new StringBuilder(); | |||
s.append("opens").append(getFlagsAsString()).append(" ").append(getPackage().replace('/', '.')); | |||
String[] toModules = getToModuleNames(); | |||
if (toModules.length!=0) { | |||
s.append(" to "); | |||
for (int i=0;i<toModules.length;i++) { | |||
if (i>0) { | |||
s.append(", "); | |||
} | |||
s.append(toModules[i]); | |||
} | |||
} | |||
return s.toString().trim(); | |||
} | |||
} | |||
public class Provide { | |||
private final int providedTypeIndex; | |||
private final int[] withTypeIndices; | |||
public Provide(int providedTypeIndex, int[] withTypeIndices) { | |||
this.providedTypeIndex = providedTypeIndex; | |||
this.withTypeIndices = withTypeIndices; | |||
} | |||
public String getProvidedType() { | |||
return cpool.getConstantString_CONSTANTClass(providedTypeIndex); | |||
} | |||
public int getProvidedTypeIndex() { | |||
return providedTypeIndex; | |||
} | |||
public String[] getWithTypeStrings() { | |||
String[] result = new String[withTypeIndices.length]; | |||
for (int i=0;i<withTypeIndices.length;i++) { | |||
result[i] = cpool.getConstantString_CONSTANTClass(withTypeIndices[i]); | |||
} | |||
return result; | |||
} | |||
public int[] getWithTypeIndices() { | |||
return withTypeIndices; | |||
} | |||
public String toString() { | |||
StringBuilder s =new StringBuilder(); | |||
s.append("provides ").append(getProvidedType().replace('/', '.')); | |||
s.append(" with "); | |||
String[] withtypes = getWithTypeStrings(); | |||
for (int i=0;i< withtypes.length;i++) { | |||
if (i>0) s.append(","); | |||
s.append(withtypes[i].replace('/','.')); | |||
} | |||
return s.toString(); | |||
} | |||
} | |||
public class Uses { | |||
private final int typeNameIndex; | |||
public Uses(int typeNameIndex) { | |||
this.typeNameIndex = typeNameIndex; | |||
} | |||
public String getTypeName() { | |||
return cpool.getConstantString_CONSTANTClass(typeNameIndex); | |||
} | |||
public int getTypeNameIndex() { | |||
return typeNameIndex; | |||
} | |||
public String toString() { | |||
StringBuilder s =new StringBuilder(); | |||
s.append("uses ").append(getTypeName().replace('/', '.')); | |||
return s.toString().trim(); | |||
} | |||
} | |||
private final int readInt() { | |||
return ((moduleInfo[ptr++] & 0xFF) << 24) + ((moduleInfo[ptr++] & 0xFF) << 16) | |||
+ ((moduleInfo[ptr++] & 0xFF) << 8) + (moduleInfo[ptr++] & 0xFF); | |||
} | |||
private final int readUnsignedShort() { | |||
return ((moduleInfo[ptr++] & 0xff) << 8) + (moduleInfo[ptr++] & 0xff); | |||
} | |||
private final int readUnsignedShort(int offset) { | |||
return ((moduleInfo[offset++] & 0xff) << 8) + (moduleInfo[offset] & 0xff); | |||
} | |||
// Format: http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jvms-diffs.pdf 4.7.25 | |||
private void ensureUnpacked() { | |||
if (!unpacked) { | |||
ptr = 0; | |||
moduleNameIndex = readUnsignedShort(); | |||
moduleFlags = readUnsignedShort(); | |||
moduleVersionIndex = readUnsignedShort(); | |||
int count = readUnsignedShort(); | |||
requires = new Require[count]; | |||
for (int i = 0; i < count; i++) { | |||
requires[i] = new Require(readUnsignedShort(), readUnsignedShort(), readUnsignedShort()); | |||
} | |||
count = readUnsignedShort(); | |||
exports = new Export[count]; | |||
for (int i = 0; i < count; i++) { | |||
int index = readUnsignedShort(); | |||
int flags = readUnsignedShort(); | |||
int toCount = readUnsignedShort(); | |||
int[] to = new int[toCount]; | |||
for (int j = 0; j < toCount; j++) { | |||
to[j] = readUnsignedShort(); | |||
} | |||
exports[i] = new Export(index, flags, to); | |||
} | |||
count = readUnsignedShort(); | |||
opens = new Open[count]; | |||
for (int i = 0; i < count; i++) { | |||
int index = readUnsignedShort(); | |||
int flags = readUnsignedShort(); | |||
int toCount = readUnsignedShort(); | |||
int[] to = new int[toCount]; | |||
for (int j = 0; j < toCount; j++) { | |||
to[j] = readUnsignedShort(); | |||
} | |||
opens[i] = new Open(index, flags, to); | |||
} | |||
count = readUnsignedShort(); | |||
uses = new Uses[count]; | |||
for (int i = 0; i < count; i++) { | |||
uses[i] = new Uses(readUnsignedShort()); | |||
} | |||
count = readUnsignedShort(); | |||
provides = new Provide[count]; | |||
for (int i = 0; i < count; i++) { | |||
int index = readUnsignedShort(); | |||
int toCount = readUnsignedShort(); | |||
int[] to = new int[toCount]; | |||
for (int j = 0; j < toCount; j++) { | |||
to[j] = readUnsignedShort(); | |||
} | |||
provides[i] = new Provide(index, to); | |||
} | |||
unpacked = true; | |||
} | |||
} | |||
@Override | |||
public final void dump(DataOutputStream file) throws IOException { | |||
super.dump(file); | |||
if (!unpacked) { | |||
file.write(moduleInfo); | |||
} else { | |||
file.writeShort(moduleNameIndex); | |||
file.writeShort(moduleFlags); | |||
file.writeShort(moduleVersionIndex); | |||
file.writeShort(requires.length); | |||
for (int i = 0; i < requires.length; i++) { | |||
file.writeShort(requires[i].moduleIndex); | |||
file.writeShort(requires[i].flags); | |||
file.writeShort(requires[i].versionIndex); | |||
} | |||
file.writeShort(exports.length); | |||
for (Export export : exports) { | |||
file.writeShort(export.packageIndex); | |||
int[] toIndices = export.toModuleIndices; | |||
file.writeShort(toIndices.length); | |||
for (int index : toIndices) { | |||
file.writeShort(index); | |||
} | |||
} | |||
file.writeShort(opens.length); | |||
for (Open open : opens) { | |||
file.writeShort(open.packageIndex); | |||
int[] toIndices = open.toModuleIndices; | |||
file.writeShort(toIndices.length); | |||
for (int index : toIndices) { | |||
file.writeShort(index); | |||
} | |||
} | |||
file.writeShort(uses.length); | |||
for (Uses use : uses) { | |||
file.writeShort(use.getTypeNameIndex()); | |||
} | |||
file.writeShort(provides.length); | |||
for (Provide provide : provides) { | |||
file.writeShort(provide.providedTypeIndex); | |||
int[] toIndices = provide.withTypeIndices; | |||
file.writeShort(toIndices.length); | |||
for (int index : toIndices) { | |||
file.writeShort(index); | |||
} | |||
} | |||
} | |||
} | |||
public String toStringRequires() { | |||
StringBuilder s = new StringBuilder(); | |||
s.append('#').append(requires.length); | |||
if (requires.length > 0) { | |||
for (Require require : requires) { | |||
s.append(' '); | |||
s.append(require.moduleIndex).append(':').append(require.flags); | |||
} | |||
} | |||
return s.toString(); | |||
} | |||
public String toStringExports() { | |||
StringBuilder s = new StringBuilder(); | |||
s.append('#').append(exports.length); | |||
if (exports.length > 0) { | |||
for (Export export : exports) { | |||
s.append(' '); | |||
s.append(export.packageIndex).append(":["); | |||
int[] toIndices = export.toModuleIndices; | |||
for (int i = 0; i < toIndices.length; i++) { | |||
if (i > 0) | |||
s.append(','); | |||
s.append(toIndices[i]); | |||
} | |||
s.append("]"); | |||
} | |||
} | |||
return s.toString(); | |||
} | |||
public String toStringOpens() { | |||
StringBuilder s = new StringBuilder(); | |||
s.append('#').append(opens.length); | |||
if (opens.length > 0) { | |||
for (Open open : opens) { | |||
s.append(' '); | |||
s.append(open.packageIndex).append(":["); | |||
int[] toIndices = open.toModuleIndices; | |||
for (int i = 0; i < toIndices.length; i++) { | |||
if (i > 0) | |||
s.append(','); | |||
s.append(toIndices[i]); | |||
} | |||
s.append("]"); | |||
} | |||
} | |||
return s.toString(); | |||
} | |||
public String toStringUses() { | |||
StringBuilder s = new StringBuilder(); | |||
s.append('#').append(uses.length); | |||
if (uses.length > 0) { | |||
for (Uses use : uses) { | |||
s.append(' '); | |||
s.append(use.getTypeName()); | |||
} | |||
} | |||
return s.toString(); | |||
} | |||
public String toStringProvides() { | |||
StringBuilder s = new StringBuilder(); | |||
s.append('#').append(provides.length); | |||
if (provides.length > 0) { | |||
for (Provide provide : provides) { | |||
s.append(' '); | |||
s.append(provide.providedTypeIndex).append(":["); | |||
int[] indices = provide.withTypeIndices; | |||
for (int i = 0; i < indices.length; i++) { | |||
if (i > 0) | |||
s.append(','); | |||
s.append(indices[i]); | |||
} | |||
s.append("]"); | |||
} | |||
} | |||
return s.toString(); | |||
} | |||
@Override | |||
public final String toString() { | |||
StringBuilder s = new StringBuilder(); | |||
ensureUnpacked(); | |||
s.append("Module("); | |||
if (requires.length != 0) { | |||
s.append("requires="); | |||
s.append(toStringRequires()); | |||
s.append(" "); | |||
} | |||
if (exports.length != 0) { | |||
s.append("exports="); | |||
s.append(toStringExports()); | |||
s.append(" "); | |||
} | |||
if (opens.length != 0) { | |||
s.append("opens="); | |||
s.append(toStringOpens()); | |||
s.append(" "); | |||
} | |||
if (uses.length != 0) { | |||
s.append("uses="); | |||
s.append(toStringUses()); | |||
s.append(" "); | |||
} | |||
if (provides.length != 0) { | |||
s.append("provides="); | |||
s.append(toStringProvides()); | |||
s.append(" "); | |||
} | |||
return s.toString().trim()+")"; | |||
} | |||
/** | |||
* @return deep copy of this attribute // | |||
*/ | |||
// @Override | |||
// public Attribute copy(ConstantPool constant_pool) { | |||
// return (Module) clone(); | |||
// } | |||
@Override | |||
public void accept(ClassVisitor v) { | |||
v.visitModule(this); | |||
} | |||
public Require[] getRequires() { | |||
ensureUnpacked(); | |||
return requires; | |||
} | |||
public String[] getRequiredModuleNames() { | |||
ensureUnpacked(); | |||
String[] results = new String[requires.length]; | |||
for (int i=0;i<requires.length;i++) { | |||
results[i] = cpool.getModuleName(requires[i].moduleIndex); | |||
} | |||
return results; | |||
} | |||
public byte[] getBytes() { | |||
return moduleInfo; | |||
} | |||
public Export[] getExports() { | |||
ensureUnpacked(); | |||
return exports; | |||
} | |||
public Open[] getOpens() { | |||
ensureUnpacked(); | |||
return opens; | |||
} | |||
public Uses[] getUses() { | |||
ensureUnpacked(); | |||
return uses; | |||
} | |||
public Provide[] getProvides() { | |||
ensureUnpacked(); | |||
return provides; | |||
} | |||
public String getModuleName() { | |||
return ((ConstantModule)cpool.getConstant(moduleNameIndex)).getModuleName(cpool); | |||
} | |||
public int getModuleFlags() { | |||
// 0x0020 (ACC_OPEN) - Indicates that this module is open. | |||
// 0x1000 (ACC_SYNTHETIC) - Indicates that this module was not explicitly or implicitly declared. | |||
// 0x8000 (ACC_MANDATED) - Indicates that this module was implicitly declared | |||
return moduleFlags; | |||
} | |||
/** @return the module version or null if no version information specified */ | |||
public String getModuleVersion() { | |||
if (moduleVersionIndex == 0) { | |||
return null; | |||
} else { | |||
return cpool.getConstantUtf8(moduleVersionIndex).getValue(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,106 @@ | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2017 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/>. | |||
*/ | |||
package org.aspectj.apache.bcel.classfile; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Indicates the main class of a module. | |||
* http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jvms-diffs.pdf 4.7.26 | |||
* | |||
* @author Andy Clement | |||
*/ | |||
public final class ModuleMainClass extends Attribute { | |||
private int mainClassIndex; | |||
public ModuleMainClass(ModuleMainClass c) { | |||
this(c.getNameIndex(), c.getLength(), c.getMainClassIndex(), c.getConstantPool()); | |||
} | |||
public ModuleMainClass(int nameIndex, int length, int mainClassIndex, ConstantPool cp) { | |||
super(Constants.ATTR_MODULE_MAIN_CLASS, nameIndex, length, cp); | |||
this.mainClassIndex = mainClassIndex; | |||
} | |||
ModuleMainClass(int nameIndex, int length, DataInputStream stream, ConstantPool cp) throws IOException { | |||
this(nameIndex, length, 0, cp); | |||
this.mainClassIndex = stream.readUnsignedShort(); | |||
} | |||
@Override | |||
public void accept(ClassVisitor v) { | |||
v.visitModuleMainClass(this); | |||
} | |||
@Override | |||
public final void dump(DataOutputStream stream) throws IOException { | |||
super.dump(stream); | |||
stream.writeShort(mainClassIndex); | |||
} | |||
public final int getMainClassIndex() { | |||
return mainClassIndex; | |||
} | |||
@Override | |||
public final String toString() { | |||
return cpool.getConstantString_CONSTANTClass(mainClassIndex); | |||
} | |||
} |
@@ -0,0 +1,126 @@ | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2017 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/>. | |||
*/ | |||
package org.aspectj.apache.bcel.classfile; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Indicates all the packages of a module that are exported or opened by the module attribute. | |||
* http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jvms-diffs.pdf 4.7.26 | |||
* | |||
* @author Andy Clement | |||
*/ | |||
public final class ModulePackages extends Attribute { | |||
private static int[] NO_PACKAGES = new int[0]; | |||
private int[] packageIndices; | |||
public ModulePackages(ModulePackages c) { | |||
this(c.getNameIndex(), c.getLength(), c.getPackageIndices(), c.getConstantPool()); | |||
} | |||
public ModulePackages(int nameIndex, int length, int[] packageIndices, ConstantPool cp) { | |||
super(Constants.ATTR_MODULE_PACKAGES, nameIndex, length, cp); | |||
setPackageIndices(packageIndices); | |||
} | |||
ModulePackages(int nameIndex, int length, DataInputStream stream, ConstantPool cp) throws IOException { | |||
this(nameIndex, length, (int[]) null, cp); | |||
int packageIndicesCount = stream.readUnsignedShort(); | |||
packageIndices = new int[packageIndicesCount]; | |||
for (int i = 0; i < packageIndicesCount; i++) { | |||
packageIndices[i] = stream.readUnsignedShort(); | |||
} | |||
} | |||
@Override | |||
public void accept(ClassVisitor v) { | |||
v.visitModulePackages(this); | |||
} | |||
@Override | |||
public final void dump(DataOutputStream stream) throws IOException { | |||
super.dump(stream); | |||
stream.writeShort(packageIndices.length); | |||
for (int i = 0; i < packageIndices.length; i++) { | |||
stream.writeShort(packageIndices[i]); | |||
} | |||
} | |||
public final int[] getPackageIndices() { | |||
return packageIndices; | |||
} | |||
public final void setPackageIndices(int[] packageIndices) { | |||
if (packageIndices == null) { | |||
this.packageIndices = NO_PACKAGES; | |||
} else { | |||
this.packageIndices = packageIndices; | |||
} | |||
} | |||
@Override | |||
public final String toString() { | |||
StringBuffer buf = new StringBuffer(); | |||
for (int i = 0; i < packageIndices.length; i++) { | |||
buf.append(cpool.getPackageName(packageIndices[i]) + "\n"); | |||
} | |||
return buf.toString(); | |||
} | |||
} |
@@ -82,6 +82,10 @@ public class InstructionFactory implements InstructionConstants { | |||
this(null, cp); | |||
} | |||
public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind) { | |||
return createInvoke(class_name, name, ret_type, arg_types, kind, false); | |||
} | |||
/** | |||
* Create an invoke instruction. | |||
* | |||
@@ -90,14 +94,15 @@ public class InstructionFactory implements InstructionConstants { | |||
* @param ret_type return type of method | |||
* @param arg_types argument types of method | |||
* @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL | |||
* @param isInterface for an invokestatic on an interface allows us to tell this method the target is an interface | |||
* @see Constants | |||
*/ | |||
public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind) { | |||
public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind, boolean isInterface) { | |||
String signature = Utility.toMethodSignature(ret_type, arg_types); | |||
int index; | |||
if (kind == Constants.INVOKEINTERFACE) { | |||
if (kind == Constants.INVOKEINTERFACE || isInterface) { | |||
index = cp.addInterfaceMethodref(class_name, name, signature); | |||
} else if (kind == Constants.INVOKEDYNAMIC){ | |||
throw new IllegalStateException("NYI"); |
@@ -88,15 +88,13 @@ public class ClassLoaderRepository implements Repository { | |||
private ClassLoaderReference loaderRef; | |||
// Choice of cache... | |||
private WeakHashMap /* <URL,SoftRef(JavaClass)> */<URL, SoftReference<JavaClass>> localCache = new WeakHashMap<URL, SoftReference<JavaClass>>(); | |||
private static SoftHashMap /* <URL,JavaClass> */sharedCache = new SoftHashMap(Collections | |||
.synchronizedMap(new HashMap<Object, SpecialValue>())); | |||
private WeakHashMap<URL, SoftReference<JavaClass>> localCache = new WeakHashMap<URL, SoftReference<JavaClass>>(); | |||
private static SoftHashMap /* <URL,JavaClass> */sharedCache = new SoftHashMap(Collections.synchronizedMap(new HashMap<Object, SpecialValue>())); | |||
// For fast translation of the classname *intentionally not static* | |||
private SoftHashMap /* <String,URL> */nameMap = new SoftHashMap(new HashMap(), false); | |||
public static boolean useSharedCache = System.getProperty("org.aspectj.apache.bcel.useSharedCache", "true").equalsIgnoreCase( | |||
"true"); | |||
public static boolean useSharedCache = System.getProperty("org.aspectj.apache.bcel.useSharedCache", "true").equalsIgnoreCase("true"); | |||
private static int cacheHitsShared = 0; | |||
private static int missSharedEvicted = 0; // Misses in shared cache access due to reference GC |
@@ -1,9 +1,7 @@ | |||
package org.aspectj.apache.bcel.util; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* Copyright (c) 2001, 2017 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
@@ -53,326 +51,501 @@ package org.aspectj.apache.bcel.util; | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.aspectj.apache.bcel.util; | |||
import java.util.*; | |||
import java.util.zip.*; | |||
import java.io.*; | |||
import java.net.URI; | |||
import java.nio.file.FileVisitResult; | |||
import java.nio.file.SimpleFileVisitor; | |||
import java.nio.file.DirectoryStream; | |||
import java.nio.file.FileSystems; | |||
import java.nio.file.Files; | |||
import java.nio.file.NoSuchFileException; | |||
import java.nio.file.Path; | |||
import java.nio.file.attribute.BasicFileAttributeView; | |||
import java.nio.file.attribute.BasicFileAttributes; | |||
/** | |||
* Responsible for loading (class) files from the CLASSPATH. Inspired by | |||
* sun.tools.ClassPath. | |||
* | |||
* @version $Id: ClassPath.java,v 1.5 2009/09/09 19:56:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @author M. Dahm | |||
* @author Mario Ivankovits | |||
* @author Andy Clement | |||
*/ | |||
public class ClassPath implements Serializable { | |||
private static ClassPath SYSTEM_CLASS_PATH = null; | |||
private PathEntry[] paths; | |||
private String class_path; | |||
public static ClassPath getSystemClassPath() { | |||
if (SYSTEM_CLASS_PATH == null) { | |||
SYSTEM_CLASS_PATH = new ClassPath(); | |||
} | |||
return SYSTEM_CLASS_PATH; | |||
} | |||
/** | |||
* Search for classes in given path. | |||
*/ | |||
public ClassPath(String class_path) { | |||
this.class_path = class_path; | |||
ArrayList<PathEntry> vec = new ArrayList<PathEntry>(); | |||
for(StringTokenizer tok=new StringTokenizer(class_path, | |||
System.getProperty("path.separator")); | |||
tok.hasMoreTokens();) | |||
{ | |||
String path = tok.nextToken(); | |||
if(!path.equals("")) { | |||
File file = new File(path); | |||
try { | |||
if(file.exists()) { | |||
if(file.isDirectory()) | |||
vec.add(new Dir(path)); | |||
else | |||
vec.add(new Zip(new ZipFile(file))); | |||
} | |||
} catch(IOException e) { | |||
System.err.println("CLASSPATH component " + file + ": " + e); | |||
private static final String JRT_FS = "jrt-fs.jar"; | |||
private static ClassPath SYSTEM_CLASS_PATH = null; | |||
private PathEntry[] paths; | |||
private String class_path; | |||
public static ClassPath getSystemClassPath() { | |||
if (SYSTEM_CLASS_PATH == null) { | |||
SYSTEM_CLASS_PATH = new ClassPath(); | |||
} | |||
return SYSTEM_CLASS_PATH; | |||
} | |||
} | |||
} | |||
paths = new PathEntry[vec.size()]; | |||
vec.toArray(paths); | |||
} | |||
/** | |||
* Search for classes in CLASSPATH. | |||
* @deprecated Use SYSTEM_CLASS_PATH constant | |||
*/ | |||
public ClassPath() { | |||
this(getClassPath()); | |||
} | |||
/** @return used class path string | |||
*/ | |||
public String toString() { | |||
return class_path; | |||
} | |||
public int hashCode() { | |||
return class_path.hashCode(); | |||
} | |||
public boolean equals(Object o) { | |||
if(o instanceof ClassPath) { | |||
return class_path.equals(((ClassPath)o).class_path); | |||
} | |||
return false; | |||
} | |||
private static final void getPathComponents(String path, ArrayList<String> list) { | |||
if(path != null) { | |||
StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); | |||
while(tok.hasMoreTokens()) { | |||
String name = tok.nextToken(); | |||
File file = new File(name); | |||
if(file.exists()) | |||
list.add(name); | |||
} | |||
} | |||
} | |||
/** Checks for class path components in the following properties: | |||
* "java.class.path", "sun.boot.class.path", "java.ext.dirs" | |||
* | |||
* @return class path as used by default by BCEL | |||
*/ | |||
public static final String getClassPath() { | |||
String class_path = System.getProperty("java.class.path"); | |||
String boot_path = System.getProperty("sun.boot.class.path"); | |||
String ext_path = System.getProperty("java.ext.dirs"); | |||
ArrayList<String> list = new ArrayList<String>(); | |||
getPathComponents(class_path, list); | |||
getPathComponents(boot_path, list); | |||
ArrayList<String> dirs = new ArrayList<String>(); | |||
getPathComponents(ext_path, dirs); | |||
for(Iterator<String> e = dirs.iterator(); e.hasNext(); ) { | |||
File ext_dir = new File(e.next()); | |||
String[] extensions = ext_dir.list(new FilenameFilter() { | |||
public boolean accept(File dir, String name) { | |||
name = name.toLowerCase(); | |||
return name.endsWith(".zip") || name.endsWith(".jar"); | |||
/** | |||
* Search for classes in given path. | |||
*/ | |||
public ClassPath(String class_path) { | |||
this.class_path = class_path; | |||
ArrayList<PathEntry> vec = new ArrayList<PathEntry>(); | |||
for (StringTokenizer tok = new StringTokenizer(class_path, System.getProperty("path.separator")); tok | |||
.hasMoreTokens();) { | |||
String path = tok.nextToken(); | |||
if (!path.equals("")) { | |||
File file = new File(path); | |||
try { | |||
if (file.exists()) { | |||
if (file.isDirectory()) { | |||
vec.add(new Dir(path)); | |||
} else if (file.getName().endsWith("jrt-fs.jar")) { // TODO a bit crude... | |||
vec.add(new JImage()); | |||
} else { | |||
vec.add(new Zip(new ZipFile(file))); | |||
} | |||
} | |||
} catch (IOException e) { | |||
System.err.println("CLASSPATH component " + file + ": " + e); | |||
} | |||
} | |||
} | |||
paths = new PathEntry[vec.size()]; | |||
vec.toArray(paths); | |||
} | |||
}); | |||
if(extensions != null) | |||
for(int i=0; i < extensions.length; i++) | |||
list.add(ext_path + File.separatorChar + extensions[i]); | |||
} | |||
StringBuffer buf = new StringBuffer(); | |||
for(Iterator<String> e = list.iterator(); e.hasNext(); ) { | |||
buf.append(e.next()); | |||
if(e.hasNext()) | |||
buf.append(File.pathSeparatorChar); | |||
} | |||
return buf.toString().intern(); | |||
} | |||
/** | |||
* @param name fully qualified class name, e.g. java.lang.String | |||
* @return input stream for class | |||
*/ | |||
public InputStream getInputStream(String name) throws IOException { | |||
return getInputStream(name, ".class"); | |||
} | |||
/** | |||
* Return stream for class or resource on CLASSPATH. | |||
* | |||
* @param name fully qualified file name, e.g. java/lang/String | |||
* @param suffix file name ends with suff, e.g. .java | |||
* @return input stream for file on class path | |||
*/ | |||
public InputStream getInputStream(String name, String suffix) throws IOException { | |||
InputStream is = null; | |||
try { | |||
is = getClass().getClassLoader().getResourceAsStream(name + suffix); | |||
} catch(Exception e) { } | |||
if(is != null) | |||
return is; | |||
return getClassFile(name, suffix).getInputStream(); | |||
} | |||
/** | |||
* @param name fully qualified file name, e.g. java/lang/String | |||
* @param suffix file name ends with suff, e.g. .java | |||
* @return class file for the java class | |||
*/ | |||
public ClassFile getClassFile(String name, String suffix) throws IOException { | |||
for(int i=0; i < paths.length; i++) { | |||
ClassFile cf; | |||
if((cf = paths[i].getClassFile(name, suffix)) != null) | |||
return cf; | |||
} | |||
throw new IOException("Couldn't find: " + name + suffix); | |||
} | |||
/** | |||
* @param name fully qualified class name, e.g. java.lang.String | |||
* @return input stream for class | |||
*/ | |||
public ClassFile getClassFile(String name) throws IOException { | |||
return getClassFile(name, ".class"); | |||
} | |||
/** | |||
* @param name fully qualified file name, e.g. java/lang/String | |||
* @param suffix file name ends with suffix, e.g. .java | |||
* @return byte array for file on class path | |||
*/ | |||
public byte[] getBytes(String name, String suffix) throws IOException { | |||
InputStream is = getInputStream(name, suffix); | |||
if(is == null) | |||
throw new IOException("Couldn't find: " + name + suffix); | |||
DataInputStream dis = new DataInputStream(is); | |||
byte[] bytes = new byte[is.available()]; | |||
dis.readFully(bytes); | |||
dis.close(); is.close(); | |||
return bytes; | |||
} | |||
/** | |||
* @return byte array for class | |||
*/ | |||
public byte[] getBytes(String name) throws IOException { | |||
return getBytes(name, ".class"); | |||
} | |||
/** | |||
* @param name name of file to search for, e.g. java/lang/String.java | |||
* @return full (canonical) path for file | |||
*/ | |||
public String getPath(String name) throws IOException { | |||
int index = name.lastIndexOf('.'); | |||
String suffix = ""; | |||
if(index > 0) { | |||
suffix = name.substring(index); | |||
name = name.substring(0, index); | |||
} | |||
return getPath(name, suffix); | |||
} | |||
/** | |||
* @param name name of file to search for, e.g. java/lang/String | |||
* @param suffix file name suffix, e.g. .java | |||
* @return full (canonical) path for file, if it exists | |||
*/ | |||
public String getPath(String name, String suffix) throws IOException { | |||
return getClassFile(name, suffix).getPath(); | |||
} | |||
private static abstract class PathEntry implements Serializable { | |||
abstract ClassFile getClassFile(String name, String suffix) throws IOException; | |||
} | |||
/** Contains information about file/ZIP entry of the Java class. | |||
*/ | |||
public interface ClassFile { | |||
/** @return input stream for class file. | |||
*/ | |||
public abstract InputStream getInputStream() throws IOException; | |||
/** @return canonical path to class file. | |||
*/ | |||
public abstract String getPath(); | |||
/** @return base path of found class, i.e. class is contained relative | |||
* to that path, which may either denote a directory, or zip file | |||
*/ | |||
public abstract String getBase(); | |||
/** @return modification time of class file. | |||
*/ | |||
public abstract long getTime(); | |||
/** @return size of class file. | |||
*/ | |||
public abstract long getSize(); | |||
} | |||
private static class Dir extends PathEntry { | |||
private String dir; | |||
Dir(String d) { dir = d; } | |||
ClassFile getClassFile(String name, String suffix) throws IOException { | |||
final File file = new File(dir + File.separatorChar + | |||
name.replace('.', File.separatorChar) + suffix); | |||
return file.exists()? new ClassFile() { | |||
public InputStream getInputStream() throws IOException { return new FileInputStream(file); } | |||
public String getPath() { try { | |||
return file.getCanonicalPath(); | |||
} catch(IOException e) { return null; } | |||
/** | |||
* Search for classes in CLASSPATH. | |||
* | |||
* @deprecated Use SYSTEM_CLASS_PATH constant | |||
*/ | |||
public ClassPath() { | |||
this(getClassPath()); | |||
} | |||
public long getTime() { return file.lastModified(); } | |||
public long getSize() { return file.length(); } | |||
public String getBase() { return dir; } | |||
} : null; | |||
} | |||
/** | |||
* @return used class path string | |||
*/ | |||
public String toString() { | |||
return class_path; | |||
} | |||
public String toString() { return dir; } | |||
} | |||
public int hashCode() { | |||
return class_path.hashCode(); | |||
} | |||
private static class Zip extends PathEntry { | |||
private ZipFile zip; | |||
public boolean equals(Object o) { | |||
if (o instanceof ClassPath) { | |||
return class_path.equals(((ClassPath) o).class_path); | |||
} | |||
Zip(ZipFile z) { zip = z; } | |||
return false; | |||
} | |||
ClassFile getClassFile(String name, String suffix) throws IOException { | |||
final ZipEntry entry = zip.getEntry(name.replace('.', '/') + suffix); | |||
private static final void getPathComponents(String path, ArrayList<String> list) { | |||
if (path != null) { | |||
StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); | |||
return (entry != null)? new ClassFile() { | |||
public InputStream getInputStream() throws IOException { return zip.getInputStream(entry); } | |||
public String getPath() { return entry.toString(); } | |||
public long getTime() { return entry.getTime(); } | |||
public long getSize() { return entry.getSize(); } | |||
public String getBase() { | |||
return zip.getName(); | |||
while (tok.hasMoreTokens()) { | |||
String name = tok.nextToken(); | |||
File file = new File(name); | |||
if (file.exists()) | |||
list.add(name); | |||
} | |||
} | |||
} | |||
} : null; | |||
} | |||
} | |||
} | |||
/** | |||
* Checks for class path components in the following properties: | |||
* "java.class.path", "sun.boot.class.path", "java.ext.dirs" | |||
* | |||
* @return class path as used by default by BCEL | |||
*/ | |||
public static final String getClassPath() { | |||
String class_path = System.getProperty("java.class.path"); | |||
String boot_path = System.getProperty("sun.boot.class.path"); | |||
String ext_path = System.getProperty("java.ext.dirs"); | |||
String vm_version = System.getProperty("java.version"); | |||
ArrayList<String> list = new ArrayList<String>(); | |||
getPathComponents(class_path, list); | |||
getPathComponents(boot_path, list); | |||
ArrayList<String> dirs = new ArrayList<String>(); | |||
getPathComponents(ext_path, dirs); | |||
for (Iterator<String> e = dirs.iterator(); e.hasNext();) { | |||
File ext_dir = new File(e.next()); | |||
String[] extensions = ext_dir.list(new FilenameFilter() { | |||
public boolean accept(File dir, String name) { | |||
name = name.toLowerCase(); | |||
return name.endsWith(".zip") || name.endsWith(".jar"); | |||
} | |||
}); | |||
if (extensions != null) | |||
for (int i = 0; i < extensions.length; i++) | |||
list.add(ext_path + File.separatorChar + extensions[i]); | |||
} | |||
StringBuffer buf = new StringBuffer(); | |||
for (Iterator<String> e = list.iterator(); e.hasNext();) { | |||
buf.append(e.next()); | |||
if (e.hasNext()) | |||
buf.append(File.pathSeparatorChar); | |||
} | |||
// On Java9 the sun.boot.class.path won't be set. System classes accessible through JRT filesystem | |||
if (vm_version.startsWith("9")) { | |||
buf.insert(0, File.pathSeparatorChar); | |||
buf.insert(0, System.getProperty("java.home") + File.separator + "lib" + File.separator + JRT_FS); | |||
} | |||
return buf.toString().intern(); | |||
} | |||
/** | |||
* @param name | |||
* fully qualified class name, e.g. java.lang.String | |||
* @return input stream for class | |||
*/ | |||
public InputStream getInputStream(String name) throws IOException { | |||
return getInputStream(name, ".class"); | |||
} | |||
/** | |||
* Return stream for class or resource on CLASSPATH. | |||
* | |||
* @param name | |||
* fully qualified file name, e.g. java/lang/String | |||
* @param suffix | |||
* file name ends with suff, e.g. .java | |||
* @return input stream for file on class path | |||
*/ | |||
public InputStream getInputStream(String name, String suffix) throws IOException { | |||
InputStream is = null; | |||
try { | |||
is = getClass().getClassLoader().getResourceAsStream(name + suffix); | |||
} catch (Exception e) { | |||
} | |||
if (is != null) | |||
return is; | |||
return getClassFile(name, suffix).getInputStream(); | |||
} | |||
/** | |||
* @param name | |||
* fully qualified file name, e.g. java/lang/String | |||
* @param suffix | |||
* file name ends with suff, e.g. .java | |||
* @return class file for the java class | |||
*/ | |||
public ClassFile getClassFile(String name, String suffix) throws IOException { | |||
for (int i = 0; i < paths.length; i++) { | |||
ClassFile cf; | |||
if ((cf = paths[i].getClassFile(name, suffix)) != null) | |||
return cf; | |||
} | |||
throw new IOException("Couldn't find: " + name + suffix); | |||
} | |||
/** | |||
* @param name | |||
* fully qualified class name, e.g. java.lang.String | |||
* @return input stream for class | |||
*/ | |||
public ClassFile getClassFile(String name) throws IOException { | |||
return getClassFile(name, ".class"); | |||
} | |||
/** | |||
* @param name | |||
* fully qualified file name, e.g. java/lang/String | |||
* @param suffix | |||
* file name ends with suffix, e.g. .java | |||
* @return byte array for file on class path | |||
*/ | |||
public byte[] getBytes(String name, String suffix) throws IOException { | |||
InputStream is = getInputStream(name, suffix); | |||
if (is == null) | |||
throw new IOException("Couldn't find: " + name + suffix); | |||
DataInputStream dis = new DataInputStream(is); | |||
byte[] bytes = new byte[is.available()]; | |||
dis.readFully(bytes); | |||
dis.close(); | |||
is.close(); | |||
return bytes; | |||
} | |||
/** | |||
* @return byte array for class | |||
*/ | |||
public byte[] getBytes(String name) throws IOException { | |||
return getBytes(name, ".class"); | |||
} | |||
/** | |||
* @param name | |||
* name of file to search for, e.g. java/lang/String.java | |||
* @return full (canonical) path for file | |||
*/ | |||
public String getPath(String name) throws IOException { | |||
int index = name.lastIndexOf('.'); | |||
String suffix = ""; | |||
if (index > 0) { | |||
suffix = name.substring(index); | |||
name = name.substring(0, index); | |||
} | |||
return getPath(name, suffix); | |||
} | |||
/** | |||
* @param name | |||
* name of file to search for, e.g. java/lang/String | |||
* @param suffix | |||
* file name suffix, e.g. .java | |||
* @return full (canonical) path for file, if it exists | |||
*/ | |||
public String getPath(String name, String suffix) throws IOException { | |||
return getClassFile(name, suffix).getPath(); | |||
} | |||
private static abstract class PathEntry implements Serializable { | |||
abstract ClassFile getClassFile(String name, String suffix) throws IOException; | |||
} | |||
/** | |||
* Contains information about file/ZIP entry of the Java class. | |||
*/ | |||
public interface ClassFile { | |||
/** | |||
* @return input stream for class file. | |||
*/ | |||
public abstract InputStream getInputStream() throws IOException; | |||
/** | |||
* @return canonical path to class file. | |||
*/ | |||
public abstract String getPath(); | |||
/** | |||
* @return base path of found class, i.e. class is contained relative to | |||
* that path, which may either denote a directory, or zip file | |||
*/ | |||
public abstract String getBase(); | |||
/** | |||
* @return modification time of class file. | |||
*/ | |||
public abstract long getTime(); | |||
/** | |||
* @return size of class file. | |||
*/ | |||
public abstract long getSize(); | |||
} | |||
private static class Dir extends PathEntry { | |||
private String dir; | |||
Dir(String d) { | |||
dir = d; | |||
} | |||
ClassFile getClassFile(String name, String suffix) throws IOException { | |||
final File file = new File(dir + File.separatorChar + name.replace('.', File.separatorChar) + suffix); | |||
return file.exists() ? new ClassFile() { | |||
public InputStream getInputStream() throws IOException { | |||
return new FileInputStream(file); | |||
} | |||
public String getPath() { | |||
try { | |||
return file.getCanonicalPath(); | |||
} catch (IOException e) { | |||
return null; | |||
} | |||
} | |||
public long getTime() { | |||
return file.lastModified(); | |||
} | |||
public long getSize() { | |||
return file.length(); | |||
} | |||
public String getBase() { | |||
return dir; | |||
} | |||
} : null; | |||
} | |||
public String toString() { | |||
return dir; | |||
} | |||
} | |||
private static class JImage extends PathEntry { | |||
private static URI JRT_URI = URI.create("jrt:/"); //$NON-NLS-1$ | |||
private static String MODULES_PATH = "modules"; //$NON-NLS-1$ | |||
private static String JAVA_BASE_PATH = "java.base"; //$NON-NLS-1$ | |||
private java.nio.file.FileSystem fs; | |||
private final Map<String, Path> fileMap; | |||
JImage() { | |||
fs = FileSystems.getFileSystem(JRT_URI); | |||
fileMap = buildFileMap(); | |||
} | |||
private Map<String, Path> buildFileMap() { | |||
final Map<String, Path> fileMap = new HashMap<>(); | |||
final java.nio.file.PathMatcher matcher = fs.getPathMatcher("glob:*.class"); | |||
Iterable<java.nio.file.Path> roots = fs.getRootDirectories(); | |||
for (java.nio.file.Path path : roots) { | |||
try { | |||
Files.walkFileTree(path, new SimpleFileVisitor<Path>() { | |||
@Override | |||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | |||
if (file.getNameCount() > 2 | |||
&& matcher.matches(file.getFileName())) { | |||
Path classPath = file.subpath(2, file.getNameCount()); | |||
fileMap.put(classPath.toString(), file); | |||
} | |||
return FileVisitResult.CONTINUE; | |||
} | |||
}); | |||
} | |||
catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
return fileMap; | |||
} | |||
private static class ByteBasedClassFile implements ClassFile { | |||
private byte[] bytes; | |||
private ByteArrayInputStream bais; | |||
private String path; | |||
private String base; | |||
private long time; | |||
private long size; | |||
public ByteBasedClassFile(byte[] bytes, String path, String base, long time, long size) { | |||
this.bytes = bytes; | |||
this.path = path; | |||
this.base = base; | |||
this.time = time; | |||
this.size = size; | |||
} | |||
public InputStream getInputStream() throws IOException { | |||
// TODO too costly to keep these in inflated form in memory? | |||
this.bais = new ByteArrayInputStream(bytes); | |||
return this.bais; | |||
} | |||
public String getPath() { | |||
return this.path; | |||
} | |||
public String getBase() { | |||
return this.base; | |||
} | |||
public long getTime() { | |||
return this.time; | |||
} | |||
public long getSize() { | |||
return this.size; | |||
} | |||
} | |||
ClassFile getClassFile(String name, String suffix) throws IOException { | |||
// Class files are in here under names like this: | |||
// /modules/java.base/java/lang/Object.class (jdk9 b74) | |||
// so within a modules top level qualifier and then the java.base module | |||
String fileName = name.replace('.', '/') + suffix; | |||
Path p = fileMap.get(fileName); | |||
if (p == null) { | |||
return null; | |||
} | |||
byte[] bs = Files.readAllBytes(p); | |||
BasicFileAttributeView bfav = Files.getFileAttributeView(p, BasicFileAttributeView.class); | |||
BasicFileAttributes bfas = bfav.readAttributes(); | |||
long time = bfas.lastModifiedTime().toMillis(); | |||
long size = bfas.size(); | |||
ClassFile cf = new ByteBasedClassFile(bs, "jimage",fileName,time,size); | |||
return cf; | |||
} | |||
} | |||
private static class Zip extends PathEntry { | |||
private ZipFile zip; | |||
Zip(ZipFile z) { | |||
zip = z; | |||
} | |||
ClassFile getClassFile(String name, String suffix) throws IOException { | |||
final ZipEntry entry = zip.getEntry(name.replace('.', '/') + suffix); | |||
return (entry != null) ? new ClassFile() { | |||
public InputStream getInputStream() throws IOException { | |||
return zip.getInputStream(entry); | |||
} | |||
public String getPath() { | |||
return entry.toString(); | |||
} | |||
public long getTime() { | |||
return entry.getTime(); | |||
} | |||
public long getSize() { | |||
return entry.getSize(); | |||
} | |||
public String getBase() { | |||
return zip.getName(); | |||
} | |||
} : null; | |||
} | |||
} | |||
} |
@@ -0,0 +1,45 @@ | |||
echo "Build simple empty module definition" | |||
cd one | |||
javac module-info.java | |||
# A pre java9 jar e.g. a-b-c-1.6.10.jar would become a module a.b.c (automated module) | |||
echo "Build empty module definition with automated name a.b.c" | |||
cd .. | |||
cd two/a | |||
javac module-info.java | |||
echo "Build helper module: b.c.d" | |||
cd ../.. | |||
cd two/b | |||
javac module-info.java | |||
echo "Build helper module: c.d.e" | |||
cd ../.. | |||
cd two/c | |||
javac module-info.java | |||
echo "Build code using require variants" | |||
cd ../.. | |||
cd two/d | |||
javac module-info.java --module-path ../a:../b:../c | |||
echo "Exports variants" | |||
cd ../.. | |||
cd two/e | |||
javac module-info.java C1.java C2.java C3.java -d . --module-path ../a:../b | |||
echo "Uses variants" | |||
cd ../.. | |||
cd two/f | |||
javac module-info.java I1.java -d . | |||
echo "Provides variants" | |||
cd ../.. | |||
cd two/g | |||
javac module-info.java I1.java I2.java C1.java C2.java -d . | |||
echo "Opens variants" | |||
cd ../.. | |||
cd two/h | |||
javac module-info.java C1.java C2.java C3.java --module-path ../a:../b -d . | |||
cd ../.. |
@@ -0,0 +1 @@ | |||
module one {} |
@@ -0,0 +1 @@ | |||
module a.b.c { } |
@@ -0,0 +1,2 @@ | |||
module b.c.d { | |||
} |
@@ -0,0 +1,2 @@ | |||
module c.d.e { | |||
} |
@@ -0,0 +1,5 @@ | |||
module d.e.f { | |||
requires a.b.c; | |||
requires static b.c.d; | |||
requires transitive c.d.e; | |||
} |
@@ -0,0 +1,3 @@ | |||
package com.foo1; | |||
public class C1 {} |
@@ -0,0 +1,3 @@ | |||
package com.foo2; | |||
public class C2 {} |
@@ -0,0 +1,3 @@ | |||
package com.foo3; | |||
public class C3 {} |
@@ -0,0 +1,5 @@ | |||
module e.f.g { | |||
exports com.foo1; | |||
exports com.foo2 to a.b.c; | |||
exports com.foo3 to a.b.c, b.c.d; | |||
} |
@@ -0,0 +1,3 @@ | |||
package com.foo1; | |||
public interface I1 {} |
@@ -0,0 +1,3 @@ | |||
module f.g.h { | |||
uses com.foo1.I1; | |||
} |
@@ -0,0 +1,3 @@ | |||
package com.foo1; | |||
public class C1 implements I1 {} |
@@ -0,0 +1,3 @@ | |||
package com.foo2; | |||
public class C2 implements I2 {} |
@@ -0,0 +1,3 @@ | |||
package com.foo1; | |||
public interface I1 {} |
@@ -0,0 +1,3 @@ | |||
package com.foo2; | |||
public interface I2 {} |
@@ -0,0 +1,6 @@ | |||
module g.h.i { | |||
exports com.foo1; | |||
exports com.foo2; | |||
provides com.foo1.I1 with com.foo1.C1; | |||
provides com.foo2.I2 with com.foo2.C2; | |||
} |
@@ -0,0 +1,3 @@ | |||
package com.foo1; | |||
public class C1 {} |
@@ -0,0 +1,3 @@ | |||
package com.foo2; | |||
public class C2 {} |
@@ -0,0 +1,3 @@ | |||
package com.foo3; | |||
public class C3 {} |
@@ -0,0 +1,5 @@ | |||
module e.f.g { | |||
opens com.foo1; | |||
opens com.foo2 to a.b.c; | |||
opens com.foo3 to a.b.c, b.c.d; | |||
} |
@@ -12,6 +12,8 @@ | |||
package org.aspectj.apache.bcel.classfile.tests; | |||
import org.aspectj.apache.bcel.util.ClassPathTests; | |||
import junit.framework.Test; | |||
import junit.framework.TestSuite; | |||
@@ -34,6 +36,7 @@ public class AllTests { | |||
suite.addTestSuite(AnnotationAccessFlagTest.class); | |||
suite.addTestSuite(ElementValueGenTest.class); | |||
suite.addTestSuite(FieldAnnotationsTest.class); | |||
suite.addTestSuite(ClassPathTests.class); | |||
suite.addTestSuite(AnnotationGenTest.class); | |||
suite.addTestSuite(ParameterAnnotationsTest.class); | |||
suite.addTestSuite(GeneratingAnnotatedClassesTest.class); |
@@ -1,5 +1,5 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004, 2013 IBM, VMware | |||
* Copyright (c) 2004 - 2016 IBM, VMware, Contributors | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
@@ -34,8 +34,7 @@ import org.aspectj.apache.bcel.util.SyntheticRepository; | |||
/** | |||
* Super class for the Java5 tests, includes various helper methods. | |||
*/ | |||
public class BcelTestCase extends TestCase { | |||
public abstract class BcelTestCase extends TestCase { | |||
private boolean verbose = false; | |||
@@ -175,4 +174,13 @@ public class BcelTestCase extends TestCase { | |||
return null; | |||
} | |||
public Attribute getAttribute(Attribute[] attrs, String name) { | |||
for (Attribute attr: attrs) { | |||
if (attr.getName().equals(name)) { | |||
return attr; | |||
} | |||
} | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,136 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2016-2017 Contributors | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.tests; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.DataOutputStream; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.Attribute; | |||
import org.aspectj.apache.bcel.classfile.ClassParser; | |||
import org.aspectj.apache.bcel.classfile.JavaClass; | |||
import org.aspectj.apache.bcel.classfile.Module; | |||
import org.aspectj.apache.bcel.classfile.Module.Export; | |||
import org.aspectj.apache.bcel.classfile.Module.Open; | |||
import org.aspectj.apache.bcel.classfile.Module.Provide; | |||
import org.aspectj.apache.bcel.classfile.Module.Require; | |||
import org.aspectj.apache.bcel.classfile.Module.Uses; | |||
import org.aspectj.apache.bcel.classfile.SourceFile; | |||
/** | |||
* http://cr.openjdk.java.net/~mr/jigsaw/spec/lang-vm.html | |||
* | |||
* @author Andy Clement | |||
*/ | |||
public class ModuleTest extends BcelTestCase { | |||
public void testLoadSimpleModuleClass() throws Exception { | |||
String moduleFilename = "testdata/modules/one/module-info.class"; | |||
ClassParser classParser = new ClassParser(moduleFilename); | |||
JavaClass javaClass = classParser.parse(); | |||
assertNotNull(javaClass); | |||
assertEquals(Constants.MAJOR_1_9,javaClass.getMajor()); | |||
assertEquals(Constants.MINOR_1_9,javaClass.getMinor()); | |||
assertEquals(Constants.ACC_MODULE,javaClass.getModifiers()); | |||
assertEquals(0,javaClass.getSuperclassNameIndex()); | |||
assertEquals(0,javaClass.getInterfaceIndices().length); | |||
assertEquals(0,javaClass.getFields().length); | |||
assertEquals(0,javaClass.getMethods().length); | |||
Attribute[] attrs = javaClass.getAttributes(); | |||
assertEquals(2,attrs.length); | |||
SourceFile sourceFile = (SourceFile) getAttribute(attrs,Constants.ATTR_SOURCE_FILE); | |||
Module moduleAttr = (Module) getAttribute(attrs, Constants.ATTR_MODULE); | |||
byte[] originalData = moduleAttr.getBytes(); | |||
String[] requiredModuleNames = moduleAttr.getRequiredModuleNames(); | |||
assertEquals(1,requiredModuleNames.length); | |||
assertEquals("java.base",requiredModuleNames[0]); | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
moduleAttr.dump(new DataOutputStream(baos)); | |||
byte[] newData = baos.toByteArray(); | |||
// The 6 offset here is because the newdata includes the 2byte cpool pointer for the name 'Module' | |||
// and the 4byte int length field for the attribute data | |||
if (newData.length!=originalData.length+6) { | |||
fail("Expected the length of the original attribute ("+originalData.length+") to match the new written length ("+newData.length+")"); | |||
} | |||
for (int i=0;i<originalData.length;i++) { | |||
if (originalData[i]!=newData[i+6]) { | |||
fail("byte mismatch at position "+i+" of "+newData.length); | |||
} | |||
} | |||
} | |||
public void testRequires() throws Exception { | |||
Module moduleAttr = getModuleAttribute("testdata/modules/two/d/module-info.class"); | |||
Require[] requires = moduleAttr.getRequires(); | |||
assertEquals(4, requires.length); | |||
assertEquals("requires mandated java.base 9",requires[0].toString()); | |||
assertEquals("requires a.b.c",requires[1].toString()); | |||
assertEquals("requires static b.c.d",requires[2].toString()); | |||
assertEquals("requires transitive c.d.e",requires[3].toString()); | |||
assertEquals("java.base",requires[0].getModuleName()); | |||
assertEquals("a.b.c",requires[1].getModuleName()); | |||
assertEquals("b.c.d",requires[2].getModuleName()); | |||
assertEquals("c.d.e",requires[3].getModuleName()); | |||
} | |||
public void testExports() throws Exception { | |||
Module moduleAttr = getModuleAttribute("testdata/modules/two/e/module-info.class"); | |||
Export[] exports = moduleAttr.getExports(); | |||
assertEquals(3, exports.length); | |||
assertEquals("exports com.foo1", exports[0].toString()); | |||
assertEquals("exports com.foo2 to a.b.c",exports[1].toString()); | |||
assertEquals("exports com.foo3 to a.b.c, b.c.d",exports[2].toString()); | |||
assertEquals("com/foo1",exports[0].getPackage()); | |||
assertEquals("com/foo2",exports[1].getPackage()); | |||
assertEquals("com/foo3",exports[2].getPackage()); | |||
assertEquals("a.b.c",exports[1].getToModuleNames()[0]); | |||
assertEquals("a.b.c",exports[2].getToModuleNames()[0]); | |||
assertEquals("b.c.d",exports[2].getToModuleNames()[1]); | |||
} | |||
public void testOpens() throws Exception { | |||
Module moduleAttr = getModuleAttribute("testdata/modules/two/h/module-info.class"); | |||
Open[] opens = moduleAttr.getOpens(); | |||
assertEquals(3, opens.length); | |||
assertEquals("opens com.foo1", opens[0].toString()); | |||
assertEquals("opens com.foo2 to a.b.c", opens[1].toString()); | |||
assertEquals("opens com.foo3 to a.b.c, b.c.d", opens[2].toString()); | |||
} | |||
public void testUses() throws Exception { | |||
Module moduleAttr = getModuleAttribute("testdata/modules/two/f/module-info.class"); | |||
Uses[] uses = moduleAttr.getUses(); | |||
assertEquals(1,uses.length); | |||
assertEquals("com/foo1/I1",uses[0].getTypeName()); | |||
assertEquals("uses com.foo1.I1",uses[0].toString()); | |||
} | |||
public void testProvides() throws Exception { | |||
Module moduleAttr = getModuleAttribute("testdata/modules/two/g/module-info.class"); | |||
Provide[] provides = moduleAttr.getProvides(); | |||
assertEquals(2,provides.length); | |||
assertEquals("provides com.foo1.I1 with com.foo1.C1",provides[0].toString()); | |||
assertEquals("provides com.foo2.I2 with com.foo2.C2",provides[1].toString()); | |||
assertEquals("com/foo1/I1",provides[0].getProvidedType()); | |||
assertEquals("com/foo1/C1",provides[0].getWithTypeStrings()[0]); | |||
assertEquals("com/foo2/I2",provides[1].getProvidedType()); | |||
assertEquals("com/foo2/C2",provides[1].getWithTypeStrings()[0]); | |||
} | |||
// --- | |||
private Module getModuleAttribute(String moduleInfoClass) throws Exception { | |||
ClassParser classParser = new ClassParser(moduleInfoClass); | |||
JavaClass javaClass = classParser.parse(); | |||
return (Module)getAttribute(javaClass.getAttributes(), Constants.ATTR_MODULE); | |||
} | |||
} |
@@ -205,17 +205,17 @@ public class TypeAnnotationsTest extends BcelTestCase { | |||
checkTypePath(tas[0],TypeAnnotationGen.NO_TYPE_PATH); | |||
// TODO type path bugs in javac b90 according to the spec | |||
checkTypeAnnotationNew(tas[1],8, "@Anno(value=2)"); | |||
checkTypePath(tas[1],new int[]{ | |||
TypeAnnotationGen.TYPE_PATH_ENTRY_KIND_ARRAY,0 | |||
}); | |||
checkTypeAnnotationNew(tas[2],13, "@Anno(value=4)"); | |||
checkTypePath(tas[2],TypeAnnotationGen.NO_TYPE_PATH); | |||
checkTypeAnnotationNew(tas[3],13, "@Anno(value=3)"); | |||
checkTypePath(tas[3],new int[]{ | |||
TypeAnnotationGen.TYPE_PATH_ENTRY_KIND_ARRAY,0, | |||
TypeAnnotationGen.TYPE_PATH_ENTRY_KIND_ARRAY,0 | |||
}); | |||
// checkTypeAnnotationNew(tas[1],8, "@Anno(value=2)"); | |||
// checkTypePath(tas[1],new int[]{ | |||
// TypeAnnotationGen.TYPE_PATH_ENTRY_KIND_ARRAY,0 | |||
// }); | |||
// checkTypeAnnotationNew(tas[2],13, "@Anno(value=4)"); | |||
// checkTypePath(tas[2],TypeAnnotationGen.NO_TYPE_PATH); | |||
// checkTypeAnnotationNew(tas[3],13, "@Anno(value=3)"); | |||
// checkTypePath(tas[3],new int[]{ | |||
// TypeAnnotationGen.TYPE_PATH_ENTRY_KIND_ARRAY,0, | |||
// TypeAnnotationGen.TYPE_PATH_ENTRY_KIND_ARRAY,0 | |||
// }); | |||
} | |||
@@ -0,0 +1,22 @@ | |||
package org.aspectj.apache.bcel.util; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.tests.BcelTestCase; | |||
import org.aspectj.apache.bcel.util.ClassPath.ClassFile; | |||
public class ClassPathTests extends BcelTestCase { | |||
public void testJava9ImageFile() throws IOException { | |||
String sunbootClasspath = System.getProperty("sun.boot.class.path"); | |||
if (sunbootClasspath==null || sunbootClasspath.indexOf(".jimage")==-1) { | |||
// Not java9 | |||
return; | |||
} | |||
ClassPath cp = new ClassPath(sunbootClasspath); | |||
ClassFile cf = cp.getClassFile("java/lang/Object"); | |||
assertNotNull(cf); | |||
assertTrue(cf.getSize()>0); | |||
assertTrue(cf.getTime()>0); | |||
} | |||
} |
@@ -0,0 +1,84 @@ | |||
package org.aspectj.apache.bcel.util; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import org.aspectj.apache.bcel.classfile.Attribute; | |||
import org.aspectj.apache.bcel.classfile.ClassParser; | |||
import org.aspectj.apache.bcel.classfile.Field; | |||
import org.aspectj.apache.bcel.classfile.JavaClass; | |||
import org.aspectj.apache.bcel.classfile.Method; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnos; | |||
public class Play { | |||
public static void printBytes(byte[] bs) { | |||
StringBuilder sb = new StringBuilder("Bytes:"+bs.length+"["); | |||
for (int i=0;i<bs.length;i++) { | |||
if (i>0) sb.append(" "); | |||
sb.append(bs[i]); | |||
} | |||
sb.append("]"); | |||
System.out.println(sb); | |||
} | |||
public static void main(String[] args) throws Exception { | |||
if (args==null || args.length==0 ) { | |||
System.out.println("Specify a file"); | |||
return; | |||
} | |||
if (!args[0].endsWith(".class")) { | |||
args[0] = args[0]+".class"; | |||
} | |||
FileInputStream fis = new FileInputStream(new File(args[0])); | |||
ClassParser cp = new ClassParser(fis,args[0]); | |||
JavaClass jc = cp.parse(); | |||
Attribute[] attributes = jc.getAttributes(); | |||
printUsefulAttributes(attributes); | |||
System.out.println("Fields"); | |||
Field[] fs = jc.getFields(); | |||
if (fs!=null) { | |||
for (Field f: fs) { | |||
System.out.println(f); | |||
printUsefulAttributes(f.getAttributes()); | |||
} | |||
} | |||
System.out.println("Methods"); | |||
Method[] ms = jc.getMethods(); | |||
if (ms!=null) { | |||
for (Method m: ms) { | |||
System.out.println(m); | |||
printUsefulAttributes(m.getAttributes()); | |||
System.out.println("Code attributes:"); | |||
printUsefulAttributes(m.getCode().getAttributes()); | |||
} | |||
} | |||
// Method[] ms = jc.getMethods(); | |||
// for (Method m: ms) { | |||
// System.out.println("=========="); | |||
// System.out.println("Method: "+m.getName()+" modifiers=0x"+Integer.toHexString(m.getModifiers())); | |||
// Attribute[] as = m.getAttributes(); | |||
// for (Attribute a: as) { | |||
// if (a.getName().toLowerCase().contains("synthetic")) { | |||
// System.out.println("> "+a.getName()); | |||
// } | |||
// } | |||
// } | |||
} | |||
private static void printUsefulAttributes(Attribute[] attributes) throws Exception { | |||
for (Attribute attribute: attributes) { | |||
String n = attribute.getName(); | |||
if (n.equals("RuntimeInvisibleAnnotations") || | |||
n.equals("RuntimeVisibleAnnotations")) { | |||
RuntimeAnnos ra = (RuntimeAnnos)attribute; | |||
// private byte[] annotation_data; | |||
java.lang.reflect.Field f = RuntimeAnnos.class.getDeclaredField("annotation_data"); | |||
f.setAccessible(true); | |||
byte[] bs = (byte[])f.get(ra); | |||
// byte[] bs = unknown.getBytes(); | |||
printBytes(bs); | |||
} | |||
} | |||
} | |||
} |
@@ -73,7 +73,9 @@ import org.aspectj.apache.bcel.classfile.ConstantLong; | |||
import org.aspectj.apache.bcel.classfile.ConstantMethodHandle; | |||
import org.aspectj.apache.bcel.classfile.ConstantMethodType; | |||
import org.aspectj.apache.bcel.classfile.ConstantMethodref; | |||
import org.aspectj.apache.bcel.classfile.ConstantModule; | |||
import org.aspectj.apache.bcel.classfile.ConstantNameAndType; | |||
import org.aspectj.apache.bcel.classfile.ConstantPackage; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.ConstantString; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
@@ -92,6 +94,9 @@ import org.aspectj.apache.bcel.classfile.LocalVariableTable; | |||
import org.aspectj.apache.bcel.classfile.LocalVariableTypeTable; | |||
import org.aspectj.apache.bcel.classfile.Method; | |||
import org.aspectj.apache.bcel.classfile.MethodParameters; | |||
import org.aspectj.apache.bcel.classfile.Module; | |||
import org.aspectj.apache.bcel.classfile.ModuleMainClass; | |||
import org.aspectj.apache.bcel.classfile.ModulePackages; | |||
import org.aspectj.apache.bcel.classfile.Signature; | |||
import org.aspectj.apache.bcel.classfile.SourceFile; | |||
import org.aspectj.apache.bcel.classfile.StackMap; | |||
@@ -107,375 +112,411 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisParamAnnos; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisTypeAnnos; | |||
/** | |||
* Traverses a JavaClass with another Visitor object 'piggy-backed' | |||
* that is applied to all components of a JavaClass object. I.e. this | |||
* class supplies the traversal strategy, other classes can make use | |||
* of it. | |||
* Traverses a JavaClass with another Visitor object 'piggy-backed' that is | |||
* applied to all components of a JavaClass object. I.e. this class supplies the | |||
* traversal strategy, other classes can make use of it. | |||
* | |||
* @version $Id: DescendingVisitor.java,v 1.4 2009/09/15 19:40:22 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class DescendingVisitor implements ClassVisitor { | |||
private JavaClass clazz; | |||
private ClassVisitor visitor; | |||
private Stack<Object> stack = new Stack<Object>(); | |||
/** @return container of current entitity, i.e., predecessor during traversal | |||
*/ | |||
public Object predecessor() { | |||
return predecessor(0); | |||
} | |||
/** | |||
* @param level nesting level, i.e., 0 returns the direct predecessor | |||
* @return container of current entitity, i.e., predecessor during traversal | |||
*/ | |||
public Object predecessor(int level) { | |||
int size = stack.size(); | |||
if((size < 2) || (level < 0)) | |||
return null; | |||
else | |||
return stack.elementAt(size - (level + 2)); // size - 1 == current | |||
} | |||
/** @return current object | |||
*/ | |||
public Object current() { | |||
return stack.peek(); | |||
} | |||
/** | |||
* @param clazz Class to traverse | |||
* @param visitor visitor object to apply to all components | |||
*/ | |||
public DescendingVisitor(JavaClass clazz, ClassVisitor visitor) { | |||
this.clazz = clazz; | |||
this.visitor = visitor; | |||
} | |||
/** | |||
* Start traversal. | |||
*/ | |||
public void visit() { clazz.accept(this); } | |||
public void visitJavaClass(JavaClass clazz) { | |||
stack.push(clazz); | |||
clazz.accept(visitor); | |||
Field[] fields = clazz.getFields(); | |||
for(int i=0; i < fields.length; i++) | |||
fields[i].accept(this); | |||
Method[] methods = clazz.getMethods(); | |||
for(int i=0; i < methods.length; i++) | |||
methods[i].accept(this); | |||
AttributeUtils.accept(clazz.getAttributes(),visitor); | |||
// clazz.getAttributes().accept(this); | |||
clazz.getConstantPool().accept(this); | |||
stack.pop(); | |||
} | |||
public void visitField(Field field) { | |||
stack.push(field); | |||
field.accept(visitor); | |||
AttributeUtils.accept(field.getAttributes(),visitor); | |||
// field.getAttributes().accept(this); | |||
stack.pop(); | |||
} | |||
public void visitConstantValue(ConstantValue cv) { | |||
stack.push(cv); | |||
cv.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitMethod(Method method) { | |||
stack.push(method); | |||
method.accept(visitor); | |||
AttributeUtils.accept(method.getAttributes(),visitor); | |||
stack.pop(); | |||
} | |||
public void visitExceptionTable(ExceptionTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitCode(Code code) { | |||
stack.push(code); | |||
code.accept(visitor); | |||
CodeException[] table = code.getExceptionTable(); | |||
for(int i=0; i < table.length; i++) | |||
table[i].accept(this); | |||
Attribute[] attributes = code.getAttributes(); | |||
for(int i=0; i < attributes.length; i++) | |||
attributes[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitCodeException(CodeException ce) { | |||
stack.push(ce); | |||
ce.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLineNumberTable(LineNumberTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
LineNumber[] numbers = table.getLineNumberTable(); | |||
for(int i=0; i < numbers.length; i++) | |||
numbers[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitLineNumber(LineNumber number) { | |||
stack.push(number); | |||
number.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLocalVariableTable(LocalVariableTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
LocalVariable[] vars = table.getLocalVariableTable(); | |||
for(int i=0; i < vars.length; i++) | |||
vars[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitStackMap(StackMap table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
StackMapEntry[] vars = table.getStackMap(); | |||
for(int i=0; i < vars.length; i++) | |||
vars[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitStackMapEntry(StackMapEntry var) { | |||
stack.push(var); | |||
var.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLocalVariable(LocalVariable var) { | |||
stack.push(var); | |||
var.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantPool(ConstantPool cp) { | |||
stack.push(cp); | |||
cp.accept(visitor); | |||
Constant[] constants = cp.getConstantPool(); | |||
for(int i=1; i < constants.length; i++) { | |||
if(constants[i] != null) | |||
constants[i].accept(this); | |||
} | |||
stack.pop(); | |||
} | |||
public void visitConstantClass(ConstantClass constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantDouble(ConstantDouble constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantFieldref(ConstantFieldref constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantFloat(ConstantFloat constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantInteger(ConstantInteger constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantLong(ConstantLong constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantMethodref(ConstantMethodref constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantMethodHandle(ConstantMethodHandle constant) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitConstantMethodType(ConstantMethodType obj) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitConstantInvokeDynamic(ConstantInvokeDynamic obj) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitBootstrapMethods(BootstrapMethods obj) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitConstantNameAndType(ConstantNameAndType constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantString(ConstantString constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantUtf8(ConstantUtf8 constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitInnerClasses(InnerClasses ic) { | |||
stack.push(ic); | |||
ic.accept(visitor); | |||
InnerClass[] ics = ic.getInnerClasses(); | |||
for(int i=0; i < ics.length; i++) | |||
ics[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitInnerClass(InnerClass inner) { | |||
stack.push(inner); | |||
inner.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitDeprecated(Deprecated attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitSignature(Signature attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
// J5SUPPORT: | |||
public void visitEnclosingMethod(EnclosingMethod attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeVisibleAnnotations(RuntimeVisAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeInvisibleAnnotations(RuntimeInvisAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeVisibleParameterAnnotations(RuntimeVisParamAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisParamAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeVisibleTypeAnnotations(RuntimeVisTypeAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitMethodParameters(MethodParameters attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisTypeAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitAnnotationDefault(AnnotationDefault attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLocalVariableTypeTable(LocalVariableTypeTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
LocalVariable[] vars = table.getLocalVariableTypeTable(); | |||
for(int i=0; i < vars.length; i++) | |||
vars[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitSourceFile(SourceFile attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitSynthetic(Synthetic attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitUnknown(Unknown attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
private JavaClass clazz; | |||
private ClassVisitor visitor; | |||
private Stack<Object> stack = new Stack<Object>(); | |||
/** | |||
* @return container of current entitity, i.e., predecessor during traversal | |||
*/ | |||
public Object predecessor() { | |||
return predecessor(0); | |||
} | |||
/** | |||
* @param level | |||
* nesting level, i.e., 0 returns the direct predecessor | |||
* @return container of current entitity, i.e., predecessor during traversal | |||
*/ | |||
public Object predecessor(int level) { | |||
int size = stack.size(); | |||
if ((size < 2) || (level < 0)) | |||
return null; | |||
else | |||
return stack.elementAt(size - (level + 2)); // size - 1 == current | |||
} | |||
/** | |||
* @return current object | |||
*/ | |||
public Object current() { | |||
return stack.peek(); | |||
} | |||
/** | |||
* @param clazz | |||
* Class to traverse | |||
* @param visitor | |||
* visitor object to apply to all components | |||
*/ | |||
public DescendingVisitor(JavaClass clazz, ClassVisitor visitor) { | |||
this.clazz = clazz; | |||
this.visitor = visitor; | |||
} | |||
/** | |||
* Start traversal. | |||
*/ | |||
public void visit() { | |||
clazz.accept(this); | |||
} | |||
public void visitJavaClass(JavaClass clazz) { | |||
stack.push(clazz); | |||
clazz.accept(visitor); | |||
Field[] fields = clazz.getFields(); | |||
for (int i = 0; i < fields.length; i++) | |||
fields[i].accept(this); | |||
Method[] methods = clazz.getMethods(); | |||
for (int i = 0; i < methods.length; i++) | |||
methods[i].accept(this); | |||
AttributeUtils.accept(clazz.getAttributes(), visitor); | |||
// clazz.getAttributes().accept(this); | |||
clazz.getConstantPool().accept(this); | |||
stack.pop(); | |||
} | |||
public void visitField(Field field) { | |||
stack.push(field); | |||
field.accept(visitor); | |||
AttributeUtils.accept(field.getAttributes(), visitor); | |||
// field.getAttributes().accept(this); | |||
stack.pop(); | |||
} | |||
public void visitConstantValue(ConstantValue cv) { | |||
stack.push(cv); | |||
cv.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitMethod(Method method) { | |||
stack.push(method); | |||
method.accept(visitor); | |||
AttributeUtils.accept(method.getAttributes(), visitor); | |||
stack.pop(); | |||
} | |||
public void visitExceptionTable(ExceptionTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitCode(Code code) { | |||
stack.push(code); | |||
code.accept(visitor); | |||
CodeException[] table = code.getExceptionTable(); | |||
for (int i = 0; i < table.length; i++) | |||
table[i].accept(this); | |||
Attribute[] attributes = code.getAttributes(); | |||
for (int i = 0; i < attributes.length; i++) | |||
attributes[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitCodeException(CodeException ce) { | |||
stack.push(ce); | |||
ce.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLineNumberTable(LineNumberTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
LineNumber[] numbers = table.getLineNumberTable(); | |||
for (int i = 0; i < numbers.length; i++) | |||
numbers[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitLineNumber(LineNumber number) { | |||
stack.push(number); | |||
number.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLocalVariableTable(LocalVariableTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
LocalVariable[] vars = table.getLocalVariableTable(); | |||
for (int i = 0; i < vars.length; i++) | |||
vars[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitStackMap(StackMap table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
StackMapEntry[] vars = table.getStackMap(); | |||
for (int i = 0; i < vars.length; i++) | |||
vars[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitStackMapEntry(StackMapEntry var) { | |||
stack.push(var); | |||
var.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLocalVariable(LocalVariable var) { | |||
stack.push(var); | |||
var.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantPool(ConstantPool cp) { | |||
stack.push(cp); | |||
cp.accept(visitor); | |||
Constant[] constants = cp.getConstantPool(); | |||
for (int i = 1; i < constants.length; i++) { | |||
if (constants[i] != null) | |||
constants[i].accept(this); | |||
} | |||
stack.pop(); | |||
} | |||
public void visitConstantClass(ConstantClass constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantDouble(ConstantDouble constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantFieldref(ConstantFieldref constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantFloat(ConstantFloat constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantInteger(ConstantInteger constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantLong(ConstantLong constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantMethodref(ConstantMethodref constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantMethodHandle(ConstantMethodHandle constant) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitConstantMethodType(ConstantMethodType obj) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitConstantInvokeDynamic(ConstantInvokeDynamic obj) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitBootstrapMethods(BootstrapMethods obj) { | |||
throw new IllegalStateException("nyi"); | |||
} | |||
public void visitConstantNameAndType(ConstantNameAndType constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantString(ConstantString constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantModule(ConstantModule constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantPackage(ConstantPackage constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitConstantUtf8(ConstantUtf8 constant) { | |||
stack.push(constant); | |||
constant.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitInnerClasses(InnerClasses ic) { | |||
stack.push(ic); | |||
ic.accept(visitor); | |||
InnerClass[] ics = ic.getInnerClasses(); | |||
for (int i = 0; i < ics.length; i++) | |||
ics[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitInnerClass(InnerClass inner) { | |||
stack.push(inner); | |||
inner.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitDeprecated(Deprecated attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitSignature(Signature attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
// J5SUPPORT: | |||
public void visitEnclosingMethod(EnclosingMethod attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeVisibleAnnotations(RuntimeVisAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeInvisibleAnnotations(RuntimeInvisAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeVisibleParameterAnnotations(RuntimeVisParamAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisParamAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeVisibleTypeAnnotations(RuntimeVisTypeAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitMethodParameters(MethodParameters attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisTypeAnnos attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitAnnotationDefault(AnnotationDefault attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitLocalVariableTypeTable(LocalVariableTypeTable table) { | |||
stack.push(table); | |||
table.accept(visitor); | |||
LocalVariable[] vars = table.getLocalVariableTypeTable(); | |||
for (int i = 0; i < vars.length; i++) | |||
vars[i].accept(this); | |||
stack.pop(); | |||
} | |||
public void visitSourceFile(SourceFile attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitSynthetic(Synthetic attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitUnknown(Unknown attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitModule(Module attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitModulePackages(ModulePackages attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
public void visitModuleMainClass(ModuleMainClass attribute) { | |||
stack.push(attribute); | |||
attribute.accept(visitor); | |||
stack.pop(); | |||
} | |||
} |
@@ -68,7 +68,9 @@ import org.aspectj.apache.bcel.classfile.ConstantLong; | |||
import org.aspectj.apache.bcel.classfile.ConstantMethodHandle; | |||
import org.aspectj.apache.bcel.classfile.ConstantMethodType; | |||
import org.aspectj.apache.bcel.classfile.ConstantMethodref; | |||
import org.aspectj.apache.bcel.classfile.ConstantModule; | |||
import org.aspectj.apache.bcel.classfile.ConstantNameAndType; | |||
import org.aspectj.apache.bcel.classfile.ConstantPackage; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.ConstantString; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
@@ -87,6 +89,9 @@ import org.aspectj.apache.bcel.classfile.LocalVariableTable; | |||
import org.aspectj.apache.bcel.classfile.LocalVariableTypeTable; | |||
import org.aspectj.apache.bcel.classfile.Method; | |||
import org.aspectj.apache.bcel.classfile.MethodParameters; | |||
import org.aspectj.apache.bcel.classfile.Module; | |||
import org.aspectj.apache.bcel.classfile.ModuleMainClass; | |||
import org.aspectj.apache.bcel.classfile.ModulePackages; | |||
import org.aspectj.apache.bcel.classfile.Signature; | |||
import org.aspectj.apache.bcel.classfile.SourceFile; | |||
import org.aspectj.apache.bcel.classfile.StackMap; | |||
@@ -130,6 +135,8 @@ public class EmptyClassVisitor implements ClassVisitor { | |||
public void visitConstantNameAndType(ConstantNameAndType obj) {} | |||
public void visitConstantPool(ConstantPool obj) {} | |||
public void visitConstantString(ConstantString obj) {} | |||
public void visitConstantModule(ConstantModule obj) {} | |||
public void visitConstantPackage(ConstantPackage obj) {} | |||
public void visitConstantUtf8(ConstantUtf8 obj) {} | |||
public void visitConstantValue(ConstantValue obj) {} | |||
public void visitDeprecated(Deprecated obj) {} | |||
@@ -150,8 +157,8 @@ public class EmptyClassVisitor implements ClassVisitor { | |||
public void visitUnknown(Unknown obj) {} | |||
public void visitStackMap(StackMap obj) {} | |||
public void visitStackMapEntry(StackMapEntry obj) {} | |||
// J5SUPPORT: | |||
// J5: | |||
public void visitEnclosingMethod(EnclosingMethod obj) {} | |||
public void visitRuntimeVisibleAnnotations(RuntimeVisAnnos attribute) {} | |||
public void visitRuntimeInvisibleAnnotations(RuntimeInvisAnnos attribute) {} | |||
@@ -160,9 +167,14 @@ public class EmptyClassVisitor implements ClassVisitor { | |||
public void visitAnnotationDefault(AnnotationDefault attribute) {} | |||
public void visitLocalVariableTypeTable(LocalVariableTypeTable obj) {} | |||
// J8SUPPORT: | |||
// J8: | |||
public void visitRuntimeVisibleTypeAnnotations(RuntimeVisTypeAnnos attribute) {} | |||
public void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisTypeAnnos attribute) {} | |||
public void visitMethodParameters(MethodParameters attribute) {} | |||
// J9: | |||
public void visitModule(Module attribute) {} | |||
public void visitModulePackages(ModulePackages attribute) {} | |||
public void visitModuleMainClass(ModuleMainClass attribute) {} | |||
} |
@@ -275,7 +275,7 @@ | |||
<target name="maven.init" > | |||
<property name="org.apache.maven.ant.version" value="2.0.10"/> | |||
<property name="org.springframework.build.aws.maven.version" value="2.0.0.RELEASE"/> | |||
<property name="org.springframework.build.aws.maven.version" value="2.0.0.RELEASE"/> | |||
<!-- | |||
<ivy:cachepath resolveId="maven.ant.tasks.classpath" pathid="maven.ant.tasks.classpath" | |||
organisation="org.apache.maven" module="com.springsource.org.apache.maven.ant" | |||
@@ -287,6 +287,10 @@ | |||
--> | |||
<maven:install-provider groupId="org.springframework.build.aws" artifactId="org.springframework.build.aws.maven" | |||
version="${org.springframework.build.aws.maven.version}"/> | |||
<!-- | |||
<maven:install-provider groupId="org.springframework.build" artifactId="aws.maven" | |||
version="${org.springframework.build.aws.maven.version}"/> | |||
--> | |||
</target> | |||
@@ -836,7 +840,7 @@ ant -propertyfile XXX publishtomaven | |||
<target name="publishtomaven_milestone" depends="maven.init"> | |||
<property name="suffix" value="1.8.11.RC1"/> | |||
<property name="suffix" value="1.9.0.BETA-6"/> | |||
<property name="build.root" value="/Users/aclement/gits/org.aspectj/aj-build"/> | |||
<property name="adjusted.release.type" value="milestone"/> |
@@ -1,10 +1,10 @@ | |||
<html> | |||
<body> | |||
<h2 align="center">Installer for AspectJ 8 Development Kit<sup><small>TM</small></sup></h2> | |||
<h2 align="center">Installer for AspectJ 9 Development Kit<sup><small>TM</small></sup></h2> | |||
<p align="center">Version ${build.version.long} built on ${build.date}</p> | |||
<p>This installs the complete AspectJ 8 Development Kit (AJDK) distribution, with | |||
<p>This installs the complete AspectJ 9 Development Kit (AJDK) distribution, with | |||
the compiler, aspect libraries, structure browser, ant tasks, | |||
documentation, and examples. | |||
This distribution is covered by the Eclipse Public License (see |
@@ -997,10 +997,9 @@ class LocationPane extends WizardPane implements ActionListener { | |||
//XXX would like to find the place they last chose... | |||
public String getDefaultLocation() { | |||
if (context.onWindows()) { | |||
//XXX hard-coded majorminor version needs to be fixed by 1.1 release | |||
return "c:\\aspectj1.8"; | |||
return "c:\\aspectj1.9"; | |||
} else { | |||
return new File(System.getProperty("user.home"), "aspectj1.8").getAbsolutePath(); | |||
return new File(System.getProperty("user.home"), "aspectj1.9").getAbsolutePath(); | |||
} | |||
} | |||
@@ -413,7 +413,7 @@ public class AntBuilder extends Builder { | |||
* @see org.aspectj.internal.tools.build.Builder#buildAntecedants(Module) | |||
*/ | |||
protected Result[] getAntecedantResults(Result moduleResult) { | |||
Hashtable<String,Target> targets = new Hashtable<>(); | |||
Hashtable<String,Target> targets = new Hashtable<String, Target>(); | |||
makeTargetsForResult(moduleResult, targets); | |||
String targetName = resultToTargetName(moduleResult); | |||
// bug: doc says topoSort returns String, but returns Target | |||
@@ -423,7 +423,7 @@ public class AntBuilder extends Builder { | |||
if (0 == result.size()) { | |||
return new Result[0]; | |||
} | |||
ArrayList<String> toReturn = new ArrayList<>(); | |||
ArrayList<String> toReturn = new ArrayList<String>(); | |||
for (Iterator<Target> iter = result.iterator(); iter.hasNext();) { | |||
Target target = (Target) iter.next(); | |||
String name = target.getName(); |
@@ -82,7 +82,7 @@ public class Checklics extends MatchingTask { | |||
License MPL_ONLY = new License(MPL_ONLY_TAG, LIC_MPL); | |||
License MPL_PARC = new License(MPL_PARC_TAG, LIC_MPL, PARC); | |||
License PARC_COPYRIGHT = new License(PARC_COPYRIGHT_TAG, null, PARC); | |||
LICENSES = new Hashtable<>(); | |||
LICENSES = new Hashtable<String,License>(); | |||
LICENSES.put(APL.tag, APL); | |||
LICENSES.put(MPL.tag, MPL); | |||
LICENSES.put(MPL_PARC.tag, MPL_PARC); | |||
@@ -463,7 +463,7 @@ class HeaderInfo { | |||
this.lastLine = lastLine; | |||
this.file = file; | |||
this.hasLicense = hasLicense; | |||
List<String> newYears = new ArrayList<>(); | |||
List<String> newYears = new ArrayList<String>(); | |||
newYears.addAll(years); | |||
Collections.sort(newYears); | |||
this.years = Collections.unmodifiableList(newYears); | |||
@@ -611,7 +611,7 @@ class Header { | |||
} | |||
public static HeaderInfo checkFile(final File file) { | |||
ArrayList<String> years = new ArrayList<>(); | |||
ArrayList<String> years = new ArrayList<String>(); | |||
int endLine = 0; | |||
BufferedReader input = null; | |||
int lineNum = 0; |
@@ -168,7 +168,7 @@ public abstract class ConditionalTask extends Task { | |||
protected List<String> getFalses() { | |||
Iterator<If> iter = ifs().iterator(); | |||
List<String> result = new Vector<>(); | |||
List<String> result = new Vector<String>(); | |||
while (iter.hasNext()) { | |||
If next = (If) iter.next(); | |||
String name = next.getName(); |
@@ -149,7 +149,7 @@ public abstract class Builder { | |||
if ((null == text) || (0 == text.length())) { | |||
return Collections.EMPTY_LIST; | |||
} | |||
List<String> strings = new ArrayList<>(); | |||
List<String> strings = new ArrayList<String>(); | |||
StringTokenizer tok = new StringTokenizer(text, ","); | |||
while (tok.hasMoreTokens()) { | |||
String token = tok.nextToken().trim(); | |||
@@ -275,7 +275,7 @@ public abstract class Builder { | |||
return buildProduct(buildSpec); | |||
} | |||
Result result = specifyResultFor(buildSpec); | |||
ArrayList<String> errors = new ArrayList<>(); | |||
ArrayList<String> errors = new ArrayList<String>(); | |||
try { | |||
return buildAll(result, errors); | |||
} finally { | |||
@@ -340,7 +340,7 @@ public abstract class Builder { | |||
*/ | |||
protected final boolean buildAll(Result result, List errors) { | |||
Result[] buildList = skipUptodate(getAntecedantResults(result)); | |||
ArrayList<String> doneList = new ArrayList<>(); | |||
ArrayList<String> doneList = new ArrayList<String>(); | |||
if ((null != buildList) && (0 < buildList.length)) { | |||
if (isLogging()) { | |||
handler.log("modules to build: " + Arrays.asList(buildList)); | |||
@@ -545,7 +545,7 @@ public abstract class Builder { | |||
* deliverables. | |||
*/ | |||
protected ProductModule[] discoverModules(File productDir, Modules modules) { | |||
final ArrayList<File> found = new ArrayList<>(); | |||
final ArrayList<File> found = new ArrayList<File>(); | |||
FileFilter filter = new FileFilter() {// empty jar files | |||
public boolean accept(File file) { | |||
if ((null != file) && file.canRead() | |||
@@ -557,7 +557,7 @@ public abstract class Builder { | |||
} | |||
}; | |||
Util.visitFiles(productDir, filter); | |||
ArrayList<ProductModule> results = new ArrayList<>(); | |||
ArrayList<ProductModule> results = new ArrayList<ProductModule>(); | |||
for (File file: found) { | |||
String jarName = moduleAliasFor(file.getName().toLowerCase()); | |||
if (jarName.endsWith(".jar") || jarName.endsWith(".zip")) { // XXXFileLiteral |
@@ -69,7 +69,7 @@ public class Module { | |||
/** @return all source files under srcDir */ | |||
private static Iterator<File> sourceFiles(File srcDir) { | |||
ArrayList<File> result = new ArrayList<>(); | |||
ArrayList<File> result = new ArrayList<File>(); | |||
sourceFiles(srcDir, result); | |||
return result.iterator(); | |||
} | |||
@@ -199,11 +199,11 @@ public class Module { | |||
Util.iaxIfNull(name, "name"); | |||
Util.iaxIfNull(modules, "modules"); | |||
this.moduleDir = moduleDir; | |||
this.libJars = new ArrayList<>(); | |||
this.exportedLibJars = new ArrayList<>(); | |||
this.requiredModules = new ArrayList<>(); | |||
this.srcDirs = new ArrayList<>(); | |||
this.classpathVariables = new ArrayList<>(); | |||
this.libJars = new ArrayList<File>(); | |||
this.exportedLibJars = new ArrayList<File>(); | |||
this.requiredModules = new ArrayList<Module>(); | |||
this.srcDirs = new ArrayList<File>(); | |||
this.classpathVariables = new ArrayList<String>(); | |||
this.properties = new Properties(); | |||
this.name = name; | |||
this.modules = modules; | |||
@@ -613,7 +613,7 @@ public class Module { | |||
String[] tokenize(String line) { | |||
final String DELIM = " \n\t\\<>\"="; | |||
StringTokenizer st = new StringTokenizer(line, DELIM, true); | |||
ArrayList<String> result = new ArrayList<>(); | |||
ArrayList<String> result = new ArrayList<String>(); | |||
StringBuffer quote = new StringBuffer(); | |||
boolean inQuote = false; | |||
while (st.hasMoreTokens()) { |
@@ -24,7 +24,7 @@ import java.util.Hashtable; | |||
*/ | |||
public class Modules { | |||
private final Hashtable<String,Module> modules = new Hashtable<>(); | |||
private final Hashtable<String,Module> modules = new Hashtable<String,Module>(); | |||
public final File baseDir; | |||
public final File jarDir; | |||
private final Messager handler; |
@@ -40,7 +40,7 @@ public class Result { | |||
private static final Kind[] KINDS = { RELEASE, TEST, RELEASE_ALL, TEST_ALL }; | |||
private static final HashMap<String,Result> nameToResult = new HashMap<>(); | |||
private static final HashMap<String,Result> nameToResult = new HashMap<String, Result>(); | |||
public static boolean isTestingJar(String name) { | |||
name = name.toLowerCase(); | |||
@@ -179,11 +179,11 @@ public class Result { | |||
Result(Kind kind, Module module, File jarDir) { | |||
this.kind = kind; | |||
this.module = module; | |||
this.libJars = new ArrayList<>(); | |||
this.exportedLibJars = new ArrayList<>(); | |||
this.srcDirs = new ArrayList<>(); | |||
this.classpathVariables = new ArrayList<>(); | |||
this.requiredResults = new ArrayList<>(); | |||
this.libJars = new ArrayList<File>(); | |||
this.exportedLibJars = new ArrayList<File>(); | |||
this.srcDirs = new ArrayList<File>(); | |||
this.classpathVariables = new ArrayList<String>(); | |||
this.requiredResults = new ArrayList<Result>(); | |||
String name = module.name; | |||
if (!kind.normal) { | |||
name += "-test"; | |||
@@ -219,7 +219,7 @@ public class Result { | |||
/** @return List (File) of jar's required */ | |||
public List<File> findJarRequirements() { | |||
ArrayList<File> result = new ArrayList<>(); | |||
ArrayList<File> result = new ArrayList<File>(); | |||
Module.doFindJarRequirements(this, result); | |||
return result; | |||
} |
@@ -391,7 +391,7 @@ class Sample { | |||
* type-safe Collection of samples. | |||
*/ | |||
class Samples { | |||
private ArrayList<Sample> samples = new ArrayList<>(); | |||
private ArrayList<Sample> samples = new ArrayList<Sample>(); | |||
int size() { | |||
return samples.size(); | |||
} | |||
@@ -406,7 +406,7 @@ class Samples { | |||
} | |||
List<Sample> getSortedSamples(Comparator<Sample> comparer) { | |||
ArrayList<Sample> result = new ArrayList<>(); | |||
ArrayList<Sample> result = new ArrayList<Sample>(); | |||
result.addAll(samples); | |||
Collections.sort(result, comparer); | |||
return result; | |||
@@ -957,7 +957,7 @@ class SampleUtil { | |||
} | |||
public static String[] splitAnchorName(String anchorName) { | |||
ArrayList<String> result = new ArrayList<>(); | |||
ArrayList<String> result = new ArrayList<String>(); | |||
int start = 0; | |||
int loc = anchorName.indexOf("-", start); | |||
String next; |
@@ -69,7 +69,7 @@ public class BuildModuleTests extends TestCase { | |||
* @return | |||
*/ | |||
private static File[] findSourceRoots(File moduleDir) { | |||
ArrayList<File> result = new ArrayList<>(); | |||
ArrayList<File> result = new ArrayList<File>(); | |||
for (String name: SOURCE_NAMES) { | |||
File srcDir = new File(moduleDir, name); | |||
if (srcDir.canRead() && srcDir.isDirectory()) { | |||
@@ -196,7 +196,7 @@ public class BuildModuleTests extends TestCase { | |||
// separate check to verify all file types (suffixes) are known | |||
if (!"testsrc".equals(srcDir.getName())) { | |||
ArrayList<File> unknownFiles = new ArrayList<>(); | |||
ArrayList<File> unknownFiles = new ArrayList<File>(); | |||
UnknownFileCheck.SINGLETON.unknownFiles(srcDir, unknownFiles); | |||
if (!unknownFiles.isEmpty()) { | |||
String s = "unknown files (see readme-build-module.html to " | |||
@@ -217,12 +217,12 @@ public class BuildModuleTests extends TestCase { | |||
*/ | |||
static class UnknownFileCheck implements FileFilter { | |||
private static final UnknownFileCheck SINGLETON = new UnknownFileCheck(); | |||
private static final ArrayList<String> STATIC_ERRORS = new ArrayList<>(); | |||
private static final ArrayList<String> STATIC_ERRORS = new ArrayList<String>(); | |||
// Builder.BINARY_SOURCE_PATTERN and Builder.RESOURCE_PATTERN | |||
public static final List<String> KNOWN_SUFFIXES; | |||
static { | |||
List<String> suffixes = new ArrayList<>(); | |||
List<String> suffixes = new ArrayList<String>(); | |||
// sources from org.aspectj.util.FileUtil.SOURCE_SUFFIXES | |||
suffixes.add(".aj"); | |||
suffixes.add(".java"); |
@@ -80,7 +80,7 @@ public class BuildModuleTest extends TestCase { | |||
} | |||
} | |||
ArrayList<File> tempFiles = new ArrayList<>(); | |||
ArrayList<File> tempFiles = new ArrayList<File>(); | |||
private File jarDir; | |||
private boolean deleteJars; | |||
boolean building; // must be enabled for tests to run | |||
@@ -343,7 +343,7 @@ public class BuildModuleTest extends TestCase { | |||
try { | |||
zipFile = new ZipFile(weaverAllJar); | |||
Enumeration e = zipFile.entries(); | |||
ArrayList<String> entryNames = new ArrayList<>(); | |||
ArrayList<String> entryNames = new ArrayList<String>(); | |||
while (e.hasMoreElements()) { | |||
ZipEntry entry = (ZipEntry) e.nextElement(); | |||
String name = entry.getName(); |
@@ -72,7 +72,7 @@ public class ModulesTest extends TestCase { | |||
} | |||
} | |||
ArrayList<File> tempFiles = new ArrayList<>(); | |||
ArrayList<File> tempFiles = new ArrayList<File>(); | |||
public ModulesTest(String name) { | |||
super(name); | |||
@@ -101,7 +101,7 @@ public class ModulesTest extends TestCase { | |||
} | |||
public void testAllModulesCreation() { | |||
ArrayList<Module> badModules = new ArrayList<>(); | |||
ArrayList<Module> badModules = new ArrayList<Module>(); | |||
for (String name: MODULE_NAMES) { | |||
File dir = new File(BASE_DIR, name); | |||
if (dir.isDirectory()) { |
@@ -5,7 +5,7 @@ | |||
<groupId>org.aspectj</groupId> | |||
<artifactId>aspectjrt</artifactId> | |||
<packaging>jar</packaging> | |||
<version>1.8.6.BUILD-SNAPSHOT</version> | |||
<version>1.9.0.BUILD-SNAPSHOT</version> | |||
<name>AspectJ runtime</name> | |||
<description>The runtime needed to execute a program using AspectJ</description> | |||
<url>http://www.aspectj.org</url> |
@@ -5,7 +5,7 @@ | |||
<groupId>org.aspectj</groupId> | |||
<artifactId>aspectjtools</artifactId> | |||
<packaging>jar</packaging> | |||
<version>1.8.6.BUILD-SNAPSHOT</version> | |||
<version>1.9.0.BUILD-SNAPSHOT</version> | |||
<name>AspectJ tools</name> | |||
<description>Tools from the AspectJ project</description> | |||
<url>http://www.aspectj.org</url> |