From 26f4d623e46b56cfec334ca3da5f77bc67f6f89e Mon Sep 17 00:00:00 2001 From: "zundel@google.com" Date: Tue, 19 Jun 2012 15:45:19 +0000 Subject: [PATCH] Gets rid of some warnings in the analyzer for unused code and unused imports Ironically, the code to detect dead code in switch statements was itself dead (holdover from a change I did yesterday) Review URL: https://chromiumcodereview.appspot.com//10575019 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@8853 260f80e4-7a28-3924-810f-c04153c831b5 --- .../google/dart/compiler/ast/LibraryUnit.java | 3 +- .../dart/compiler/parser/DartParser.java | 34 +------------------ .../resolver/CompileTimeConstantAnalyzer.java | 16 ++++----- .../compiler/resolver/ResolveVisitor.java | 11 +++--- 4 files changed, 15 insertions(+), 49 deletions(-) diff --git a/compiler/java/com/google/dart/compiler/ast/LibraryUnit.java b/compiler/java/com/google/dart/compiler/ast/LibraryUnit.java index 8ba6ca3c797..e3dc6a64614 100644 --- a/compiler/java/com/google/dart/compiler/ast/LibraryUnit.java +++ b/compiler/java/com/google/dart/compiler/ast/LibraryUnit.java @@ -5,7 +5,6 @@ package com.google.dart.compiler.ast; import com.google.common.base.Objects; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.dart.compiler.DartCompiler; @@ -138,7 +137,7 @@ public class LibraryUnit { public Iterable getImports() { return imports; } - + public Iterable getImportedLibraries() { Set libraries = Sets.newHashSet(); for (LibraryImport libraryImport : imports) { diff --git a/compiler/java/com/google/dart/compiler/parser/DartParser.java b/compiler/java/com/google/dart/compiler/parser/DartParser.java index df9abb86a43..269ba9d7357 100644 --- a/compiler/java/com/google/dart/compiler/parser/DartParser.java +++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java @@ -4079,39 +4079,7 @@ public class DartParser extends CompletionHooksParserBase { return done(new DartSwitchStatement(expr, members)); } - private void parseDeadSwitchCode() { - boolean done = false; - boolean warned = false; - boolean oldInCaseStatement = inCaseStatement; - inCaseStatement = true; - try { - while (!done) { - if (peek(0) == Token.IDENTIFIER && peek(1) == Token.COLON) { - beginLabel(); - DartIdentifier identifier = parseIdentifier(); - expect(Token.COLON); - done(new DartLabel(identifier, null)); - - } - - Token nextToken = peek(0); - switch(nextToken) { - case CASE: - case DEFAULT: - case EOS: - case RBRACE: - return; - default: - warned = true; - parseStatement(); - } - } - } finally { - inCaseStatement = oldInCaseStatement; - } - } - - /** + /** *
    * catchParameter
    *    : FINAL type? identifier
diff --git a/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java b/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
index 85ebe8eed3f..943d2a2d9cf 100644
--- a/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
@@ -174,7 +174,7 @@ public class CompileTimeConstantAnalyzer {
      */
     private Type getMostSpecificType(DartNode node) {
       if (node != null) {
-        Element element = (Element) node.getElement();
+        Element element = node.getElement();
         Type type = inferredTypes.get(node);
         if (type != null) {
           return type;
@@ -289,7 +289,7 @@ public class CompileTimeConstantAnalyzer {
           rememberInferredType(x, intType);
         } else if (lhsType.equals(doubleType) && rhsType.equals(doubleType)) {
           rememberInferredType(x, doubleType);
-        } else  if (lhsType.equals(doubleType) && rhsType.equals(intType) 
+        } else  if (lhsType.equals(doubleType) && rhsType.equals(intType)
             || lhsType.equals(intType) && rhsType.equals(doubleType)) {
           rememberInferredType(x, doubleType);
         } else {
@@ -372,7 +372,7 @@ public class CompileTimeConstantAnalyzer {
           if (!element.getModifiers().isConstant() && !element.getModifiers().isFinal()) {
             expectedConstant(x);
           }
-          
+
           // Infer type by visiting node or cached from Element.
           final Type inferredType;
           if (element instanceof FieldNodeElement) {
@@ -381,19 +381,19 @@ public class CompileTimeConstantAnalyzer {
             fieldNode.accept(this);
             inferredType = getMostSpecificType(fieldNode);
             fieldNodeElement.setConstantType(inferredType);
-          } else if (fieldElement.getType() != null 
+          } else if (fieldElement.getType() != null
               && !fieldElement.getType().equals(dynamicType)) {
             inferredType = fieldElement.getType();
           } else {
             inferredType = fieldElement.getConstantType();
           }
-          
+
           // Done with this element.
           visitedElements.remove(element);
 
           rememberInferredType(x, inferredType);
           break;
-          
+
         case METHOD:
           if (!element.getModifiers().isStatic() && !Elements.isTopLevel(element)) {
             expectedConstant(x);
@@ -612,7 +612,7 @@ public class CompileTimeConstantAnalyzer {
       }
       return null;
     }
-    
+
     @Override
     public Void visitClass(DartClass node) {
       ClassElement oldClassElement = currentClass;
@@ -623,7 +623,7 @@ public class CompileTimeConstantAnalyzer {
         currentClass = oldClassElement;
       }
     }
-    
+
     @Override
     public Void visitMethodDefinition(DartMethodDefinition node) {
       inConstConstructor = node.getModifiers().isConstant();
diff --git a/compiler/java/com/google/dart/compiler/resolver/ResolveVisitor.java b/compiler/java/com/google/dart/compiler/resolver/ResolveVisitor.java
index 02755b603ae..58906572225 100644
--- a/compiler/java/com/google/dart/compiler/resolver/ResolveVisitor.java
+++ b/compiler/java/com/google/dart/compiler/resolver/ResolveVisitor.java
@@ -12,7 +12,6 @@ import com.google.dart.compiler.ast.DartFunctionTypeAlias;
 import com.google.dart.compiler.ast.DartIdentifier;
 import com.google.dart.compiler.ast.DartNode;
 import com.google.dart.compiler.ast.DartParameter;
-import com.google.dart.compiler.ast.DartThisExpression;
 import com.google.dart.compiler.ast.DartTypeNode;
 import com.google.dart.compiler.ast.DartTypeParameter;
 import com.google.dart.compiler.type.DynamicType;
@@ -52,13 +51,13 @@ abstract class ResolveVisitor extends ASTVisitor {
                                                element.getParameters(), returnType);
     Elements.setType(element, type);
     for (DartParameter parameter : node.getParameters()) {
-      if (//!(parameter.getQualifier() instanceof DartThisExpression) && 
-          parameter.getModifiers().isNamed() && 
+      if (//!(parameter.getQualifier() instanceof DartThisExpression) &&
+          parameter.getModifiers().isNamed() &&
           DartIdentifier.isPrivateName(parameter.getElement().getName())) {
-        getContext().onError(parameter.getName(), 
+        getContext().onError(parameter.getName(),
             ResolverErrorCode.NAMED_PARAMETERS_CANNOT_START_WITH_UNDER);
       }
-    }                
+    }
     return element;
   }
 
@@ -115,7 +114,7 @@ abstract class ResolveVisitor extends ASTVisitor {
     recordElement(node.getName(), element);
     return recordElement(node, element);
   }
-  
+
   protected EnclosingElement getEnclosingElement() {
     return null;
   }