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

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

Issue 9190044: Issue 1140: Tweak relative path for shadowing problems. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3561852ad315fe6a4f844f41c51e9be5345f3320..32ac9f5308f79f4b5d4dcfad1f5507a9fb82e56d 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Elements.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Elements.java
@@ -40,6 +40,7 @@ import com.google.dart.compiler.type.TypeVariable;
import com.google.dart.compiler.util.Paths;
import java.io.File;
+import java.net.URI;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
@@ -436,6 +437,7 @@ static FieldElementImplementation fieldFromNode(DartField node,
return node;
}
+
/**
* @return the {@link String} which contains user-readable description of "target" {@link Element}
* location relative to "source".
@@ -450,13 +452,11 @@ static FieldElementImplementation fieldFromNode(DartField node,
}
targetInfo = targetNode.getSourceInfo();
}
- // Prepare relative (short) path to the target unit from source unit.
- String relativePath;
+ // Prepare path to the target unit from source unit.
+ String targetPath;
{
SourceInfo sourceInfo = source.getNode().getSourceInfo();
- String sourceName = getSourceName(sourceInfo);
- String targetName = getSourceName(targetInfo);
- relativePath = Paths.relativePathFor(new File(sourceName), new File(targetName));
+ targetPath = getRelativeSourcePath(sourceInfo, targetInfo);
}
// Prepare (may be empty) target class name.
String targetClassName;
@@ -467,35 +467,50 @@ static FieldElementImplementation fieldFromNode(DartField node,
// Format location string.
return MessageFormat.format(
"{0}:{1}:{2}:{3}",
- relativePath,
+ targetPath,
targetClassName,
targetInfo.getSourceLine(),
targetInfo.getSourceColumn());
}
-
+
/**
- * @return the result of {@link Source#getName()} safely, even if {@link Source} is
- * <code>null</code>.
+ * @return the relative or absolute path from "source" to "target".
*/
- private static String getSourceName(SourceInfo sourceInfo) {
- Source source = sourceInfo.getSource();
- if (source != null) {
- return source.getName();
+ private static String getRelativeSourcePath(SourceInfo source, SourceInfo target) {
+ Source sourceSource = source.getSource();
+ Source targetSource = target.getSource();
+ // If both source are from file, prepare relative path.
+ if (sourceSource != null && targetSource != null) {
+ URI sourceUri = sourceSource.getUri();
+ URI targetUri = targetSource.getUri();
+ if (Objects.equal(sourceUri.getScheme(), "file")
+ && Objects.equal(targetUri.getScheme(), "file")) {
+ return Paths.relativePathFor(new File(sourceUri.getPath()), new File(targetUri.getPath()));
+ }
}
- return "";
+ // Else return absolute path (including dart:// protocol).
+ if (targetSource != null) {
+ URI targetUri = targetSource.getUri();
+ return targetUri.toString();
+ }
+ // No source for target.
+ return "<unknown>";
}
-
+
/**
* @return the enclosing {@link ClassElement} (may be same if already given {@link ClassElement}),
* may be <code>null</code> if top level element.
*/
public static ClassElement getEnclosingClassElement(Element element) {
DartNode node = element.getNode();
- while (node != null) {
- if (node instanceof DartClass) {
- return ((DartClass) node).getSymbol();
- }
+ if (node != null) {
node = node.getParent();
+ while (node != null) {
+ if (node instanceof DartClass) {
+ return ((DartClass) node).getSymbol();
+ }
+ node = node.getParent();
+ }
}
return null;
}
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698