Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AjLookupEnvironment.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.lookup;
  13. import java.util.ArrayList;
  14. import java.util.Collection;
  15. import java.util.HashMap;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
  20. import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
  21. import org.aspectj.bridge.IMessage;
  22. import org.aspectj.bridge.WeaveMessage;
  23. import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
  24. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
  25. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
  26. import org.aspectj.org.eclipse.jdt.internal.compiler.env.AccessRestriction;
  27. import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryType;
  28. import org.aspectj.org.eclipse.jdt.internal.compiler.env.INameEnvironment;
  29. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  30. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.ITypeRequestor;
  31. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
  32. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
  33. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
  34. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
  35. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
  36. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
  37. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
  38. import org.aspectj.org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
  39. import org.aspectj.weaver.AsmRelationshipProvider;
  40. import org.aspectj.weaver.ConcreteTypeMunger;
  41. import org.aspectj.weaver.ResolvedTypeMunger;
  42. import org.aspectj.weaver.ResolvedTypeX;
  43. import org.aspectj.weaver.TypeX;
  44. import org.aspectj.weaver.WeaverStateInfo;
  45. import org.aspectj.weaver.World;
  46. import org.aspectj.weaver.bcel.LazyClassGen;
  47. import org.aspectj.weaver.patterns.DeclareParents;
  48. /**
  49. * Overrides the default eclipse LookupEnvironment for two purposes.
  50. *
  51. * 1. To provide some additional phases to <code>completeTypeBindings</code>
  52. * that weave declare parents and inter-type declarations at the correct time.
  53. *
  54. * 2. To intercept the loading of new binary types to ensure the they will have
  55. * declare parents and inter-type declarations woven when appropriate.
  56. *
  57. * @author Jim Hugunin
  58. */
  59. public class AjLookupEnvironment extends LookupEnvironment {
  60. public EclipseFactory factory = null;
  61. // private boolean builtInterTypesAndPerClauses = false;
  62. private List pendingTypesToWeave = new ArrayList();
  63. private Map dangerousInterfaces = new HashMap();
  64. public AjLookupEnvironment(
  65. ITypeRequestor typeRequestor,
  66. CompilerOptions options,
  67. ProblemReporter problemReporter,
  68. INameEnvironment nameEnvironment) {
  69. super(typeRequestor, options, problemReporter, nameEnvironment);
  70. }
  71. //??? duplicates some of super's code
  72. public void completeTypeBindings() {
  73. // builtInterTypesAndPerClauses = false;
  74. //pendingTypesToWeave = new ArrayList();
  75. stepCompleted = BUILD_TYPE_HIERARCHY;
  76. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  77. units[i].scope.checkAndSetImports();
  78. }
  79. stepCompleted = CHECK_AND_SET_IMPORTS;
  80. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  81. units[i].scope.connectTypeHierarchy();
  82. }
  83. stepCompleted = CONNECT_TYPE_HIERARCHY;
  84. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  85. units[i].scope.buildFieldsAndMethods();
  86. }
  87. // would like to gather up all TypeDeclarations at this point and put them in the factory
  88. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  89. SourceTypeBinding[] b = units[i].scope.topLevelTypes;
  90. for (int j = 0; j < b.length; j++) {
  91. factory.addSourceTypeBinding(b[j]);
  92. }
  93. }
  94. // need to build inter-type declarations for all AspectDeclarations at this point
  95. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  96. SourceTypeBinding[] b = units[i].scope.topLevelTypes;
  97. for (int j = 0; j < b.length; j++) {
  98. buildInterTypeAndPerClause(b[j].scope);
  99. addCrosscuttingStructures(b[j].scope);
  100. }
  101. }
  102. factory.finishTypeMungers();
  103. // now do weaving
  104. Collection typeMungers = factory.getTypeMungers();
  105. Collection declareParents = factory.getDeclareParents();
  106. doPendingWeaves();
  107. // We now have some list of types to process, and we are about to apply the type mungers.
  108. // There can be situations where the order of types passed to the compiler causes the
  109. // output from the compiler to vary - THIS IS BAD. For example, if we have class A
  110. // and class B extends A. Also, an aspect that 'declare parents: A+ implements Serializable'
  111. // then depending on whether we see A first, we may or may not make B serializable.
  112. // The fix is to process them in the right order, ensuring that for a type we process its
  113. // supertypes and superinterfaces first. This algorithm may have problems with:
  114. // - partial hierarchies (e.g. suppose types A,B,C are in a hierarchy and A and C are to be woven but not B)
  115. // - weaving that brings new types in for processing (see pendingTypesToWeave.add() calls) after we thought
  116. // we had the full list.
  117. //
  118. // but these aren't common cases (he bravely said...)
  119. boolean typeProcessingOrderIsImportant = declareParents.size()>0;
  120. if (typeProcessingOrderIsImportant) {
  121. List typesToProcess = new ArrayList();
  122. for (int i=lastCompletedUnitIndex+1; i<=lastUnitIndex; i++) {
  123. CompilationUnitScope cus = units[i].scope;
  124. SourceTypeBinding[] stbs = cus.topLevelTypes;
  125. for (int j=0; j<stbs.length; j++) {
  126. SourceTypeBinding stb = stbs[j];
  127. typesToProcess.add(stb);
  128. }
  129. }
  130. while (typesToProcess.size()>0) {
  131. // A side effect of weaveIntertypes() is that the processed type is removed from the collection
  132. weaveIntertypes(typesToProcess,(SourceTypeBinding)typesToProcess.get(0),typeMungers,declareParents);
  133. }
  134. } else {
  135. // Order isn't important
  136. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  137. //System.err.println("Working on "+new String(units[i].getFileName()));
  138. weaveInterTypeDeclarations(units[i].scope, typeMungers, declareParents);
  139. }
  140. }
  141. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  142. SourceTypeBinding[] b = units[i].scope.topLevelTypes;
  143. for (int j = 0; j < b.length; j++) {
  144. resolvePointcutDeclarations(b[j].scope);
  145. }
  146. }
  147. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  148. SourceTypeBinding[] b = units[i].scope.topLevelTypes;
  149. for (int j = 0; j < b.length; j++) {
  150. addAdviceLikeDeclares(b[j].scope);
  151. }
  152. }
  153. for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
  154. units[i] = null; // release unnecessary reference to the parsed unit
  155. }
  156. stepCompleted = BUILD_FIELDS_AND_METHODS;
  157. lastCompletedUnitIndex = lastUnitIndex;
  158. }
  159. /**
  160. * Weave the parents and intertype decls into a given type. This method looks at the
  161. * supertype and superinterfaces for the specified type and recurses to weave those first
  162. * if they are in the full list of types we are going to process during this compile... it stops recursing
  163. * the first time it hits a type we aren't going to process during this compile. This could cause problems
  164. * if you supply 'pieces' of a hierarchy, i.e. the bottom and the top, but not the middle - but what the hell
  165. * are you doing if you do that?
  166. */
  167. private void weaveIntertypes(List typesToProcess,SourceTypeBinding typeToWeave,Collection typeMungers,Collection declareParents) {
  168. // Look at the supertype first
  169. ReferenceBinding superType = typeToWeave.superclass();
  170. //System.err.println("Been asked to weave "+new String(typeToWeave.getFileName()));
  171. if (typesToProcess.contains(superType) && superType instanceof SourceTypeBinding) {
  172. //System.err.println("Recursing to supertype "+new String(superType.getFileName()));
  173. weaveIntertypes(typesToProcess,(SourceTypeBinding)superType,typeMungers,declareParents);
  174. }
  175. // Then look at the superinterface list
  176. ReferenceBinding[] interfaceTypes = typeToWeave.superInterfaces();
  177. for (int i = 0; i < interfaceTypes.length; i++) {
  178. ReferenceBinding binding = interfaceTypes[i];
  179. if (typesToProcess.contains(binding) && binding instanceof SourceTypeBinding) {
  180. //System.err.println("Recursing to superinterface "+new String(binding.getFileName()));
  181. weaveIntertypes(typesToProcess,(SourceTypeBinding)binding,typeMungers,declareParents);
  182. }
  183. }
  184. weaveInterTypeDeclarations(typeToWeave,typeMungers,declareParents,false);
  185. typesToProcess.remove(typeToWeave);
  186. }
  187. private void doPendingWeaves() {
  188. for (Iterator i = pendingTypesToWeave.iterator(); i.hasNext(); ) {
  189. SourceTypeBinding t = (SourceTypeBinding)i.next();
  190. weaveInterTypeDeclarations(t);
  191. }
  192. pendingTypesToWeave.clear();
  193. }
  194. private void addAdviceLikeDeclares(ClassScope s) {
  195. TypeDeclaration dec = s.referenceContext;
  196. if (dec instanceof AspectDeclaration) {
  197. ResolvedTypeX typeX = factory.fromEclipse(dec.binding);
  198. factory.getWorld().getCrosscuttingMembersSet().addAdviceLikeDeclares(typeX);
  199. }
  200. SourceTypeBinding sourceType = s.referenceContext.binding;
  201. ReferenceBinding[] memberTypes = sourceType.memberTypes;
  202. for (int i = 0, length = memberTypes.length; i < length; i++) {
  203. addAdviceLikeDeclares(((SourceTypeBinding) memberTypes[i]).scope);
  204. }
  205. }
  206. private void addCrosscuttingStructures(ClassScope s) {
  207. TypeDeclaration dec = s.referenceContext;
  208. if (dec instanceof AspectDeclaration) {
  209. ResolvedTypeX typeX = factory.fromEclipse(dec.binding);
  210. factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX);
  211. if (typeX.getSuperclass().isAspect() && !typeX.getSuperclass().isExposedToWeaver()) {
  212. factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX.getSuperclass());
  213. }
  214. }
  215. SourceTypeBinding sourceType = s.referenceContext.binding;
  216. ReferenceBinding[] memberTypes = sourceType.memberTypes;
  217. for (int i = 0, length = memberTypes.length; i < length; i++) {
  218. addCrosscuttingStructures(((SourceTypeBinding) memberTypes[i]).scope);
  219. }
  220. }
  221. private void resolvePointcutDeclarations(ClassScope s) {
  222. TypeDeclaration dec = s.referenceContext;
  223. SourceTypeBinding sourceType = s.referenceContext.binding;
  224. boolean hasPointcuts = false;
  225. AbstractMethodDeclaration[] methods = dec.methods;
  226. boolean initializedMethods = false;
  227. if (methods != null) {
  228. for (int i=0; i < methods.length; i++) {
  229. if (methods[i] instanceof PointcutDeclaration) {
  230. hasPointcuts = true;
  231. if (!initializedMethods) {
  232. sourceType.methods(); //force initialization
  233. initializedMethods = true;
  234. }
  235. ((PointcutDeclaration)methods[i]).resolvePointcut(s);
  236. }
  237. }
  238. }
  239. if (hasPointcuts || dec instanceof AspectDeclaration) {
  240. ResolvedTypeX.Name name = (ResolvedTypeX.Name)factory.fromEclipse(sourceType);
  241. EclipseSourceType eclipseSourceType = (EclipseSourceType)name.getDelegate();
  242. eclipseSourceType.checkPointcutDeclarations();
  243. }
  244. ReferenceBinding[] memberTypes = sourceType.memberTypes;
  245. for (int i = 0, length = memberTypes.length; i < length; i++) {
  246. resolvePointcutDeclarations(((SourceTypeBinding) memberTypes[i]).scope);
  247. }
  248. }
  249. private void buildInterTypeAndPerClause(ClassScope s) {
  250. TypeDeclaration dec = s.referenceContext;
  251. if (dec instanceof AspectDeclaration) {
  252. ((AspectDeclaration)dec).buildInterTypeAndPerClause(s);
  253. }
  254. SourceTypeBinding sourceType = s.referenceContext.binding;
  255. // test classes don't extend aspects
  256. if (sourceType.superclass != null) {
  257. ResolvedTypeX parent = factory.fromEclipse(sourceType.superclass);
  258. if (parent.isAspect() && !(dec instanceof AspectDeclaration)) {
  259. factory.showMessage(IMessage.ERROR, "class \'" + new String(sourceType.sourceName) +
  260. "\' can not extend aspect \'" + parent.getName() + "\'",
  261. factory.fromEclipse(sourceType).getSourceLocation(), null);
  262. }
  263. }
  264. ReferenceBinding[] memberTypes = sourceType.memberTypes;
  265. for (int i = 0, length = memberTypes.length; i < length; i++) {
  266. buildInterTypeAndPerClause(((SourceTypeBinding) memberTypes[i]).scope);
  267. }
  268. }
  269. private void weaveInterTypeDeclarations(CompilationUnitScope unit, Collection typeMungers, Collection declareParents) {
  270. for (int i = 0, length = unit.topLevelTypes.length; i < length; i++) {
  271. weaveInterTypeDeclarations(unit.topLevelTypes[i], typeMungers, declareParents, false);
  272. }
  273. }
  274. private void weaveInterTypeDeclarations(SourceTypeBinding sourceType) {
  275. if (!factory.areTypeMungersFinished()) {
  276. if (!pendingTypesToWeave.contains(sourceType)) pendingTypesToWeave.add(sourceType);
  277. } else {
  278. weaveInterTypeDeclarations(sourceType, factory.getTypeMungers(), factory.getDeclareParents(), true);
  279. }
  280. }
  281. private void weaveInterTypeDeclarations(SourceTypeBinding sourceType, Collection typeMungers, Collection declareParents, boolean skipInners) {
  282. ResolvedTypeX onType = factory.fromEclipse(sourceType);
  283. WeaverStateInfo info = onType.getWeaverState();
  284. if (info != null && !info.isOldStyle()) {
  285. Collection mungers =
  286. onType.getWeaverState().getTypeMungers(onType);
  287. //System.out.println(onType + " mungers: " + mungers);
  288. for (Iterator i = mungers.iterator(); i.hasNext(); ) {
  289. ConcreteTypeMunger m = (ConcreteTypeMunger)i.next();
  290. EclipseTypeMunger munger = factory.makeEclipseTypeMunger(m);
  291. if (munger.munge(sourceType)) {
  292. if (onType.isInterface() &&
  293. munger.getMunger().needsAccessToTopmostImplementor())
  294. {
  295. if (!onType.getWorld().getCrosscuttingMembersSet().containsAspect(munger.getAspectType())) {
  296. dangerousInterfaces.put(onType,
  297. "implementors of " + onType + " must be woven by " +
  298. munger.getAspectType());
  299. }
  300. }
  301. }
  302. }
  303. return;
  304. }
  305. //System.out.println("dangerousInterfaces: " + dangerousInterfaces);
  306. for (Iterator i = dangerousInterfaces.entrySet().iterator(); i.hasNext();) {
  307. Map.Entry entry = (Map.Entry) i.next();
  308. ResolvedTypeX interfaceType = (ResolvedTypeX)entry.getKey();
  309. if (onType.isTopmostImplementor(interfaceType)) {
  310. factory.showMessage(IMessage.ERROR,
  311. onType + ": " + entry.getValue(),
  312. onType.getSourceLocation(), null);
  313. }
  314. }
  315. boolean needOldStyleWarning = (info != null && info.isOldStyle());
  316. onType.clearInterTypeMungers();
  317. for (Iterator i = declareParents.iterator(); i.hasNext();) {
  318. doDeclareParents((DeclareParents)i.next(), sourceType);
  319. }
  320. for (Iterator i = typeMungers.iterator(); i.hasNext();) {
  321. EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
  322. if (munger.matches(onType)) {
  323. if (needOldStyleWarning) {
  324. factory.showMessage(IMessage.WARNING,
  325. "The class for " + onType + " should be recompiled with ajc-1.1.1 for best results",
  326. onType.getSourceLocation(), null);
  327. needOldStyleWarning = false;
  328. }
  329. onType.addInterTypeMunger(munger);
  330. //TODO: Andy Should be done at weave time.
  331. // Unfortunately we can't do it at weave time unless the type mungers remember where
  332. // they came from. Thats why we do it here during complation because at this time
  333. // they do know their source location. I've put a flag in ResolvedTypeMunger that
  334. // records whether type mungers are currently set to remember their source location.
  335. // The flag is currently set to false, it should be set to true when we do the
  336. // work to version all AspectJ attributes.
  337. // (When done at weave time, it is done by invoking addRelationship() on
  338. // AsmRelationshipProvider (see BCELTypeMunger)
  339. if (!ResolvedTypeMunger.persistSourceLocation) // Do it up front if we bloody have to
  340. AsmInterTypeRelationshipProvider.getDefault().addRelationship(onType, munger);
  341. }
  342. }
  343. //???onType.checkInterTypeMungers();
  344. onType.checkInterTypeMungers();
  345. for (Iterator i = onType.getInterTypeMungers().iterator(); i.hasNext();) {
  346. EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
  347. //System.out.println("applying: " + munger + " to " + new String(sourceType.sourceName));
  348. munger.munge(sourceType);
  349. }
  350. if (skipInners) return;
  351. ReferenceBinding[] memberTypes = sourceType.memberTypes;
  352. for (int i = 0, length = memberTypes.length; i < length; i++) {
  353. if (memberTypes[i] instanceof SourceTypeBinding) {
  354. weaveInterTypeDeclarations((SourceTypeBinding) memberTypes[i], typeMungers, declareParents, false);
  355. }
  356. }
  357. }
  358. private void doDeclareParents(DeclareParents declareParents, SourceTypeBinding sourceType) {
  359. List newParents = declareParents.findMatchingNewParents(factory.fromEclipse(sourceType),false);
  360. if (!newParents.isEmpty()) {
  361. for (Iterator i = newParents.iterator(); i.hasNext(); ) {
  362. ResolvedTypeX parent = (ResolvedTypeX)i.next();
  363. if (dangerousInterfaces.containsKey(parent)) {
  364. ResolvedTypeX onType = factory.fromEclipse(sourceType);
  365. factory.showMessage(IMessage.ERROR,
  366. onType + ": " + dangerousInterfaces.get(parent),
  367. onType.getSourceLocation(), null);
  368. }
  369. AsmRelationshipProvider.getDefault().addDeclareParentsRelationship(declareParents.getSourceLocation(),factory.fromEclipse(sourceType), newParents);
  370. addParent(sourceType, parent);
  371. }
  372. }
  373. }
  374. private void reportDeclareParentsMessage(WeaveMessage.WeaveMessageKind wmk,SourceTypeBinding sourceType,ResolvedTypeX parent) {
  375. if (!factory.getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)) {
  376. String filename = new String(sourceType.getFileName());
  377. int takefrom = filename.lastIndexOf('/');
  378. if (takefrom == -1 ) takefrom = filename.lastIndexOf('\\');
  379. filename = filename.substring(takefrom+1);
  380. factory.getWorld().getMessageHandler().handleMessage(
  381. WeaveMessage.constructWeavingMessage(wmk,
  382. new String[]{CharOperation.toString(sourceType.compoundName),
  383. filename,
  384. parent.getClassName(),
  385. getShortname(parent.getSourceLocation().getSourceFile().getPath())}));
  386. }
  387. }
  388. private String getShortname(String path) {
  389. int takefrom = path.lastIndexOf('/');
  390. if (takefrom == -1) {
  391. takefrom = path.lastIndexOf('\\');
  392. }
  393. return path.substring(takefrom+1);
  394. }
  395. private void addParent(SourceTypeBinding sourceType, ResolvedTypeX parent) {
  396. ReferenceBinding parentBinding = (ReferenceBinding)factory.makeTypeBinding(parent);
  397. sourceType.rememberTypeHierarchy();
  398. if (parentBinding.isClass()) {
  399. sourceType.superclass = parentBinding;
  400. // this used to be true, but I think I've fixed it now, decp is done at weave time!
  401. // TAG: WeavingMessage DECLARE PARENTS: EXTENDS
  402. // Compiler restriction: Can't do EXTENDS at weave time
  403. // So, only see this message if doing a source compilation
  404. // reportDeclareParentsMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSEXTENDS,sourceType,parent);
  405. } else {
  406. ReferenceBinding[] oldI = sourceType.superInterfaces;
  407. ReferenceBinding[] newI;
  408. if (oldI == null) {
  409. newI = new ReferenceBinding[1];
  410. newI[0] = parentBinding;
  411. } else {
  412. int n = oldI.length;
  413. newI = new ReferenceBinding[n+1];
  414. System.arraycopy(oldI, 0, newI, 0, n);
  415. newI[n] = parentBinding;
  416. }
  417. sourceType.superInterfaces = newI;
  418. // warnOnAddedInterface(factory.fromEclipse(sourceType),parent); // now reported at weave time...
  419. // this used to be true, but I think I've fixed it now, decp is done at weave time!
  420. // TAG: WeavingMessage DECLARE PARENTS: IMPLEMENTS
  421. // This message will come out of BcelTypeMunger.munge if doing a binary weave
  422. // reportDeclareParentsMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSIMPLEMENTS,sourceType,parent);
  423. }
  424. }
  425. public void warnOnAddedInterface (ResolvedTypeX type, ResolvedTypeX parent) {
  426. World world = factory.getWorld();
  427. ResolvedTypeX serializable = world.getCoreType(TypeX.SERIALIZABLE);
  428. if (serializable.isAssignableFrom(type)
  429. && !serializable.isAssignableFrom(parent)
  430. && !LazyClassGen.hasSerialVersionUIDField(type)) {
  431. world.getLint().needsSerialVersionUIDField.signal(
  432. new String[] {
  433. type.getName().toString(),
  434. "added interface " + parent.getName().toString()
  435. },
  436. null,
  437. null);
  438. }
  439. }
  440. private List pendingTypesToFinish = new ArrayList();
  441. boolean inBinaryTypeCreationAndWeaving = false;
  442. boolean processingTheQueue = false;
  443. public BinaryTypeBinding createBinaryTypeFrom(
  444. IBinaryType binaryType,
  445. PackageBinding packageBinding,
  446. boolean needFieldsAndMethods,
  447. AccessRestriction accessRestriction)
  448. {
  449. if (inBinaryTypeCreationAndWeaving) {
  450. BinaryTypeBinding ret = super.createBinaryTypeFrom(
  451. binaryType,
  452. packageBinding,
  453. needFieldsAndMethods,
  454. accessRestriction);
  455. pendingTypesToFinish.add(ret);
  456. return ret;
  457. }
  458. inBinaryTypeCreationAndWeaving = true;
  459. try {
  460. BinaryTypeBinding ret = super.createBinaryTypeFrom(
  461. binaryType,
  462. packageBinding,
  463. needFieldsAndMethods,
  464. accessRestriction);
  465. weaveInterTypeDeclarations(ret);
  466. return ret;
  467. } finally {
  468. inBinaryTypeCreationAndWeaving = false;
  469. // Start processing the list...
  470. if (pendingTypesToFinish.size()>0) {
  471. processingTheQueue = true;
  472. while (!pendingTypesToFinish.isEmpty()) {
  473. BinaryTypeBinding nextVictim = (BinaryTypeBinding)pendingTypesToFinish.remove(0);
  474. // During this call we may recurse into this method and add
  475. // more entries to the pendingTypesToFinish list.
  476. weaveInterTypeDeclarations(nextVictim);
  477. }
  478. processingTheQueue = false;
  479. }
  480. }
  481. }
  482. }