diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2023-01-29 14:57:58 +0100 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2024-04-13 13:03:06 +0200 |
commit | a1a700fc6eb8793d7bfa08a31a4529eb2e49b84c (patch) | |
tree | 44ab93d62981e1310327bdf351281a9e5d834173 /org.aspectj.ajdt.core | |
parent | 287ec8f5ef52510b36b05331e69b7dd579c01ecf (diff) | |
download | aspectj-a1a700fc6eb8793d7bfa08a31a4529eb2e49b84c.tar.gz aspectj-a1a700fc6eb8793d7bfa08a31a4529eb2e49b84c.zip |
Implement source location matching for weave messages in XML tests
WIP (work in progress).
Closes #218.
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'org.aspectj.ajdt.core')
2 files changed, 42 insertions, 18 deletions
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java index cbd21e585..274bf1e90 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java @@ -108,8 +108,12 @@ public class EclipseSourceLocation implements ISourceLocation { public String getContext() { if (null == context) { - ICompilationUnit compilationUnit = result.compilationUnit; - IProblem[] problems = result.problems; + ICompilationUnit compilationUnit = null; + IProblem[] problems = null; + if (result != null) { + compilationUnit = result.compilationUnit; + problems = result.problems; + } if ((null == compilationUnit) || (null == problems) || (1 != problems.length)) { // ?? which of n>1 problems? context = NO_CONTEXT; diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java index bc934815c..0a8f0fcfc 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java @@ -33,6 +33,7 @@ import java.util.stream.Collectors; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; +import org.aspectj.bridge.WeaveMessage; import org.aspectj.testing.util.TestUtil; import org.aspectj.util.LangUtil; @@ -134,8 +135,10 @@ public abstract class AjcTestCase extends TestCase { */ public static class Message { private int line = -1; + private int aspectLine = -1; private String text; private String sourceFileName; + private String aspectFileName; private ISourceLocation[] seeAlsos; public boolean careAboutOtherMessages = true; @@ -172,19 +175,28 @@ public abstract class AjcTestCase extends TestCase { * </p> */ public Message(int line, String srcFile, String text, ISourceLocation[] seeAlso) { + this(line, srcFile, -1, null, text, seeAlso); + } + + public Message(int line, String srcFile, int aspectLine, String aspectFile, String text, ISourceLocation[] seeAlso) { this.line = line; StringBuilder srcFileName = new StringBuilder(); if (srcFile != null) { char[] chars = srcFile.toCharArray(); for (char c : chars) { - if ((c == '\\') || (c == '/')) { - srcFileName.append(separator); - } else { - srcFileName.append(c); - } + srcFileName.append((c == '\\' || c == '/') ? separator : c); } this.sourceFileName = srcFileName.toString(); } + this.aspectLine = aspectLine; + StringBuilder aspectFileName = new StringBuilder(); + if (aspectFile != null) { + char[] chars = aspectFile.toCharArray(); + for (char c : chars) { + aspectFileName.append((c == '\\' || c == '/') ? separator : c); + } + this.aspectFileName = aspectFileName.toString(); + } this.text = text; if (this.text != null && text.startsWith("*")) { // Don't care what other messages are around @@ -211,33 +223,41 @@ public abstract class AjcTestCase extends TestCase { */ public boolean matches(IMessage message) { ISourceLocation loc = message.getSourceLocation(); - if ((loc == null) && ((line != -1) || (sourceFileName != null))) { + if ((loc == null) && ((line != -1) || (sourceFileName != null))) return false; - } if (line != -1) { - if (loc.getLine() != line) { + if (loc.getLine() != line) return false; - } } if (sourceFileName != null) { - if (!loc.getSourceFile().getPath().endsWith(sourceFileName)) { + if (!loc.getSourceFile().getPath().endsWith(sourceFileName)) return false; + } + if (message instanceof WeaveMessage) { + List<ISourceLocation> extraLocations = message.getExtraSourceLocations(); + loc = extraLocations.size() > 0 ? extraLocations.get(0) : null; + if ((loc == null) && ((aspectLine != -1) || (aspectFileName != null))) + return false; + if (aspectLine != -1) { + if (loc.getLine() != aspectLine) + return false; + } + if (aspectFileName != null) { + if (!loc.getSourceFile().getPath().endsWith(aspectFileName)) + return false; } } if (text != null) { - if (!message.getMessage().contains(text)) { + if (!message.getMessage().contains(text)) return false; - } } if (seeAlsos != null) { List<ISourceLocation> extraLocations = message.getExtraSourceLocations(); - if (extraLocations.size() != seeAlsos.length) { + if (extraLocations.size() != seeAlsos.length) return false; - } for (ISourceLocation seeAlso : seeAlsos) { - if (!hasAMatch(extraLocations, seeAlso)) { + if (!hasAMatch(extraLocations, seeAlso)) return false; - } } } return true; |