[jboss-svn-commits] JBL Code SVN: r23562 - in labs/jbosstm/workspace/adinn/orchestration: src and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 23 09:57:20 EDT 2008
Author: adinn
Date: 2008-10-23 09:57:20 -0400 (Thu, 23 Oct 2008)
New Revision: 23562
Added:
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/test/
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/test/TestScript.java
Removed:
labs/jbosstm/workspace/adinn/orchestration/src/TestScript.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/test/
Modified:
labs/jbosstm/workspace/adinn/orchestration/build.xml
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/TypeHelper.java
Log:
removed redundant annotation classes and relocated parser/typechecker test class
Modified: labs/jbosstm/workspace/adinn/orchestration/build.xml
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/build.xml 2008-10-23 13:35:41 UTC (rev 23561)
+++ labs/jbosstm/workspace/adinn/orchestration/build.xml 2008-10-23 13:57:20 UTC (rev 23562)
@@ -160,22 +160,11 @@
<delete dir="${dd.grammar.dir}" includes="*.java *.tokens"/>
</target>
- <target name="TestScript.compile">
- <!-- build the TestScript class and then run it to check parsing of rule elements -->
- <javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${javac.debug}" includes="TestScript.java">
+ <target name="TestScript" depends="jar">
+ <java classname="org.jboss.jbossts.orchestration.test.TestScript" fork="true">
<classpath>
- <pathelement location="${asm.home}/${asm.jar}"/>
- <fileset dir="${ext.lib.dir}" includes="${ext.antlr.jars}"/>
- </classpath>
- </javac>
- </target>
-
- <target name="TestScript" depends="TestScript.compile">
- <java classname="TestScript" fork="true">
- <classpath>
<fileset dir="${build.lib.dir}" includes="orchestration.jar"/>
<pathelement location="${asm.home}/${asm.jar}"/>
- <fileset dir="${ext.lib.dir}" includes="${ext.antlr.jars}"/>
<!-- xts, jta and jboss as jars-->
<fileset dir="${xts.lib.dir}" includes="${xts.lib.jars}"/>
<fileset dir="${xts.sar.dir}" includes="${xts.sar.jars}"/>
@@ -188,12 +177,11 @@
</java>
</target>
- <target name="TestScriptDebug" depends="TestScript.compile">
- <java classname="TestScript" fork="true">
+ <target name="TestScriptDebug" depends="jar">
+ <java classname="org.jboss.jbossts.orchestration.test.TestScript" fork="true">
<classpath>
<fileset dir="${build.lib.dir}" includes="orchestration.jar"/>
<pathelement location="${asm.home}/${asm.jar}"/>
- <fileset dir="${ext.lib.dir}" includes="${ext.antlr.jars}"/>
<!-- xts, jta and jboss as jars-->
<fileset dir="${xts.lib.dir}" includes="${xts.lib.jars}"/>
<fileset dir="${xts.sar.dir}" includes="${xts.sar.jars}"/>
Deleted: labs/jbosstm/workspace/adinn/orchestration/src/TestScript.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/TestScript.java 2008-10-23 13:35:41 UTC (rev 23561)
+++ labs/jbosstm/workspace/adinn/orchestration/src/TestScript.java 2008-10-23 13:57:20 UTC (rev 23562)
@@ -1,291 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*
-* @authors Andrew Dinn
-*/
-import org.jboss.jbossts.orchestration.annotation.EventHandlerClass;
-import org.jboss.jbossts.orchestration.annotation.EventHandler;
-import org.jboss.jbossts.orchestration.rule.type.TypeHelper;
-import org.jboss.jbossts.orchestration.rule.type.Type;
-import org.jboss.jbossts.orchestration.rule.Rule;
-import org.jboss.jbossts.orchestration.rule.exception.ParseException;
-import org.jboss.jbossts.orchestration.rule.exception.TypeException;
-import org.jboss.jbossts.orchestration.rule.exception.CompileException;
-import org.objectweb.asm.Opcodes;
-
-import java.util.jar.JarFile;
-import java.util.jar.JarEntry;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.ArrayList;
-import java.io.File;
-import java.io.IOException;
-import java.io.FileInputStream;
-import java.net.URLClassLoader;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Constructor;
-
-public class TestScript
-{
- public static void main(String[] args)
- {
- TestScript testScript = new TestScript();
- testScript.testScript(args);
- }
-
- public void testScript(String[] scriptFiles)
- {
- for (String script : scriptFiles) {
- try {
- FileInputStream fis = new FileInputStream(new File(script));
- System.out.println("checking classes in " + script);
- List<String> rules = processRules(fis);
- checkRules(rules);
- } catch (IOException ioe) {
- System.err.println("TestScript: unable to open rule script file : " + script);
- }
- }
- }
-
-
-
- private List<String> processRules(FileInputStream stream)
- throws IOException
- {
- List<String> rules = new ArrayList<String>();
-
- byte[] bytes = new byte[stream.available()];
- stream.read(bytes);
- String text = new String(bytes);
- int length = text.length();
- while (length > 0) {
- int end = text.indexOf("ENDRULE");
- if (end >= 0) {
- end += "ENDRULE".length();
- if (end < length && text.charAt(end) == '\n') {
- end++;
- }
- rules.add(text.substring(0, end));
- text = text.substring(end).trim();
- } else {
- rules.add(text);
- text = "";
- }
- length = text.length();
- }
-
- return rules;
- }
-
- private void checkRules(List<String> ruleScripts)
- {
- ClassLoader loader = getClass().getClassLoader();
-
- for (String script : ruleScripts) {
- String ruleName = "";
- try {
- String[] lines = script.split("\n");
- String targetClassName;
- String targetMethodName;
- int targetLine = -1;
- String text = "";
- String sepr = "";
- int idx = 0;
- int len = lines.length;
-
- while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
- idx++;
- }
- if (lines[idx].startsWith("RULE ")) {
- ruleName = lines[idx].substring(5).trim();
- idx++;
- } else {
- throw new ParseException("Rule should start with RULE : " + lines[idx]);
- }
- while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
- idx++;
- }
- if (lines[idx].startsWith("CLASS ")) {
- targetClassName = lines[idx].substring(6).trim();
- idx++;
- } else {
- throw new ParseException("CLASS should follow RULE : " + lines[idx]) ;
- }
- while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
- idx++;
- }
- if (lines[idx].startsWith("METHOD ")) {
- targetMethodName = lines[idx].substring(7).trim();
- idx++;
- } else {
- throw new ParseException("METHOD should follow CLASS : " + lines[idx]) ;
- }
- while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
- idx++;
- }
- if (lines[idx].startsWith("LINE ")) {
- String targetLineString = lines[idx].substring(5).trim();
- targetLine = Integer.valueOf(targetLineString);
- idx++;
- }
- for (;idx < len; idx++) {
- if (lines[idx].trim().startsWith("#")) {
- lines[idx] = "";
- }
- if (lines[idx].trim().equals("ENDRULE")) {
- break;
- }
- text += sepr + lines[idx];
- sepr = "\n";
- }
- if (targetMethodName.startsWith("<init>") && (targetLine < 0)) {
- throw new ParseException("constructor method " + targetMethodName + " must specify target line in rule " + ruleName);
- }
- Rule rule = Rule.create(ruleName, targetClassName, targetMethodName, targetLine, text, loader);
- System.err.println("TestScript: parsed rule " + rule.getName());
- System.err.println(rule);
-
- String targetName = TypeHelper.parseMethodName(targetMethodName);
- String targetDesc = TypeHelper.parseMethodDescriptor(targetMethodName);
- boolean found = false;
- boolean multiple = false;
- try {
- Class targetClass = loader.loadClass(targetClassName);
- if (!targetName.equals("<init>")) {
- Method[] candidates = targetClass.getDeclaredMethods();
- for (Method candidate : candidates) {
- String candidateName = candidate.getName();
- String candidateDesc = makeDescriptor(candidate);
- if (targetName.equals(candidateName)) {
- if (targetDesc.equals("") || TypeHelper.equalDescriptors(targetDesc, candidateDesc)) {
- System.err.println("TestJar: checking rule " + ruleName);
- if (found) {
- multiple = true;
- break;
- }
- found = true;
- int access = 0;
- Class<?>[] exceptionClasses = candidate.getExceptionTypes();
- int l = exceptionClasses.length;
- String[] exceptionNames = new String[l];
- for (int i = 0; i < l; i++) {
- exceptionNames[i] = exceptionClasses[i].getCanonicalName();
- }
- if ((candidate.getModifiers() & Modifier.STATIC) != 0) {
- access = Opcodes.ACC_STATIC;
- }
- rule.setTypeInfo(targetClassName, access, candidateName, candidateDesc, exceptionNames);
- rule.typeCheck();
- System.err.println("TestJar: type checked rule " + ruleName);
- }
- }
- }
- } else {
- Constructor[] constructors = targetClass.getConstructors();
- for (Constructor constructor : constructors) {
- String candidateName = constructor.getName();
- String candidateDesc = makeDescriptor(constructor);
- if (targetName.equals("<init>")) {
- if (targetDesc.equals("") || TypeHelper.equalDescriptors(targetDesc, candidateDesc)) {
- System.err.println("TestJar: checking rule " + ruleName);
- if (found) {
- multiple = true;
- break;
- }
- found = true;
- int access = 0;
- Class<?>[] exceptionClasses = constructor.getExceptionTypes();
- int l = exceptionClasses.length;
- String[] exceptionNames = new String[l];
- for (int i = 0; i < l; i++) {
- exceptionNames[i] = exceptionClasses[i].getCanonicalName();
- }
- if ((constructor.getModifiers() & Modifier.STATIC) != 0) {
- access = Opcodes.ACC_STATIC;
- }
- rule.setTypeInfo(targetClassName, access, candidateName, candidateDesc, exceptionNames);
- rule.typeCheck();
- System.err.println("TestJar: type checked rule " + ruleName);
- }
- }
- }
- }
- } catch(ClassNotFoundException cfe) {
- System.err.println("TestScript: unable to load class " + targetClassName);
- }
- if (!found) {
- System.err.println("TestJar: no matching method for rule " + ruleName);
- } else if (multiple) {
- System.err.println("TestJar: multiple matching methods for rule " + ruleName);
- }
- } catch (ParseException e) {
- System.err.println("TestScript: parse exception for rule " + ruleName + " : " + e);
- e.printStackTrace(System.err);
- } catch (TypeException e) {
- System.err.println("TestScript: type exception for rule " + ruleName + " : " + e);
- e.printStackTrace(System.err);
- } catch (CompileException e) {
- System.err.println("TestScript: compile exception for rule " + " : " + ruleName + e);
- e.printStackTrace(System.err);
- }
- }
- }
-
- static String makeDescriptor(Method method)
- {
- Class<?> paramTypes[] = method.getParameterTypes();
- Class<?> retType = method.getReturnType();
- String desc = "(";
-
- for (Class<?> paramType : paramTypes) {
- String name = paramType.getCanonicalName();
- desc += TypeHelper.externalizeType(name);
- }
- desc += ")";
- desc += TypeHelper.externalizeType(retType.getCanonicalName());
-
- return desc;
- }
-
- static String makeDescriptor(Constructor constructor)
- {
- Class<?> paramTypes[] = constructor.getParameterTypes();
- String desc = "(";
-
- for (Class<?> paramType : paramTypes) {
- String name = paramType.getCanonicalName();
- desc += TypeHelper.externalizeType(name);
- }
- desc += ")";
-
- return desc;
- }
-
- /**
- * suffix found on end of .class files (doh :-)
- */
-
- private static final String CLASS_FILE_SUFFIX = ".class";
-}
\ No newline at end of file
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java 2008-10-23 13:35:41 UTC (rev 23561)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java 2008-10-23 13:57:20 UTC (rev 23562)
@@ -23,27 +23,21 @@
*/
package org.jboss.jbossts.orchestration.agent;
-import org.jboss.jbossts.orchestration.annotation.EventHandler;
-import org.jboss.jbossts.orchestration.annotation.EventHandlerClass;
import org.jboss.jbossts.orchestration.rule.Rule;
import org.jboss.jbossts.orchestration.rule.type.TypeHelper;
import org.jboss.jbossts.orchestration.rule.exception.ParseException;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
import org.objectweb.asm.*;
import org.objectweb.asm.commons.EmptyVisitor;
-import org.objectweb.asm.util.TraceClassVisitor;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
-import java.lang.reflect.Method;
-import java.lang.annotation.Annotation;
import java.security.ProtectionDomain;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
-import java.io.PrintWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.File;
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/TypeHelper.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/TypeHelper.java 2008-10-23 13:35:41 UTC (rev 23561)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/type/TypeHelper.java 2008-10-23 13:57:20 UTC (rev 23562)
@@ -23,8 +23,6 @@
*/
package org.jboss.jbossts.orchestration.rule.type;
-import org.jboss.jbossts.orchestration.annotation.EventHandler;
-
/**
* Helpoer class providing static methods for manipulating type and class names,
* field and method descriptor names etc
@@ -297,42 +295,4 @@
return "";
}
}
-
- /**
- * split off the signature following the method name and return it
- * @param targetName the unqualified method name, not including signature
- * @param targetSignature the method signature including brackets types and return type
- * @return
- */
- public static String generateFieldName(String targetName, String targetSignature) {
- String result = targetName;
- int startIdx = targetSignature.indexOf("(");
- int endIdx = targetSignature.indexOf(")");
- if (startIdx < 0) {
- startIdx = 0;
- }
- if (endIdx < 0) {
- endIdx = targetSignature.length() - 1;
- }
-
- String args = targetSignature.substring(startIdx, endIdx + 1);
-
- result = result.replaceAll("<", "\\$_");
- result = result.replaceAll(">", "_\\$");
-
- // remove any brackets, semi-colons and '[' characters
- args = args.replaceAll("\\(", "\\$_");
- args = args.replaceAll("\\)", "_\\$");
- args = args.replaceAll(";", "__");
- args = args.replaceAll("\\[", "\\$\\$_");
- args = args.replaceAll("/", "_\\$_");
-
- return result + args;
- }
-
- private static Class generateHandlerClass(EventHandler handler, ClassLoader loader, String targetClassName, Class targetClass)
- {
- // TODO -- write this but use Object for now
- return Object.class;
- }
}
Copied: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/test/TestScript.java (from rev 23243, labs/jbosstm/workspace/adinn/orchestration/src/TestScript.java)
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/test/TestScript.java (rev 0)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/test/TestScript.java 2008-10-23 13:57:20 UTC (rev 23562)
@@ -0,0 +1,296 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*
+* @authors Andrew Dinn
+*/
+package org.jboss.jbossts.orchestration.test;
+
+import org.jboss.jbossts.orchestration.rule.type.TypeHelper;
+import org.jboss.jbossts.orchestration.rule.Rule;
+import org.jboss.jbossts.orchestration.rule.exception.ParseException;
+import org.jboss.jbossts.orchestration.rule.exception.TypeException;
+import org.jboss.jbossts.orchestration.rule.exception.CompileException;
+import org.objectweb.asm.Opcodes;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
+import java.io.IOException;
+import java.io.FileInputStream;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Constructor;
+
+/**
+ * utility which parses and typechecks all rules in a rule script.
+ *
+ * usage : java org.jboss.jbossts.orchestration.TestScript [scriptfile]
+ *
+ * n.b. the orchestration jar and any classes mentioned in the script rules need to be in the classpath
+ */
+public class TestScript
+{
+ public static void main(String[] args)
+ {
+ if (args.length == 0 || args[0].equals("-h")) {
+ System.out.println("usage : java org.jboss.jbossts.orchestration.TestScript [scriptfile1 ...]");
+ System.out.println(" n.b. place the orchestration jar and classes mentioned in the ");
+ System.out.println(" scripts in the classpath");
+ return;
+ }
+ TestScript testScript = new TestScript();
+ testScript.testScript(args);
+ }
+
+ public void testScript(String[] scriptFiles)
+ {
+ for (String script : scriptFiles) {
+ try {
+ FileInputStream fis = new FileInputStream(new File(script));
+ System.out.println("checking classes in " + script);
+ List<String> rules = processRules(fis);
+ checkRules(rules);
+ } catch (IOException ioe) {
+ System.err.println("TestScript: unable to open rule script file : " + script);
+ }
+ }
+ }
+
+
+
+ private List<String> processRules(FileInputStream stream)
+ throws IOException
+ {
+ List<String> rules = new ArrayList<String>();
+
+ byte[] bytes = new byte[stream.available()];
+ stream.read(bytes);
+ String text = new String(bytes);
+ int length = text.length();
+ while (length > 0) {
+ int end = text.indexOf("ENDRULE");
+ if (end >= 0) {
+ end += "ENDRULE".length();
+ if (end < length && text.charAt(end) == '\n') {
+ end++;
+ }
+ rules.add(text.substring(0, end));
+ text = text.substring(end).trim();
+ } else {
+ rules.add(text);
+ text = "";
+ }
+ length = text.length();
+ }
+
+ return rules;
+ }
+
+ private void checkRules(List<String> ruleScripts)
+ {
+ ClassLoader loader = getClass().getClassLoader();
+
+ for (String script : ruleScripts) {
+ String ruleName = "";
+ try {
+ String[] lines = script.split("\n");
+ String targetClassName;
+ String targetMethodName;
+ int targetLine = -1;
+ String text = "";
+ String sepr = "";
+ int idx = 0;
+ int len = lines.length;
+
+ while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
+ idx++;
+ }
+ if (lines[idx].startsWith("RULE ")) {
+ ruleName = lines[idx].substring(5).trim();
+ idx++;
+ } else {
+ throw new ParseException("Rule should start with RULE : " + lines[idx]);
+ }
+ while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
+ idx++;
+ }
+ if (lines[idx].startsWith("CLASS ")) {
+ targetClassName = lines[idx].substring(6).trim();
+ idx++;
+ } else {
+ throw new ParseException("CLASS should follow RULE : " + lines[idx]) ;
+ }
+ while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
+ idx++;
+ }
+ if (lines[idx].startsWith("METHOD ")) {
+ targetMethodName = lines[idx].substring(7).trim();
+ idx++;
+ } else {
+ throw new ParseException("METHOD should follow CLASS : " + lines[idx]) ;
+ }
+ while (lines[idx].trim().equals("") || lines[idx].trim().startsWith("#")) {
+ idx++;
+ }
+ if (lines[idx].startsWith("LINE ")) {
+ String targetLineString = lines[idx].substring(5).trim();
+ targetLine = Integer.valueOf(targetLineString);
+ idx++;
+ }
+ for (;idx < len; idx++) {
+ if (lines[idx].trim().startsWith("#")) {
+ lines[idx] = "";
+ }
+ if (lines[idx].trim().equals("ENDRULE")) {
+ break;
+ }
+ text += sepr + lines[idx];
+ sepr = "\n";
+ }
+ if (targetMethodName.startsWith("<init>") && (targetLine < 0)) {
+ throw new ParseException("constructor method " + targetMethodName + " must specify target line in rule " + ruleName);
+ }
+ Rule rule = Rule.create(ruleName, targetClassName, targetMethodName, targetLine, text, loader);
+ System.err.println("TestScript: parsed rule " + rule.getName());
+ System.err.println(rule);
+
+ String targetName = TypeHelper.parseMethodName(targetMethodName);
+ String targetDesc = TypeHelper.parseMethodDescriptor(targetMethodName);
+ boolean found = false;
+ boolean multiple = false;
+ try {
+ Class targetClass = loader.loadClass(targetClassName);
+ if (!targetName.equals("<init>")) {
+ Method[] candidates = targetClass.getDeclaredMethods();
+ for (Method candidate : candidates) {
+ String candidateName = candidate.getName();
+ String candidateDesc = makeDescriptor(candidate);
+ if (targetName.equals(candidateName)) {
+ if (targetDesc.equals("") || TypeHelper.equalDescriptors(targetDesc, candidateDesc)) {
+ System.err.println("TestJar: checking rule " + ruleName);
+ if (found) {
+ multiple = true;
+ break;
+ }
+ found = true;
+ int access = 0;
+ Class<?>[] exceptionClasses = candidate.getExceptionTypes();
+ int l = exceptionClasses.length;
+ String[] exceptionNames = new String[l];
+ for (int i = 0; i < l; i++) {
+ exceptionNames[i] = exceptionClasses[i].getCanonicalName();
+ }
+ if ((candidate.getModifiers() & Modifier.STATIC) != 0) {
+ access = Opcodes.ACC_STATIC;
+ }
+ rule.setTypeInfo(targetClassName, access, candidateName, candidateDesc, exceptionNames);
+ rule.typeCheck();
+ System.err.println("TestJar: type checked rule " + ruleName);
+ }
+ }
+ }
+ } else {
+ Constructor[] constructors = targetClass.getConstructors();
+ for (Constructor constructor : constructors) {
+ String candidateName = constructor.getName();
+ String candidateDesc = makeDescriptor(constructor);
+ if (targetName.equals("<init>")) {
+ if (targetDesc.equals("") || TypeHelper.equalDescriptors(targetDesc, candidateDesc)) {
+ System.err.println("TestJar: checking rule " + ruleName);
+ if (found) {
+ multiple = true;
+ break;
+ }
+ found = true;
+ int access = 0;
+ Class<?>[] exceptionClasses = constructor.getExceptionTypes();
+ int l = exceptionClasses.length;
+ String[] exceptionNames = new String[l];
+ for (int i = 0; i < l; i++) {
+ exceptionNames[i] = exceptionClasses[i].getCanonicalName();
+ }
+ if ((constructor.getModifiers() & Modifier.STATIC) != 0) {
+ access = Opcodes.ACC_STATIC;
+ }
+ rule.setTypeInfo(targetClassName, access, candidateName, candidateDesc, exceptionNames);
+ rule.typeCheck();
+ System.err.println("TestJar: type checked rule " + ruleName);
+ }
+ }
+ }
+ }
+ } catch(ClassNotFoundException cfe) {
+ System.err.println("TestScript: unable to load class " + targetClassName);
+ }
+ if (!found) {
+ System.err.println("TestJar: no matching method for rule " + ruleName);
+ } else if (multiple) {
+ System.err.println("TestJar: multiple matching methods for rule " + ruleName);
+ }
+ } catch (ParseException e) {
+ System.err.println("TestScript: parse exception for rule " + ruleName + " : " + e);
+ e.printStackTrace(System.err);
+ } catch (TypeException e) {
+ System.err.println("TestScript: type exception for rule " + ruleName + " : " + e);
+ e.printStackTrace(System.err);
+ } catch (CompileException e) {
+ System.err.println("TestScript: compile exception for rule " + " : " + ruleName + e);
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+
+ static String makeDescriptor(Method method)
+ {
+ Class<?> paramTypes[] = method.getParameterTypes();
+ Class<?> retType = method.getReturnType();
+ String desc = "(";
+
+ for (Class<?> paramType : paramTypes) {
+ String name = paramType.getCanonicalName();
+ desc += TypeHelper.externalizeType(name);
+ }
+ desc += ")";
+ desc += TypeHelper.externalizeType(retType.getCanonicalName());
+
+ return desc;
+ }
+
+ static String makeDescriptor(Constructor constructor)
+ {
+ Class<?> paramTypes[] = constructor.getParameterTypes();
+ String desc = "(";
+
+ for (Class<?> paramType : paramTypes) {
+ String name = paramType.getCanonicalName();
+ desc += TypeHelper.externalizeType(name);
+ }
+ desc += ")";
+
+ return desc;
+ }
+
+ /**
+ * suffix found on end of .class files (doh :-)
+ */
+
+ private static final String CLASS_FILE_SUFFIX = ".class";
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list