*
* ajc -warn:unusedImport UnusedImport.java
*
- * Expected result = id
+ * Expected result is that id matches IProblem.UnusedImport
*/
- public void testOutjarInInjars () {
+ public void testMessageID () {
String[] args = new String[] {"UnusedImport.java","-warn:unusedImport"};
CompilationResult result = ajc(baseDir,args);
List l = result.getWarningMessages();
}
+ /**
+ * Aim: Check that the start/end of certain warnings are correct
+ *
+ * ajc -warn:unusedImport UnusedImport.java
+ *
+ * Expected result is first warning message has start=7 end=20
+ */
+ public void testMessageSourceStartEnd() {
+ String[] args = new String[] {"UnusedImport.java","-warn:unusedImport"};
+ CompilationResult result = ajc(baseDir,args);
+ List l = result.getWarningMessages();
+ IMessage m = ((IMessage)l.get(0));
+ assertTrue("Expected source start to be 7 but was "+m.getSourceStart(),
+ m.getSourceStart()==7);
+ assertTrue("Expected source end to be 20 but was "+m.getSourceEnd(),
+ m.getSourceEnd()==20);
+ }
+
}
/** Return the ID of the message where applicable, see IProblem for list of valid IDs */
int getID();
+ /** Return the start position of the problem (inclusive), or -1 if unknown. */
+ int getSourceStart();
+
+ /** Return the end position of the problem (inclusive), or -1 if unknown. */
+ int getSourceEnd();
+
/** @return Throwable associated with this message, or null if none */
Throwable getThrown();
private final List/*SourceLocation*/ extraSourceLocations;
private final boolean declared; // Is it a DEOW ?
private final int id;
+ private final int sourceStart,sourceEnd;
/**
* Create a (compiler) error or warning message
*/
public Message(String message, String details, IMessage.Kind kind,
ISourceLocation sourceLocation, Throwable thrown, ISourceLocation[] extraSourceLocations) {
- this(message,details,kind,sourceLocation,thrown,extraSourceLocations,false,0);
+ this(message,details,kind,sourceLocation,thrown,extraSourceLocations,false,0,-1,-1);
}
public Message(String message, String details, IMessage.Kind kind,
ISourceLocation sLoc, Throwable thrown, ISourceLocation[] otherLocs,
- boolean declared,int id) {
+ boolean declared,int id,int sourcestart,int sourceend) {
this.details = details;
this.id = id;
+ this.sourceStart = sourcestart;
+ this.sourceEnd = sourceend;
this.message = ((message!=null) ? message : ((thrown==null) ? null : thrown.getMessage()));
this.kind = kind;
this.sourceLocation = sLoc;
return id;
}
+ public int getSourceStart() {
+ return sourceStart;
+ }
+
+ public int getSourceEnd() {
+ return sourceEnd;
+ }
}
problem.isError() ? IMessage.ERROR : IMessage.WARNING,
sourceLocation,
null,
- seeAlsoLocations,declared,problem.getID());
+ seeAlsoLocations,
+ declared,
+ problem.getID(),
+ problem.getSourceStart(),problem.getSourceEnd());
return msg;
}
private ISourceLocation sourceLocation;
private String details;
private int id;
+ private int sourceStart,sourceEnd;
private final ArrayList extraSourceLocations = new ArrayList();
//private ISourceLocation pseudoSourceLocation; // set directly
public void setID(int id) {
this.id = id;
}
+
+ public int getSourceStart() {
+ return sourceStart;
+ }
+
+ public void setSourceStart(int s) {
+ sourceStart = s;
+ }
+
+ public int getSourceEnd() {
+ return sourceStart;
+ }
+
+ public void setSourceEnd(int s) {
+ sourceEnd = s;
+ }
/* (non-Javadoc)
* @see org.aspectj.bridge.IMessage#getExtraSourceLocations()
isError ? IMessage.ERROR : IMessage.WARNING,
shadow.getSourceLocation(),
null,
- new ISourceLocation[]{this.getSourceLocation()},true,0);
+ new ISourceLocation[]{this.getSourceLocation()},true,
+ 0, // id
+ -1,-1); // source start/end
world.getMessageHandler().handleMessage(message);