aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-03-04 09:52:21 +0000
committerwisberg <wisberg>2003-03-04 09:52:21 +0000
commitbb9ee8de60674b1bb5bbdaa9e61a7adc92aa8287 (patch)
tree9032c4361bb3ae3d56fbe27b0ff57234df3923c4 /org.aspectj.ajdt.core
parent55f3ff47ea2fd979cd2d61790f85cbba5ba7dc40 (diff)
downloadaspectj-bb9ee8de60674b1bb5bbdaa9e61a7adc92aa8287.tar.gz
aspectj-bb9ee8de60674b1bb5bbdaa9e61a7adc92aa8287.zip
partial fix for bug 31724 emits file:line numbers for declare warning/error.
This adds an optional "context" String to IMessage. The IMessage creator should create a context String (or use an implementation that lazily creates one). The IMessage client can render their messages without context embedded in the message field. Emitting source context from the weaver will be harder. Using file and start/end line will probably work, since tool clients can map to any available source file paths. (BcelSourceContext and BcelShadow can be updated with end from range.)
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java56
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java31
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java49
3 files changed, 107 insertions, 29 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java
index 18fbcdb08..d245cb90f 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java
@@ -15,13 +15,23 @@ package org.aspectj.ajdt.internal.compiler.lookup;
import java.io.File;
+import org.aspectj.ajdt.internal.core.builder.EclipseAdapterUtils;
import org.aspectj.bridge.ISourceLocation;
+import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
+import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.problem.ProblemHandler;
public class EclipseSourceLocation implements ISourceLocation {
- CompilationResult result;
+ private static String NO_CONTEXT = "USE_NULL--NO_CONTEXT_AVAILABLE";
+ CompilationResult result;
int startPos, endPos;
+ // lazy but final
+ File file;
+ int startLine = -1;
+ int endLine = -1;
+ int column = -1;
+ String context;
public EclipseSourceLocation(CompilationResult result, int startPos, int endPos) {
super();
@@ -31,20 +41,55 @@ public class EclipseSourceLocation implements ISourceLocation {
}
public File getSourceFile() {
- return new File(new String(result.fileName));
+ if (null == file) {
+ file = new File(new String(result.fileName));
+ }
+ return file;
}
public int getLine() {
- return ProblemHandler.searchLineNumber(result.lineSeparatorPositions, startPos);
+ if (-1 == startLine) {
+ startLine = ProblemHandler.searchLineNumber(result.lineSeparatorPositions, startPos);
+ }
+ return startLine;
}
public int getColumn() {
- return 0; //XXX need better search above to get both
+ if (-1 == column) {
+ int lineNumber = getLine();
+ if (0 < lineNumber) {
+ int lineStart = result.lineSeparatorPositions[getLine()];
+ int col = startPos - lineStart; // 1-based
+ if (0 <= col) {
+ column = col;
+ } else {
+ column = 0;
+ }
+ }
+ }
+ return column;
}
public int getEndLine() {
- return getLine(); //XXX no real need to do better
+ if (-1 == endLine) {
+ endLine = ProblemHandler.searchLineNumber(result.lineSeparatorPositions, endPos);
+ }
+ return endLine;
}
+
+ public String getContext() {
+ if (null == context) {
+ ICompilationUnit compilationUnit = result.compilationUnit;
+ IProblem[] problems = result.problems;
+ if ((null == compilationUnit) || (null == problems)
+ || (1 != problems.length)) { // ?? which of n>1 problems?
+ context = NO_CONTEXT;
+ } else {
+ context = EclipseAdapterUtils.makeLocationContext(compilationUnit, problems[0]);
+ }
+ }
+ return (NO_CONTEXT == context ? null : context);
+ }
/** @return String {file:}line{:column} */
@@ -61,5 +106,4 @@ public class EclipseSourceLocation implements ISourceLocation {
}
return sb.toString();
}
-
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java
index 39b6fbf2a..d93d6e8cf 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java
@@ -19,7 +19,6 @@ import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.bridge.SourceLocation;
-import org.aspectj.util.LangUtil;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.util.Util;
@@ -110,30 +109,26 @@ public class EclipseAdapterUtils {
return new String(extract) + "\n" + new String(underneath); //$NON-NLS-2$ //$NON-NLS-1$
}
+ /**
+ * Extract source location file, start and end lines, and context.
+ * Column is not extracted correctly.
+ * @return ISourceLocation with correct file and lines but not column.
+ */
public static ISourceLocation makeSourceLocation(ICompilationUnit unit, IProblem problem) {
int line = problem.getSourceLineNumber();
File file = new File(new String(problem.getOriginatingFileName()));
- return new SourceLocation(file, line, line, 0);
+ String context = makeLocationContext(unit, problem);
+ // XXX 0 column is wrong but recoverable from makeLocationContext
+ return new SourceLocation(file, line, line, 0, context);
}
- /** This renders entire message text, but also sets up source location */
+ /**
+ * Extract message text and source location, including context.
+ */
public static IMessage makeMessage(ICompilationUnit unit, IProblem problem) {
- //??? would like to know the column as well as line
- //??? and also should generate highlighting info
ISourceLocation sourceLocation = makeSourceLocation(unit, problem);
-
- String locationContext = makeLocationContext(unit, problem);
- StringBuffer mssg = new StringBuffer();
-
- mssg.append(problem.getOriginatingFileName());
- mssg.append(":" + problem.getSourceLineNumber());
- mssg.append(": ");
- mssg.append(problem.getMessage());
- mssg.append(LangUtil.EOL);
- mssg.append(locationContext);
-
- return new Message(mssg.toString(), sourceLocation, problem.isError());
- }
+ return new Message(problem.getMessage(), sourceLocation, problem.isError());
+ }
private EclipseAdapterUtils() {
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java
index 66dbf35c4..e458e5a47 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java
@@ -25,11 +25,13 @@ import org.aspectj.bridge.ICommand;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.bridge.IMessageHolder;
+import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.bridge.MessageHandler;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.ReflectionFactory;
import org.aspectj.bridge.Version;
+import org.aspectj.util.FileUtil;
import org.aspectj.util.LangUtil;
/**
@@ -343,7 +345,10 @@ public class Main {
handler.handleMessage(new Message(message, IMessage.FAIL, thrown, null));
}
- /** interceptor IMessageHandler to print as we go */
+ /**
+ * interceptor IMessageHandler to print as we go.
+ * This formats all messages to the user.
+ */
public static class MessagePrinter implements IMessageHandler {
public static final IMessageHandler VERBOSE
@@ -372,6 +377,15 @@ public class Main {
return false;
}
+ /**
+ * Render message differently.
+ * If abort, then prefix stack trace with feedback request.
+ * If the actual message is empty, then use toString on the whole.
+ * Prefix message part with file:line;
+ * If it has context, suffix message with context.
+ * @param message the IMessage to render
+ * @return String rendering IMessage (never null)
+ */
protected String render(IMessage message) {
IMessage.Kind kind = message.getKind();
if (kind.equals(IMessage.ABORT)) {
@@ -382,11 +396,36 @@ public class Main {
return Main.renderExceptionForUser(t);
}
}
- String m = message.getMessage();
- if (LangUtil.isEmpty(m)) {
- m = message.toString();
+ StringBuffer sb = new StringBuffer();
+ String text = message.getMessage();
+ boolean toString = (LangUtil.isEmpty(text));
+ if (toString) {
+ text = message.toString();
+ }
+ ISourceLocation loc = message.getISourceLocation();
+ String context = null;
+ if (null != loc) {
+ File file = loc.getSourceFile();
+ if (null != file) {
+ String name = file.getName();
+ if (!toString || (-1 == text.indexOf(name))) {
+ sb.append(FileUtil.getBestPath(file));
+ sb.append(":" + loc.getLine());
+ int col = loc.getColumn();
+ if (0 < col) {
+ sb.append(":" + col);
+ }
+ sb.append(" ");
+ }
+ }
+ context = loc.getContext();
+ }
+ sb.append(text);
+ if (null != context) {
+ sb.append(LangUtil.EOL);
+ sb.append(context);
}
- return m;
+ return sb.toString();
}
public boolean isIgnoring(IMessage.Kind kind) {