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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import com.google.common.annotations.VisibleForTesting; 7 import com.google.common.annotations.VisibleForTesting;
8 import com.google.common.base.Objects; 8 import com.google.common.base.Objects;
9 import com.google.common.collect.ImmutableSet; 9 import com.google.common.collect.ImmutableSet;
10 import com.google.common.collect.Lists; 10 import com.google.common.collect.Lists;
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if (element instanceof ClassElement) { 376 if (element instanceof ClassElement) {
377 return false; 377 return false;
378 } 378 }
379 element = element.getEnclosingElement(); 379 element = element.getEnclosingElement();
380 } 380 }
381 return true; 381 return true;
382 } 382 }
383 383
384 public static boolean isNonFactoryConstructor(Element method) { 384 public static boolean isNonFactoryConstructor(Element method) {
385 return !method.getModifiers().isFactory() 385 return !method.getModifiers().isFactory()
386 && ElementKind.of(method).equals(ElementKind.CONSTRUCTOR); 386 && ElementKind.of(method) == ElementKind.CONSTRUCTOR;
387 } 387 }
388 388
389 public static boolean isTopLevel(Element element) { 389 public static boolean isTopLevel(Element element) {
390 return ElementKind.of(element.getEnclosingElement()).equals(ElementKind.LIBR ARY); 390 return ElementKind.of(element.getEnclosingElement()) == ElementKind.LIBRARY;
391 } 391 }
392 392
393 static List<TypeVariable> makeTypeVariables(List<DartTypeParameter> parameterN odes, 393 static List<TypeVariable> makeTypeVariables(List<DartTypeParameter> parameterN odes,
394 EnclosingElement enclosingElement) { 394 EnclosingElement enclosingElement) {
395 if (parameterNodes == null) { 395 if (parameterNodes == null) {
396 return Arrays.<TypeVariable>asList(); 396 return Arrays.<TypeVariable>asList();
397 } 397 }
398 TypeVariable[] typeVariables = new TypeVariable[parameterNodes.size()]; 398 TypeVariable[] typeVariables = new TypeVariable[parameterNodes.size()];
399 int i = 0; 399 int i = 0;
400 for (DartTypeParameter parameterNode : parameterNodes) { 400 for (DartTypeParameter parameterNode : parameterNodes) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 List<String> names = Lists.newArrayList(); 480 List<String> names = Lists.newArrayList();
481 List<VariableElement> parameters = method.getParameters(); 481 List<VariableElement> parameters = method.getParameters();
482 for (VariableElement parameter : parameters) { 482 for (VariableElement parameter : parameters) {
483 String typeName = parameter.getType().getElement().getName(); 483 String typeName = parameter.getType().getElement().getName();
484 names.add(typeName); 484 names.add(typeName);
485 } 485 }
486 return names; 486 return names;
487 } 487 }
488 488
489 /** 489 /**
490 * @return the user readable title of the given {@link Element}, a little diff erent than
491 * "technical" title returned from {@link Element#toString()}.
492 */
493 public static String getUserElementTitle(Element element) {
494 return MessageFormat.format("{0} ''{1}''", getUserElementKindTitle(element), element.getName());
495 }
496
497 /**
498 * @return the user readable title of the given {@link Element}'s {@link Eleme ntKind}, a little
499 * different than "technical" title returned from {@link Element#toStr ing()}.
500 */
501 private static String getUserElementKindTitle(Element element) {
502 ElementKind kind = element.getKind();
503 switch (kind) {
504 case CLASS:
505 if (((ClassElement) element).isInterface()) {
506 return "interface";
507 }
508 break;
509 case METHOD:
510 if (isTopLevel(element)) {
511 return "top-level function";
512 }
513 break;
514 case FIELD:
515 if (isTopLevel(element)) {
516 return "top-level variable";
517 }
518 break;
519 }
520 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
521 title = StringUtils.replace(title, "_", " ");
522 title = title.toLowerCase();
523 return title;
524 }
525
526 /**
490 * @return the {@link String} which contains user-readable description of "tar get" {@link Element} 527 * @return the {@link String} which contains user-readable description of "tar get" {@link Element}
491 * location relative to "source". 528 * location relative to "source".
492 */ 529 */
493 public static String getRelativeElementLocation(Element source, Element target ) { 530 public static String getRelativeElementLocation(Element source, Element target ) {
494 // Prepare "target" SourceInfo. 531 // Prepare "target" SourceInfo.
495 SourceInfo targetInfo; 532 SourceInfo targetInfo;
496 { 533 {
497 targetInfo = target.getNameLocation(); 534 targetInfo = target.getNameLocation();
498 if (targetInfo == null) { 535 if (targetInfo == null) {
499 return "unknown"; 536 return "unknown";
500 } 537 }
501 } 538 }
502 // Prepare path to the target unit from source unit. 539 // Prepare path to the target unit from source unit.
503 String targetPath; 540 String targetPath;
504 { 541 {
505 SourceInfo sourceInfo = source.getSourceInfo(); 542 SourceInfo sourceInfo = source.getSourceInfo();
506 targetPath = getRelativeSourcePath(sourceInfo, targetInfo); 543 targetPath = getRelativeSourcePath(sourceInfo, targetInfo);
507 } 544 }
508 // Prepare (may be empty) target class name. 545 // Prepare (may be empty) target class name.
509 String targetClassName; 546 String targetClassName;
510 { 547 {
511 ClassElement targetClass = getEnclosingClassElement(target); 548 EnclosingElement targetEnclosing = target.getEnclosingElement();
549 ClassElement targetClass = getEnclosingClassElement(targetEnclosing);
512 targetClassName = targetClass != null ? targetClass.getName() : ""; 550 targetClassName = targetClass != null ? targetClass.getName() : "";
513 } 551 }
514 // Format location string. 552 // Format location string.
515 return MessageFormat.format( 553 if (StringUtils.isEmpty(targetClassName)) {
516 "{0}:{1}:{2}:{3}", 554 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
517 targetPath, 555 targetInfo.getColumn());
518 targetClassName, 556 } else {
519 targetInfo.getLine(), 557 return MessageFormat.format("{0} class:{1} line:{2} col:{3}", targetPath, targetClassName,
520 targetInfo.getColumn()); 558 targetInfo.getLine(), targetInfo.getColumn());
559 }
521 } 560 }
522 561
523 /** 562 /**
524 * @return the relative or absolute path from "source" to "target". 563 * @return the relative or absolute path from "source" to "target".
525 */ 564 */
526 private static String getRelativeSourcePath(SourceInfo source, SourceInfo targ et) { 565 private static String getRelativeSourcePath(SourceInfo source, SourceInfo targ et) {
527 Source sourceSource = source.getSource(); 566 Source sourceSource = source.getSource();
528 Source targetSource = target.getSource(); 567 Source targetSource = target.getSource();
529 return getRelativeSourcePath(sourceSource, targetSource); 568 return getRelativeSourcePath(sourceSource, targetSource);
530 } 569 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 if (element instanceof MethodElement) { 741 if (element instanceof MethodElement) {
703 MethodElement methodElement = (MethodElement) element; 742 MethodElement methodElement = (MethodElement) element;
704 return Objects.equal(methodElement.getName(), "assert") 743 return Objects.equal(methodElement.getName(), "assert")
705 && methodElement.getEnclosingElement() instanceof LibraryElement 744 && methodElement.getEnclosingElement() instanceof LibraryElement
706 && methodElement.getEnclosingElement().getName().equals("dart://core/c ore_runtime.dart"); 745 && methodElement.getEnclosingElement().getName().equals("dart://core/c ore_runtime.dart");
707 } 746 }
708 return false; 747 return false;
709 } 748 }
710 749
711 } 750 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698