From 9ce552b84bf6fa611349732b8be96699636bbada Mon Sep 17 00:00:00 2001 From: acolyer Date: Tue, 8 Jun 2004 14:01:58 +0000 Subject: [PATCH] changes from HEAD + updates for building inside eclipse --- org.aspectj.ajdt.core/.classpath | 26 +++++++++---------- .../org/aspectj/ajdt/ajc/BuildArgParser.java | 9 ++++--- .../org/aspectj/ajdt/core/AspectJCore.java | 4 +++ .../compiler/WeaverMessageHandler.java | 13 ++++++++++ .../ast/InterTypeMethodDeclaration.java | 4 +-- .../internal/core/builder/AjBuildConfig.java | 7 ++--- .../internal/core/builder/AspectJBuilder.java | 23 +++++++++++----- .../core/builder/EclipseClassPathManager.java | 6 +++++ 8 files changed, 63 insertions(+), 29 deletions(-) diff --git a/org.aspectj.ajdt.core/.classpath b/org.aspectj.ajdt.core/.classpath index 0f9073da2..c98495474 100644 --- a/org.aspectj.ajdt.core/.classpath +++ b/org.aspectj.ajdt.core/.classpath @@ -1,16 +1,16 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index 70160a203..d010975a4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -88,7 +88,9 @@ public class BuildArgParser extends Main { * which will be invalid unless there are no handler errors. */ public AjBuildConfig genBuildConfig(String[] args) { - return genBuildConfig(args, true, null); + AjBuildConfig config = new AjBuildConfig(); + populateBuildConfig(config, args, true, null); + return config; } /** @@ -100,8 +102,7 @@ public class BuildArgParser extends Main { * @return AjBuildConfig per args, * which will be invalid unless there are no handler errors. */ - public AjBuildConfig genBuildConfig(String[] args, boolean setClasspath, File configFile) { - AjBuildConfig buildConfig = new AjBuildConfig(); + public AjBuildConfig populateBuildConfig(AjBuildConfig buildConfig, String[] args, boolean setClasspath, File configFile) { buildConfig.setConfigFile(configFile); try { // sets filenames to be non-null in order to make sure that file paramters are ignored @@ -124,7 +125,7 @@ public class BuildArgParser extends Main { } List javaArgList = new ArrayList(); - // disable all special eclipse warnings by default + // disable all special eclipse warnings by default - why??? //??? might want to instead override getDefaultOptions() javaArgList.add("-warn:none"); // these next four lines are some nonsense to fool the eclipse batch compiler diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/core/AspectJCore.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/core/AspectJCore.java index ef35459e0..f80fd75c1 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/core/AspectJCore.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/core/AspectJCore.java @@ -42,6 +42,10 @@ public class AspectJCore extends JavaCore { super(pluginDescriptor); } + public static AspectJCore getAspectJCore() { + return (AspectJCore) getPlugin(); + } + /* (non-Javadoc) * @see org.eclipse.jdt.core.JavaCore#getCompilerOptions() */ diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverMessageHandler.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverMessageHandler.java index 5f2f49f72..71017a6c3 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverMessageHandler.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverMessageHandler.java @@ -49,6 +49,19 @@ public class WeaverMessageHandler implements IMessageHandler { if (! (message.isError() || message.isWarning()) ) return sink.handleMessage(message); // we only care about warnings and errors here... ISourceLocation sLoc = message.getSourceLocation(); + + // See bug 62073. We should assert that the caller pass the correct primary source location. + // But for AJ1.2 final we will simply do less processing of the locations if that is not the + // case (By calling sink.handleMessage()) - this ensures we don't put out bogus source context info. + if (sLoc instanceof EclipseSourceLocation) { + EclipseSourceLocation esLoc = (EclipseSourceLocation)sLoc; + if (currentlyWeaving!=null && esLoc.getCompilationResult()!=null) { + if (!currentlyWeaving.equals(((EclipseSourceLocation)sLoc).getCompilationResult())) + return sink.handleMessage(message); + // throw new RuntimeException("Primary source location must match the file we are currently processing!"); + } + } + CompilationResult problemSource = currentlyWeaving; if (problemSource == null) { // must be a problem found during completeTypeBindings phase of begin to compile diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java index ef69dc022..1027ba067 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java @@ -104,8 +104,8 @@ public class InterTypeMethodDeclaration extends InterTypeDeclaration { binding = classScope.referenceContext.binding.resolveTypesFor(binding); if (binding == null) { // if binding is null, we failed to find a type used in the method params, this error - // has already been reported. - throw new AbortCompilation(); + // has already been reported. + throw new AbortCompilation(compilationResult); } ResolvedMember sig = new ResolvedMember(Member.METHOD, EclipseFactory.fromBinding(onTypeBinding), declaredModifiers, EclipseFactory.fromBinding(binding.returnType), new String(declaredSelector), diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java index 51f539f3b..74f5c4767 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java @@ -299,9 +299,10 @@ public class AjBuildConfig { // XXX needs bootclasspath? * @param global the AjBuildConfig to read globals from */ public void installGlobals(AjBuildConfig global) { // XXX relies on default values - Map optionsMap = options.getMap(); - join(optionsMap,global.getOptions().getMap()); - options.set(optionsMap); + // don't join the options - they already have defaults taken care of. +// Map optionsMap = options.getMap(); +// join(optionsMap,global.getOptions().getMap()); +// options.set(optionsMap); join(aspectpath, global.aspectpath); join(classpath, global.classpath); if (null == configFile) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java index da10e2e6d..276f708b8 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java @@ -65,6 +65,7 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto // One builder instance per project (important) private BcelWeaver myWeaver = null; private BcelWorld myBcelWorld = null; + private EclipseClassPathManager cpManager = null; private UnwovenResultCollector unwovenResultCollector = null; private OutputFileNameProvider fileNameProvider = null; @@ -97,10 +98,16 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto * @see org.eclipse.jdt.internal.compiler.ICompilerAdapterFactory#getAdapter(org.eclipse.jdt.internal.compiler.Compiler) */ public ICompilerAdapter getAdapter(Compiler forCompiler) { - AjCompilerOptions options = (AjCompilerOptions) forCompiler.options; + Map javaOptions = forCompiler.options.getMap(); + // TODO get aspectj options from project and add into map before... + AjCompilerOptions ajOptions = new AjCompilerOptions(javaOptions); + forCompiler.options = ajOptions; if (isBatchBuild || myBcelWorld == null || myWeaver == null) { - initWorldAndWeaver(options); + initWorldAndWeaver(ajOptions); + } else { + // update the nameEnvironment each time we compile... + cpManager.setNameEnvironment(nameEnvironment); } // * an eclipse factory -- create from AjLookupEnvironment, need to hide AjBuildManager field @@ -110,7 +117,9 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto forCompiler.problemReporter = pr; AjLookupEnvironment le = new AjLookupEnvironment(forCompiler, forCompiler.options, pr,nameEnvironment); - EclipseFactory eFactory = new EclipseFactory(le,myBcelWorld,options.xSerializableAspects); + EclipseFactory eFactory = new EclipseFactory(le,myBcelWorld,ajOptions.xSerializableAspects); + le.factory = eFactory; + forCompiler.lookupEnvironment = le; AjBuildNotifier ajNotifier = (AjBuildNotifier) notifier; if (fileNameProvider == null ) fileNameProvider = new OutputFileNameProvider(getProject()); @@ -130,7 +139,7 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto return new AjCompilerAdapter(forCompiler,isBatchBuild,myBcelWorld, myWeaver,eFactory,unwovenResultCollector,ajNotifier,fileNameProvider,bsProvider, fullBinarySourceEntries,resultSetForFullWeave, - options.noWeave); + ajOptions.noWeave); } /* (non-Javadoc) @@ -143,8 +152,8 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto private void initWorldAndWeaver(AjCompilerOptions options) { - EclipseClassPathManager cpMgr = new EclipseClassPathManager(nameEnvironment); - myBcelWorld = new BcelWorld(cpMgr,new UnhandledMessageHandler(getProject()),null /*(xrefHandler)*/); + cpManager = new EclipseClassPathManager(nameEnvironment); + myBcelWorld = new BcelWorld(cpManager,new UnhandledMessageHandler(getProject()),null /*(xrefHandler)*/); myBcelWorld.setXnoInline(options.xNoInline); myBcelWorld.setXlazyTjp(options.xLazyThisJoinPoint); setLintProperties(myBcelWorld,options); @@ -203,7 +212,7 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto public boolean handleMessage(IMessage message) throws AbortException { try { IMarker marker = project.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); - marker.setAttribute(IMarker.MESSAGE, message); + marker.setAttribute(IMarker.MESSAGE, message.getMessage()); marker.setAttribute(IMarker.SEVERITY, message.isError() ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING); } catch (CoreException e) { AspectJCore.getPlugin().getLog().log(e.getStatus()); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseClassPathManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseClassPathManager.java index 38e3a889f..84e521c03 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseClassPathManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseClassPathManager.java @@ -38,6 +38,12 @@ public class EclipseClassPathManager extends ClassPathManager { this.nameEnv = env; } + // class path manager will be used by weaver across multiple compiles, + // whereas a name environment may be constructed per-compile. + public void setNameEnvironment(INameEnvironment env) { + this.nameEnv = env; + } + /* (non-Javadoc) * @see org.aspectj.weaver.bcel.ClassPathManager#addPath(java.lang.String, org.aspectj.bridge.IMessageHandler) */ -- 2.39.5