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.

AjCompiler.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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 Eclipse Public License v 2.0
  6. // * which accompanies this distribution and is available at
  7. // * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. // *
  9. // * Contributors:
  10. // * PARC initial implementation
  11. // * ******************************************************************/
  12. //
  13. //
  14. //package org.aspectj.ajdt.internal.compiler;
  15. //
  16. //import java.io.IOException;
  17. //import java.util.ArrayList;
  18. //import java.util.Collection;
  19. //import java.util.Collections;
  20. //import java.util.Enumeration;
  21. //import java.util.Hashtable;
  22. //import java.util.Iterator;
  23. //import java.util.List;
  24. //import java.util.Map;
  25. //
  26. //import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
  27. //import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
  28. //import org.aspectj.bridge.AbortException;
  29. //import org.aspectj.bridge.IMessage;
  30. //import org.aspectj.bridge.IMessageHandler;
  31. //import org.aspectj.bridge.ISourceLocation;
  32. //import org.aspectj.bridge.IMessage.Kind;
  33. //import org.aspectj.weaver.IClassFileProvider;
  34. //import org.aspectj.weaver.IWeaveRequestor;
  35. //import org.aspectj.weaver.bcel.BcelWeaver;
  36. //import org.aspectj.weaver.bcel.BcelWorld;
  37. //import org.aspectj.weaver.bcel.Pause;
  38. //import org.aspectj.weaver.bcel.UnwovenClassFile;
  39. //import org.aspectj.weaver.bcel.UnwovenClassFileWithThirdPartyManagedBytecode;
  40. //import org.eclipse.jdt.core.compiler.IProblem;
  41. //import org.eclipse.jdt.internal.compiler.ClassFile;
  42. //import org.eclipse.jdt.internal.compiler.CompilationResult;
  43. //import org.eclipse.jdt.internal.compiler.Compiler;
  44. //import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
  45. //import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
  46. //import org.eclipse.jdt.internal.compiler.IProblemFactory;
  47. //import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
  48. //import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
  49. //import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
  50. //import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
  51. //import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
  52. //import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
  53. //
  54. //
  55. //public class AjCompiler extends Compiler {
  56. //
  57. // private List /*InterimResult*/ resultsPendingWeave = new ArrayList();
  58. // private BcelWorld bcelWorld;
  59. // private BcelWeaver bcelWeaver;
  60. // private IIntermediateResultsRequestor intermediateResultRequestor;
  61. // private IOutputClassFileNameProvider nameProvider;
  62. // private List /*<InterimResult>*/ binarySources = new ArrayList();
  63. // private boolean skipTheWeavePhase = false;
  64. // private boolean reportedErrors = false;
  65. // private WeaverMessageHandler wmHandler;
  66. // private boolean isBatchCompile = false;
  67. // private Collection /*InterimResult*/ resultSetForFullWeave = Collections.EMPTY_LIST;
  68. //
  69. // public interface IIntermediateResultsRequestor {
  70. // void acceptResult(InterimResult intRes);
  71. // }
  72. //
  73. // public interface IOutputClassFileNameProvider {
  74. // String getOutputClassFileName(char[] eclipseClassFileName, CompilationResult result);
  75. // }
  76. //
  77. // public AjCompiler(
  78. // INameEnvironment environment,
  79. // IErrorHandlingPolicy policy,
  80. // Map settings,
  81. // ICompilerRequestor requestor,
  82. // IProblemFactory problemFactory) {
  83. // super(environment, policy, settings, requestor, problemFactory);
  84. // }
  85. //
  86. // public AjCompiler(
  87. // INameEnvironment environment,
  88. // IErrorHandlingPolicy policy,
  89. // Map settings,
  90. // ICompilerRequestor requestor,
  91. // IProblemFactory problemFactory,
  92. // boolean parseLiteralExpressionsAsConstants) {
  93. // super(
  94. // environment,
  95. // policy,
  96. // settings,
  97. // requestor,
  98. // problemFactory,
  99. // parseLiteralExpressionsAsConstants);
  100. // }
  101. //
  102. //
  103. // public void setWeaver(BcelWeaver weaver) {
  104. // this.bcelWeaver = weaver;
  105. // }
  106. //
  107. // public void setWorld(BcelWorld world) {
  108. // this.bcelWorld = world;
  109. // IMessageHandler msgHandler = world.getMessageHandler();
  110. // wmHandler = new WeaverMessageHandler(msgHandler);
  111. // world.setMessageHandler(wmHandler);
  112. // }
  113. //
  114. // public void prepareForBatchCompilation() {
  115. // isBatchCompile = true;
  116. // }
  117. //
  118. // public void setIntermediateResultsRequestor(IIntermediateResultsRequestor intReq) {
  119. // this.intermediateResultRequestor = intReq;
  120. // }
  121. //
  122. // public void setNoWeave(boolean noWeave) {
  123. // skipTheWeavePhase = noWeave;
  124. // }
  125. //
  126. // public void setFullWeaveResults(Collection compilationResults) {
  127. // resultSetForFullWeave = compilationResults;
  128. // }
  129. //
  130. // public void setOutputFileNameProvider(IOutputClassFileNameProvider p) {
  131. // this.nameProvider = p;
  132. // }
  133. //
  134. // public void addBinarySourceFiles(Map binarySourceEntries) {
  135. // // Map is fileName |-> List<UnwovenClassFile>
  136. // for (Iterator binIter = binarySourceEntries.keySet().iterator(); binIter.hasNext();) {
  137. // String sourceFileName = (String) binIter.next();
  138. // List unwovenClassFiles = (List) binarySourceEntries.get(sourceFileName);
  139. //
  140. // CompilationResult result = new CompilationResult(sourceFileName.toCharArray(),0,0,20);
  141. // result.noSourceAvailable();
  142. // InterimResult binarySource = new InterimResult(result,nameProvider);
  143. // binarySource.unwovenClassFiles = new UnwovenClassFile[unwovenClassFiles.size()];
  144. // int index = 0;
  145. // for (Iterator iter = unwovenClassFiles.iterator(); iter.hasNext();) {
  146. // UnwovenClassFile element = (UnwovenClassFile) iter.next();
  147. // binarySource.unwovenClassFiles[index] = element;
  148. // AjClassFile ajcf = new AjClassFile(element.getClassName().replace('.', '/').toCharArray(),
  149. // element.getBytes());
  150. // result.record(ajcf.fileName(),ajcf);
  151. // index++;
  152. // }
  153. // binarySources.add(binarySource);
  154. // }
  155. // }
  156. //
  157. //
  158. // /**
  159. // * In addition to processing each compilation unit in the normal ways,
  160. // * we also need to do weaving for inter-type declarations. This
  161. // * must be done before we use the signatures of these types to do any
  162. // * name binding.
  163. // */
  164. // public void process(CompilationUnitDeclaration unit, int i) {
  165. // EclipseFactory world =
  166. // EclipseFactory.fromLookupEnvironment(lookupEnvironment);
  167. // world.showMessage(IMessage.INFO, "compiling " + new String(unit.getFileName()), null, null);
  168. // super.process(unit, i);
  169. //
  170. // world.finishedCompilationUnit(unit);
  171. // }
  172. //
  173. //
  174. // /* (non-Javadoc)
  175. // * @see org.eclipse.jdt.internal.compiler.Compiler#compile(org.eclipse.jdt.internal.compiler.env.ICompilationUnit[])
  176. // * We override this method to defer handing of results to the caller until the weave phase has
  177. // * completed too. That way the class files are in final form and all error messages relating to the
  178. // * compilation unit have been reported (which is the contract the JDT expects from this method).
  179. // */
  180. // public void compile(ICompilationUnit[] sourceUnits) {
  181. // try {
  182. // resultsPendingWeave = new ArrayList();
  183. // reportedErrors = false;
  184. // super.compile(sourceUnits);
  185. // Pause.pause("After super compile");
  186. // try {
  187. // if (!(skipTheWeavePhase || reportedErrors)) {
  188. // weaveResults();
  189. // Pause.pause("After weave");
  190. // } else {
  191. // notifyRequestor(); // weaver notifies as it goes along...
  192. // }
  193. // } catch (IOException ex) {
  194. // // TODO
  195. // ex.printStackTrace();
  196. // }
  197. // } finally {
  198. // cleanup();
  199. // }
  200. // }
  201. //
  202. //
  203. // /* (non-Javadoc)
  204. // * @see org.eclipse.jdt.internal.compiler.Compiler#registerCompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult)
  205. // */
  206. // protected void registerCompilationResult(int index, CompilationResult result) {
  207. // InterimResult intRes = new InterimResult(result,nameProvider);
  208. // resultsPendingWeave.add(intRes);
  209. // if (result.hasErrors()) reportedErrors = true;
  210. // if (intermediateResultRequestor != null) {
  211. // intermediateResultRequestor.acceptResult(intRes);
  212. // }
  213. // }
  214. //
  215. // /* (non-Javadoc)
  216. // * @see org.eclipse.jdt.internal.compiler.Compiler#reset()
  217. // * Super does this too early for us...
  218. // */
  219. // public void reset() {
  220. // // no-op, super calls this too early for us...
  221. // }
  222. //
  223. // /* (non-Javadoc)
  224. // * @see org.eclipse.jdt.internal.compiler.Compiler#resolve(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration, org.eclipse.jdt.internal.compiler.env.ICompilationUnit, boolean, boolean, boolean)
  225. // */
  226. // public CompilationUnitDeclaration resolve(CompilationUnitDeclaration unit,
  227. // ICompilationUnit sourceUnit, boolean verifyMethods,
  228. // boolean analyzeCode, boolean generateCode) {
  229. // // TODO include weave phase in resolution too...
  230. // return super.resolve(unit, sourceUnit, verifyMethods, analyzeCode,
  231. // generateCode);
  232. // }
  233. //
  234. //
  235. // // AspectJ helper methods, called from compile...
  236. // private void weaveResults() throws IOException {
  237. // // ensure weaver state is set up correctly
  238. // for (Iterator iter = resultsPendingWeave.iterator(); iter.hasNext();) {
  239. // InterimResult iresult = (InterimResult) iter.next();
  240. // for (int i = 0; i < iresult.unwovenClassFiles.length; i++) {
  241. // bcelWeaver.addClassFile(iresult.unwovenClassFiles[i]);
  242. // }
  243. // }
  244. // Pause.pause("After adding class files to weaver");
  245. // bcelWeaver.prepareForWeave();
  246. // Pause.pause("After preparing for weave");
  247. // if (isBatchCompile) {
  248. // resultsPendingWeave.addAll(binarySources);
  249. // // passed into the compiler, the set of classes in injars and inpath...
  250. // } else if (bcelWeaver.needToReweaveWorld()) {
  251. // addAllKnownClassesToWeaveList();
  252. // }
  253. // Pause.pause("After adding binary sources to weaver");
  254. // bcelWeaver.weave(new WeaverAdaptor(this));
  255. // }
  256. //
  257. // private void notifyRequestor() {
  258. // for (Iterator iter = resultsPendingWeave.iterator(); iter.hasNext();) {
  259. // InterimResult iresult = (InterimResult) iter.next();
  260. // requestor.acceptResult(iresult.result.tagAsAccepted());
  261. // }
  262. // }
  263. //
  264. // private void cleanup() {
  265. // resultsPendingWeave = null;
  266. // isBatchCompile = false;
  267. // binarySources = new ArrayList();
  268. // resultSetForFullWeave = Collections.EMPTY_LIST;
  269. // super.reset();
  270. // Pause.pause("After notify and cleanup");
  271. // }
  272. //
  273. // private void addAllKnownClassesToWeaveList() {
  274. // // results pending weave already has some results from this (incremental) compile
  275. // // add in results from any other source
  276. // for (Iterator iter = resultSetForFullWeave.iterator(); iter.hasNext();) {
  277. // InterimResult ir = (InterimResult) iter.next();
  278. // if (!resultsPendingWeave.contains(ir)) { // equality based on source file name...
  279. // ir.result.hasBeenAccepted = false; // it may have been accepted before, start again
  280. // resultsPendingWeave.add(ir);
  281. // }
  282. // }
  283. // }
  284. //
  285. // // Helper class that feeds input to the weaver, and accepts results
  286. // // =======================================================================================
  287. // private static class WeaverAdaptor implements IClassFileProvider, IWeaveRequestor, Iterator {
  288. //
  289. // private AjCompiler compiler;
  290. // private Iterator resultIterator;
  291. // private int classFileIndex = 0;
  292. // private InterimResult nowProcessing;
  293. // private InterimResult lastReturnedResult;
  294. //// private CompilationResult lastAcceptedResult;
  295. // private boolean finalPhase = false;
  296. //
  297. //
  298. // public WeaverAdaptor(AjCompiler forCompiler) { this.compiler = forCompiler; }
  299. //
  300. // /* (non-Javadoc)
  301. // * @see org.aspectj.weaver.IClassFileProvider#getClassFileIterator()
  302. // */
  303. // public Iterator getClassFileIterator() {
  304. // classFileIndex = 0;
  305. // nowProcessing = null;
  306. // lastReturnedResult = null;
  307. // resultIterator = compiler.resultsPendingWeave.iterator();
  308. // return this;
  309. // }
  310. // /* (non-Javadoc)
  311. // * @see org.aspectj.weaver.IClassFileProvider#getRequestor()
  312. // */
  313. // public IWeaveRequestor getRequestor() {
  314. // return this;
  315. // }
  316. // /* (non-Javadoc)
  317. // * @see org.aspectj.weaver.IWeaveRequestor#acceptResult(org.aspectj.weaver.bcel.UnwovenClassFile)
  318. // */
  319. // public void acceptResult(UnwovenClassFile result) {
  320. // char[] key = result.getClassName().replace('.','/').toCharArray();
  321. // removeFromHashtable(lastReturnedResult.result.compiledTypes,key);
  322. // String className = result.getClassName().replace('.', '/');
  323. // AjClassFile ajcf = new AjClassFile(className.toCharArray(),
  324. // result.getBytes());
  325. // lastReturnedResult.result.record(ajcf.fileName(),ajcf);
  326. //// if ( f(lastAcceptedResult != null) && (lastReturnedResult.result != lastAcceptedResult)) {
  327. //// // we've got everything we need for lastAcceptedResult, push the result out
  328. //// // and free up the memory.
  329. //// finishedWith(lastAcceptedResult);
  330. //// }
  331. //// lastAcceptedResult = lastReturnedResult.result;
  332. // }
  333. //
  334. // private void finishedWith(InterimResult result) {
  335. // compiler.requestor.acceptResult(result.result.tagAsAccepted());
  336. // for (int i = 0; i < compiler.unitsToProcess.length; i++) {
  337. // if (compiler.unitsToProcess[i] != null) {
  338. // if (compiler.unitsToProcess[i].compilationResult == result.result) {
  339. // compiler.unitsToProcess[i] = null;
  340. // }
  341. // }
  342. // }
  343. // }
  344. //
  345. // /* (non-Javadoc)
  346. // * @see java.util.Iterator#hasNext()
  347. // */
  348. // public boolean hasNext() {
  349. // if (nowProcessing == null) {
  350. // if (!resultIterator.hasNext()) return false;
  351. // nowProcessing = (InterimResult) resultIterator.next();
  352. // classFileIndex = 0;
  353. // }
  354. // while (nowProcessing.unwovenClassFiles.length == 0 ) {
  355. // if (!resultIterator.hasNext()) return false;
  356. // nowProcessing = (InterimResult) resultIterator.next();
  357. // }
  358. // if (classFileIndex < nowProcessing.unwovenClassFiles.length) {
  359. // return true;
  360. // } else {
  361. // classFileIndex = 0;
  362. // if (!resultIterator.hasNext()) return false;
  363. // nowProcessing = (InterimResult) resultIterator.next();
  364. // while (nowProcessing.unwovenClassFiles.length == 0 ) {
  365. // if (!resultIterator.hasNext()) return false;
  366. // nowProcessing = (InterimResult) resultIterator.next();
  367. // }
  368. // }
  369. // return true;
  370. // }
  371. // /* (non-Javadoc)
  372. // * @see java.util.Iterator#next()
  373. // */
  374. // public Object next() {
  375. // if (!hasNext()) return null; // sets up indices correctly
  376. // if (finalPhase) {
  377. // if ((lastReturnedResult != null) && (lastReturnedResult != nowProcessing)) {
  378. // // we're done with the lastReturnedResult
  379. // finishedWith(lastReturnedResult);
  380. // }
  381. // }
  382. // lastReturnedResult = nowProcessing;
  383. // compiler.wmHandler.setCurrentResult(nowProcessing.result);
  384. // return nowProcessing.unwovenClassFiles[classFileIndex++];
  385. // }
  386. // /* (non-Javadoc)
  387. // * @see java.util.Iterator#remove()
  388. // */
  389. // public void remove() {
  390. // throw new UnsupportedOperationException();
  391. // }
  392. //
  393. // public void processingReweavableState() {}
  394. // public void addingTypeMungers() {}
  395. // public void weavingAspects() {}
  396. // public void weavingClasses() {finalPhase = true;}
  397. // public void weaveCompleted() {
  398. // if ((lastReturnedResult != null) && (!lastReturnedResult.result.hasBeenAccepted)) {
  399. // finishedWith(lastReturnedResult);
  400. // }
  401. // }
  402. //
  403. // private void removeFromHashtable(Hashtable table, char[] key) {
  404. // // jdt uses char[] as a key in the hashtable, which is not very useful as equality is based on being
  405. // // the same array, not having the same content.
  406. // String skey = new String(key);
  407. // char[] victim = null;
  408. // for (Enumeration iter = table.keys(); iter.hasMoreElements();) {
  409. // char[] thisKey = (char[]) iter.nextElement();
  410. // if (skey.equals(new String(thisKey))) {
  411. // victim = thisKey;
  412. // break;
  413. // }
  414. // }
  415. // if (victim != null) {
  416. // table.remove(victim);
  417. // }
  418. // }
  419. //}
  420. //
  421. // // Holder for intermediate form (class files)
  422. // // =======================================================================================
  423. // public static class InterimResult {
  424. // public CompilationResult result;
  425. // public UnwovenClassFile[] unwovenClassFiles; // longer term would be nice not to have two copies of
  426. // // the byte codes, one in result.classFiles and another
  427. // // in unwovenClassFiles;
  428. // private AjCompiler.IOutputClassFileNameProvider nameGen;
  429. //// public String[] classNames; // entry at index i is the name of the class at unwovenClassFiles[i]
  430. //// public BcelObjectType[] classTypes; // entry at i is the resolved type of the class at unwovenClassFiles[i]
  431. // public InterimResult(CompilationResult cr, AjCompiler.IOutputClassFileNameProvider np) {
  432. // result = cr;
  433. // nameGen = np;
  434. // unwovenClassFiles = ClassFileBasedByteCodeProvider.unwovenClassFilesFor(result,nameGen);
  435. // }
  436. //
  437. // public String fileName() {
  438. // return new String(result.fileName);
  439. // }
  440. //
  441. // public boolean equals(Object other) {
  442. // if( other == null || !(other instanceof InterimResult)) {
  443. // return false;
  444. // }
  445. // InterimResult ir = (InterimResult) other;
  446. // return fileName().equals(ir.fileName());
  447. // }
  448. // public int hashCode() {
  449. // return fileName().hashCode();
  450. // }
  451. // };
  452. //
  453. //
  454. //
  455. // // XXX lightweight subclass of ClassFile that only genuinely supports fileName and getBytes
  456. // // operations.
  457. // // =========================================================================================
  458. // private static class AjClassFile extends ClassFile {
  459. //
  460. // char[] filename;
  461. // byte[] bytes;
  462. //
  463. // public AjClassFile(char[] fileName, byte[] byteCodes) {
  464. // this.filename = fileName;
  465. // bytes = byteCodes;
  466. // }
  467. //
  468. // public char[] fileName() {
  469. // return filename;
  470. // }
  471. //
  472. // public byte[] getBytes() {
  473. // return bytes;
  474. // }
  475. // };
  476. //
  477. //
  478. // // Adaptor for ClassFiles that lets them act as the bytecode repository
  479. // // for UnwovenClassFiles (asking a ClassFile for its bytes causes a
  480. // // copy to be made).
  481. // private static class ClassFileBasedByteCodeProvider
  482. // implements UnwovenClassFileWithThirdPartyManagedBytecode.IByteCodeProvider {
  483. // private ClassFile cf;
  484. //
  485. // public ClassFileBasedByteCodeProvider(ClassFile cf) {
  486. // this.cf = cf;
  487. // }
  488. //
  489. // public byte[] getBytes() {
  490. // return cf.getBytes();
  491. // }
  492. //
  493. // public static UnwovenClassFile[] unwovenClassFilesFor(CompilationResult result,
  494. // AjCompiler.IOutputClassFileNameProvider nameProvider) {
  495. // ClassFile[] cfs = result.getClassFiles();
  496. // UnwovenClassFile[] ret = new UnwovenClassFile[cfs.length];
  497. // for (int i = 0; i < ret.length; i++) {
  498. // ClassFileBasedByteCodeProvider p = new ClassFileBasedByteCodeProvider(cfs[i]);
  499. // String fileName = nameProvider.getOutputClassFileName(cfs[i].fileName(), result);
  500. // ret[i] = new UnwovenClassFileWithThirdPartyManagedBytecode(fileName,p);
  501. // }
  502. // return ret;
  503. // }
  504. //
  505. // }
  506. //
  507. // // Inner class for handling messages produced by the weaver
  508. // // ==========================================================
  509. //
  510. // private class WeaverMessageHandler implements IMessageHandler {
  511. // IMessageHandler sink;
  512. // CompilationResult currentlyWeaving;
  513. //
  514. // public WeaverMessageHandler(IMessageHandler handler) {
  515. // this.sink = handler;
  516. // }
  517. //
  518. // public void setCurrentResult(CompilationResult result) {
  519. // currentlyWeaving = result;
  520. // }
  521. //
  522. // public boolean handleMessage(IMessage message) throws AbortException {
  523. // if (! (message.isError() || message.isWarning()) ) return sink.handleMessage(message);
  524. // // we only care about warnings and errors here...
  525. // ISourceLocation sLoc = message.getSourceLocation();
  526. // CompilationResult problemSource = currentlyWeaving;
  527. // if (problemSource == null) {
  528. // // must be a problem found during completeTypeBindings phase of begin to compile
  529. // if (sLoc instanceof EclipseSourceLocation) {
  530. // problemSource = ((EclipseSourceLocation)sLoc).getCompilationResult();
  531. // }
  532. // if (problemSource == null) {
  533. // // XXX this is ok for ajc, will have to do better for AJDT in time...
  534. // return sink.handleMessage(message);
  535. // }
  536. // }
  537. // int startPos = getStartPos(sLoc,problemSource);
  538. // int endPos = getEndPos(sLoc,problemSource);
  539. // int severity = message.isError() ? ProblemSeverities.Error : ProblemSeverities.Warning;
  540. // char[] filename = problemSource.fileName;
  541. // boolean usedBinarySourceFileName = false;
  542. // if (problemSource.isFromBinarySource()) {
  543. // if (sLoc != null) {
  544. // filename = sLoc.getSourceFile().getPath().toCharArray();
  545. // usedBinarySourceFileName = true;
  546. // }
  547. // }
  548. // ReferenceContext referenceContext = findReferenceContextFor(problemSource);
  549. // IProblem problem = problemReporter.createProblem(
  550. // filename,
  551. // IProblem.Unclassified,
  552. // new String[0],
  553. // new String[] {message.getMessage()},
  554. // severity,
  555. // startPos,
  556. // endPos,
  557. // sLoc != null ? sLoc.getLine() : 1,
  558. // referenceContext,
  559. // problemSource
  560. // );
  561. // IProblem[] seeAlso = buildSeeAlsoProblems(message.getExtraSourceLocations(),
  562. // problemSource,
  563. // usedBinarySourceFileName);
  564. // problem.setSeeAlsoProblems(seeAlso);
  565. // if (message.getDetails() != null) {
  566. // problem.setSupplementaryMessageInfo(message.getDetails());
  567. // }
  568. // problemReporter.record(problem, problemSource, referenceContext);
  569. // return true;
  570. //// if (weavingPhase) {
  571. //// return sink.handleMessage(message);
  572. //// } else {
  573. //// return true; // message will be reported back in compilation result later...
  574. //// }
  575. // }
  576. //
  577. // public boolean isIgnoring(Kind kind) {
  578. // return sink.isIgnoring(kind);
  579. // }
  580. //
  581. // private int getStartPos(ISourceLocation sLoc,CompilationResult result) {
  582. // int pos = 0;
  583. // if (sLoc == null) return 0;
  584. // int line = sLoc.getLine();
  585. // if (sLoc instanceof EclipseSourceLocation) {
  586. // pos = ((EclipseSourceLocation)sLoc).getStartPos();
  587. // } else {
  588. // if (line <= 1) return 0;
  589. // if (result != null) {
  590. // if ((result.lineSeparatorPositions != null) &&
  591. // (result.lineSeparatorPositions.length >= (line-1))) {
  592. // pos = result.lineSeparatorPositions[line-2] + 1;
  593. // }
  594. // }
  595. // }
  596. // return pos;
  597. // }
  598. //
  599. // private int getEndPos(ISourceLocation sLoc,CompilationResult result) {
  600. // int pos = 0;
  601. // if (sLoc == null) return 0;
  602. // int line = sLoc.getLine();
  603. // if (line <= 0) line = 1;
  604. // if (sLoc instanceof EclipseSourceLocation) {
  605. // pos = ((EclipseSourceLocation)sLoc).getEndPos();
  606. // } else {
  607. // if (result != null) {
  608. // if ((result.lineSeparatorPositions != null) &&
  609. // (result.lineSeparatorPositions.length >= line)) {
  610. // pos = result.lineSeparatorPositions[line -1] -1;
  611. // }
  612. // }
  613. // }
  614. // return pos;
  615. // }
  616. //
  617. // private ReferenceContext findReferenceContextFor(CompilationResult result) {
  618. // ReferenceContext context = null;
  619. // if (unitsToProcess == null) return null;
  620. // for (int i = 0; i < unitsToProcess.length; i++) {
  621. // if ((unitsToProcess[i] != null) &&
  622. // (unitsToProcess[i].compilationResult == result)) {
  623. // context = unitsToProcess[i];
  624. // break;
  625. // }
  626. // }
  627. // return context;
  628. // }
  629. //
  630. // private IProblem[] buildSeeAlsoProblems(List sourceLocations,
  631. // CompilationResult problemSource,
  632. // boolean usedBinarySourceFileName) {
  633. // int probLength = sourceLocations.size();
  634. // if (usedBinarySourceFileName) probLength++;
  635. // IProblem[] ret = new IProblem[probLength];
  636. // for (int i = 0; i < sourceLocations.size(); i++) {
  637. // ISourceLocation loc = (ISourceLocation) sourceLocations.get(i);
  638. // ret[i] = new DefaultProblem(loc.getSourceFile().getPath().toCharArray(),
  639. // "see also",
  640. // 0,
  641. // new String[] {},
  642. // ProblemSeverities.Ignore,
  643. // getStartPos(loc,null),
  644. // getEndPos(loc,null),
  645. // loc.getLine());
  646. // }
  647. // if (usedBinarySourceFileName) {
  648. // ret[ret.length -1] = new DefaultProblem(problemSource.fileName,"see also",0,new String[] {},
  649. // ProblemSeverities.Ignore,0,
  650. // 0,0);
  651. // }
  652. // return ret;
  653. // }
  654. // }
  655. //
  656. //}