Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Elements.java

Issue 10704114: Issue 3985. Tweaks for warning messages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: compiler/java/com/google/dart/compiler/resolver/Elements.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Elements.java b/compiler/java/com/google/dart/compiler/resolver/Elements.java
index fbfd615b4be2397c853a1f5b224f08cb79063bc2..97ee1845e4c7caa2ad02c13ec24b433031dfb81b 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Elements.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Elements.java
@@ -383,11 +383,11 @@ static FieldElementImplementation fieldFromNode(DartField node,
public static boolean isNonFactoryConstructor(Element method) {
return !method.getModifiers().isFactory()
- && ElementKind.of(method).equals(ElementKind.CONSTRUCTOR);
+ && ElementKind.of(method) == ElementKind.CONSTRUCTOR;
}
public static boolean isTopLevel(Element element) {
- return ElementKind.of(element.getEnclosingElement()).equals(ElementKind.LIBRARY);
+ return ElementKind.of(element.getEnclosingElement()) == ElementKind.LIBRARY;
}
static List<TypeVariable> makeTypeVariables(List<DartTypeParameter> parameterNodes,
@@ -487,6 +487,43 @@ static FieldElementImplementation fieldFromNode(DartField node,
}
/**
+ * @return the user readable title of the given {@link Element}, a little different than
+ * "technical" title returned from {@link Element#toString()}.
+ */
+ public static String getUserElementTitle(Element element) {
+ return MessageFormat.format("{0} ''{1}''", getUserElementKindTitle(element), element.getName());
+ }
+
+ /**
+ * @return the user readable title of the given {@link Element}'s {@link ElementKind}, a little
+ * different than "technical" title returned from {@link Element#toString()}.
+ */
+ private static String getUserElementKindTitle(Element element) {
+ ElementKind kind = element.getKind();
+ switch (kind) {
+ case CLASS:
+ if (((ClassElement) element).isInterface()) {
+ return "interface";
+ }
+ break;
+ case METHOD:
+ if (isTopLevel(element)) {
+ return "top-level function";
+ }
+ break;
+ case FIELD:
+ if (isTopLevel(element)) {
+ return "top-level variable";
+ }
+ break;
+ }
+ String title = kind.toString();
devoncarew 2012/07/08 10:09:16 We could also add a method on ElementKind that wou
scheglov 2012/07/08 14:01:08 Well, no we could not. Because as you can see, use
+ title = StringUtils.replace(title, "_", " ");
+ title = title.toLowerCase();
+ return title;
+ }
+
+ /**
* @return the {@link String} which contains user-readable description of "target" {@link Element}
* location relative to "source".
*/
@@ -508,16 +545,18 @@ static FieldElementImplementation fieldFromNode(DartField node,
// Prepare (may be empty) target class name.
String targetClassName;
{
- ClassElement targetClass = getEnclosingClassElement(target);
+ EnclosingElement targetEnclosing = target.getEnclosingElement();
+ ClassElement targetClass = getEnclosingClassElement(targetEnclosing);
targetClassName = targetClass != null ? targetClass.getName() : "";
}
// Format location string.
- return MessageFormat.format(
- "{0}:{1}:{2}:{3}",
- targetPath,
- targetClassName,
- targetInfo.getLine(),
- targetInfo.getColumn());
+ if (StringUtils.isEmpty(targetClassName)) {
+ return MessageFormat.format("{0} line:{1} col:{2}", targetPath, targetInfo.getLine(),
devoncarew 2012/07/08 10:09:16 This location information seems overly precise to
scheglov 2012/07/08 14:01:08 This is same information and same format of locati
+ targetInfo.getColumn());
+ } else {
+ return MessageFormat.format("{0} class:{1} line:{2} col:{3}", targetPath, targetClassName,
+ targetInfo.getLine(), targetInfo.getColumn());
+ }
}
/**

Powered by Google App Engine
This is Rietveld 408576698