You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Factory.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Common Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/cpl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.runtime.reflect;
  14. import java.lang.reflect.Constructor;
  15. import java.lang.reflect.Member;
  16. import java.lang.reflect.Method;
  17. import org.aspectj.lang.*;
  18. import org.aspectj.lang.reflect.*;
  19. public final class Factory {
  20. Class lexicalClass;
  21. ClassLoader lookupClassLoader;
  22. String filename;
  23. public Factory(String filename, Class lexicalClass) {
  24. //System.out.println("making
  25. this.filename = filename;
  26. this.lexicalClass = lexicalClass;
  27. lookupClassLoader = lexicalClass.getClassLoader();
  28. }
  29. public JoinPoint.StaticPart makeSJP(String kind, Signature sig, SourceLocation loc) {
  30. return new JoinPointImpl.StaticPartImpl(kind, sig, loc);
  31. }
  32. public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l, int c) {
  33. return new JoinPointImpl.StaticPartImpl(kind, sig, makeSourceLoc(l, c));
  34. }
  35. public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l) {
  36. return new JoinPointImpl.StaticPartImpl(kind, sig, makeSourceLoc(l, -1));
  37. }
  38. public static JoinPoint.StaticPart makeEncSJP(Member member) {
  39. Signature sig = null;
  40. String kind = null;
  41. if (member instanceof Method) {
  42. Method method = (Method) member;
  43. sig = new MethodSignatureImpl(method.getModifiers(),method.getName(),
  44. method.getDeclaringClass(),method.getParameterTypes(),
  45. new String[method.getParameterTypes().length],
  46. method.getExceptionTypes(),method.getReturnType());
  47. kind = JoinPoint.METHOD_EXECUTION;
  48. } else if (member instanceof Constructor) {
  49. Constructor cons = (Constructor) member;
  50. sig = new ConstructorSignatureImpl(cons.getModifiers(),cons.getDeclaringClass(),
  51. cons.getParameterTypes(),
  52. new String[cons.getParameterTypes().length],
  53. cons.getExceptionTypes());
  54. kind = JoinPoint.CONSTRUCTOR_EXECUTION;
  55. } else {
  56. throw new IllegalArgumentException("member must be either a method or constructor");
  57. }
  58. return new JoinPointImpl.StaticPartImpl(kind,sig,null);
  59. }
  60. private static Object[] NO_ARGS = new Object[0];
  61. public static JoinPoint makeJP(JoinPoint.StaticPart staticPart,
  62. Object _this, Object target)
  63. {
  64. return new JoinPointImpl(staticPart, _this, target, NO_ARGS);
  65. }
  66. public static JoinPoint makeJP(JoinPoint.StaticPart staticPart,
  67. Object _this, Object target, Object arg0)
  68. {
  69. return new JoinPointImpl(staticPart, _this, target, new Object[] {arg0});
  70. }
  71. public static JoinPoint makeJP(JoinPoint.StaticPart staticPart,
  72. Object _this, Object target, Object arg0, Object arg1)
  73. {
  74. return new JoinPointImpl(staticPart, _this, target, new Object[] {arg0, arg1});
  75. }
  76. public static JoinPoint makeJP(JoinPoint.StaticPart staticPart,
  77. Object _this, Object target, Object[] args)
  78. {
  79. return new JoinPointImpl(staticPart, _this, target, args);
  80. }
  81. public MethodSignature makeMethodSig(String stringRep) {
  82. MethodSignatureImpl ret = new MethodSignatureImpl(stringRep);
  83. ret.setLookupClassLoader(lookupClassLoader);
  84. return ret;
  85. }
  86. public MethodSignature makeMethodSig(int modifiers, String name, Class declaringType,
  87. Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
  88. Class returnType) {
  89. MethodSignatureImpl ret = new MethodSignatureImpl(modifiers,name,declaringType,parameterTypes,parameterNames,exceptionTypes,returnType);
  90. ret.setLookupClassLoader(lookupClassLoader);
  91. return ret;
  92. }
  93. public ConstructorSignature makeConstructorSig(String stringRep) {
  94. ConstructorSignatureImpl ret = new ConstructorSignatureImpl(stringRep);
  95. ret.setLookupClassLoader(lookupClassLoader);
  96. return ret;
  97. }
  98. public ConstructorSignature makeConstructorSig(int modifiers, Class declaringType,
  99. Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes) {
  100. ConstructorSignatureImpl ret = new ConstructorSignatureImpl(modifiers,declaringType,parameterTypes,parameterNames,exceptionTypes);
  101. ret.setLookupClassLoader(lookupClassLoader);
  102. return ret;
  103. }
  104. public FieldSignature makeFieldSig(String stringRep) {
  105. FieldSignatureImpl ret = new FieldSignatureImpl(stringRep);
  106. ret.setLookupClassLoader(lookupClassLoader);
  107. return ret;
  108. }
  109. public FieldSignature makeFieldSig(int modifiers, String name, Class declaringType,
  110. Class fieldType) {
  111. FieldSignatureImpl ret = new FieldSignatureImpl(modifiers,name,declaringType,fieldType);
  112. ret.setLookupClassLoader(lookupClassLoader);
  113. return ret;
  114. }
  115. public AdviceSignature makeAdviceSig(String stringRep) {
  116. AdviceSignatureImpl ret = new AdviceSignatureImpl(stringRep);
  117. ret.setLookupClassLoader(lookupClassLoader);
  118. return ret;
  119. }
  120. public AdviceSignature makeAdviceSig(int modifiers, String name, Class declaringType,
  121. Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
  122. Class returnType) {
  123. AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiers,name,declaringType,parameterTypes,parameterNames,exceptionTypes,returnType);
  124. ret.setLookupClassLoader(lookupClassLoader);
  125. return ret;
  126. }
  127. public InitializerSignature makeInitializerSig(String stringRep) {
  128. InitializerSignatureImpl ret = new InitializerSignatureImpl(stringRep);
  129. ret.setLookupClassLoader(lookupClassLoader);
  130. return ret;
  131. }
  132. public InitializerSignature makeInitializerSig(int modifiers, Class declaringType) {
  133. InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiers,declaringType);
  134. ret.setLookupClassLoader(lookupClassLoader);
  135. return ret;
  136. }
  137. public CatchClauseSignature makeCatchClauseSig(String stringRep) {
  138. CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(stringRep);
  139. ret.setLookupClassLoader(lookupClassLoader);
  140. return ret;
  141. }
  142. public CatchClauseSignature makeCatchClauseSig(Class declaringType,
  143. Class parameterType, String parameterName) {
  144. CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(declaringType,parameterType,parameterName);
  145. ret.setLookupClassLoader(lookupClassLoader);
  146. return ret;
  147. }
  148. public SourceLocation makeSourceLoc(int line, int col)
  149. {
  150. return new SourceLocationImpl(lexicalClass, this.filename, line);
  151. }
  152. }