mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 03:26:39 +00:00
Improve location information for some warnings/errors.
Fixes issue 82 Review URL: http://codereview.chromium.org//8348015 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@533 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
da8b9a6766
commit
efa0f8eb42
|
@ -162,17 +162,6 @@ public class DartCompilationError {
|
|||
this.source = location.getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a new instance representing a compilation error at the specified location.
|
||||
*
|
||||
* @param location the source range where the error occurred
|
||||
* @param errorCode the error code to be associated with this error
|
||||
* @param arguments the arguments used to build the error message
|
||||
*/
|
||||
public DartCompilationError(Location location, ErrorCode errorCode, Object... arguments) {
|
||||
this((Source)null, location, errorCode, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a new instance representing a compilation error at the specified location.
|
||||
*
|
||||
|
|
|
@ -417,7 +417,7 @@ public class DartCompiler {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (filesHaveChanged) {
|
||||
context.setFilesHaveChanged();
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ public class DartCompiler {
|
|||
Tracer.end(logEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void validateLibraryDirectives() {
|
||||
LibraryUnit appLibUnit = context.getAppLibraryUnit();
|
||||
for (LibraryUnit lib : libraries.values()) {
|
||||
|
@ -576,7 +576,7 @@ public class DartCompiler {
|
|||
private void setEntryPoint() {
|
||||
LibraryUnit lib = context.getAppLibraryUnit();
|
||||
lib.setEntryNode(new LibraryNode(MAIN_ENTRY_POINT_NAME));
|
||||
// this ensures that if we find it, it's a top-level static element
|
||||
// this ensures that if we find it, it's a top-level static element
|
||||
Element element = lib.getElement().lookupLocalElement(MAIN_ENTRY_POINT_NAME);
|
||||
switch (ElementKind.of(element)) {
|
||||
case NONE:
|
||||
|
@ -587,13 +587,13 @@ public class DartCompiler {
|
|||
MethodElement methodElement = (MethodElement) element;
|
||||
Modifiers modifiers = methodElement.getModifiers();
|
||||
if (modifiers.isGetter()) {
|
||||
context.compilationError(new DartCompilationError(Location.NONE,
|
||||
context.compilationError(new DartCompilationError(element.getNode(),
|
||||
DartCompilerErrorCode.ENTRY_POINT_METHOD_MAY_NOT_BE_GETTER, MAIN_ENTRY_POINT_NAME));
|
||||
} else if (modifiers.isSetter()) {
|
||||
context.compilationError(new DartCompilationError(Location.NONE,
|
||||
context.compilationError(new DartCompilationError(element.getNode(),
|
||||
DartCompilerErrorCode.ENTRY_POINT_METHOD_MAY_NOT_BE_SETTER, MAIN_ENTRY_POINT_NAME));
|
||||
} else if (methodElement.getParameters().size() > 0) {
|
||||
context.compilationError(new DartCompilationError(Location.NONE,
|
||||
context.compilationError(new DartCompilationError(element.getNode(),
|
||||
DartCompilerErrorCode.ENTRY_POINT_METHOD_CANNOT_HAVE_PARAMETERS,
|
||||
MAIN_ENTRY_POINT_NAME));
|
||||
} else {
|
||||
|
@ -602,7 +602,7 @@ public class DartCompiler {
|
|||
break;
|
||||
|
||||
default:
|
||||
context.compilationError(new DartCompilationError(Location.NONE,
|
||||
context.compilationError(new DartCompilationError(element.getNode(),
|
||||
DartCompilerErrorCode.NOT_A_STATIC_METHOD, MAIN_ENTRY_POINT_NAME));
|
||||
break;
|
||||
}
|
||||
|
@ -711,7 +711,8 @@ public class DartCompiler {
|
|||
// when generating documentation.
|
||||
if (context.getApplicationUnit().getEntryNode() == null && !collectComments) {
|
||||
if (config.expectEntryPoint()) {
|
||||
context.compilationError(new DartCompilationError(Location.NONE,
|
||||
context.compilationError(new DartCompilationError(
|
||||
context.getApplicationUnit().getSource(), Location.NONE,
|
||||
DartCompilerErrorCode.NO_ENTRY_POINT));
|
||||
}
|
||||
return;
|
||||
|
@ -1172,7 +1173,7 @@ public class DartCompiler {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) {
|
||||
return findLibrary(libraryUnit, "corelib.dart", new HashSet<LibraryElement>());
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.google.dart.compiler.DartCompilationError;
|
|||
import com.google.dart.compiler.DartCompilerErrorCode;
|
||||
import com.google.dart.compiler.ErrorCode;
|
||||
import com.google.dart.compiler.ast.DartNode;
|
||||
import com.google.dart.compiler.parser.DartScanner.Location;
|
||||
|
||||
/**
|
||||
* Abstract base class for sharing common utility methods between implementation
|
||||
|
@ -91,13 +90,13 @@ abstract class AbstractParser {
|
|||
*/
|
||||
protected void reportError(DartScanner.Position position, ErrorCode errorCode,
|
||||
Object... arguments) {
|
||||
DartCompilationError dartError = new DartCompilationError(ctx.getTokenLocation(), errorCode,
|
||||
arguments);
|
||||
if (dartError.getStartPosition() <= lastErrorPosition) {
|
||||
DartScanner.Location location = ctx.getTokenLocation();
|
||||
if (location.getBegin().getPos() <= lastErrorPosition) {
|
||||
return;
|
||||
}
|
||||
DartCompilationError dartError = new DartCompilationError(ctx.getSource(), location, errorCode,
|
||||
arguments);
|
||||
lastErrorPosition = position.getPos();
|
||||
dartError.setSource(ctx.getSource());
|
||||
ctx.error(dartError);
|
||||
}
|
||||
|
||||
|
@ -129,8 +128,4 @@ abstract class AbstractParser {
|
|||
next();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void error(Location location, DartCompilerErrorCode code, Object... arguments) {
|
||||
ctx.error(new DartCompilationError(location, code, arguments));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,8 @@ public class CoreTypeProviderImplementation implements CoreTypeProvider {
|
|||
if (element == null) {
|
||||
Location location = null;
|
||||
DartCompilationError error =
|
||||
new DartCompilationError(location, DartCompilerErrorCode.CANNOT_BE_RESOLVED, name);
|
||||
new DartCompilationError(null, Location.NONE,
|
||||
DartCompilerErrorCode.CANNOT_BE_RESOLVED, name);
|
||||
listener.compilationError(error);
|
||||
return Types.newDynamicType();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue