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

Unified Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 704413005: Report HintCode.UNUSED_ELEMENT for classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. Created 6 years, 1 month 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 | pkg/analyzer/lib/src/generated/element_resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/element.dart
diff --git a/pkg/analyzer/lib/src/generated/element.dart b/pkg/analyzer/lib/src/generated/element.dart
index 5615521c812c571d223f9cc072fb4164d687a599..755b8c670a5ab294199462e4e73fad76d1ea610e 100644
--- a/pkg/analyzer/lib/src/generated/element.dart
+++ b/pkg/analyzer/lib/src/generated/element.dart
@@ -3384,6 +3384,26 @@ abstract class ElementImpl implements Element {
return shortName;
}
+ /**
+ * Return `true` if this element is used or potentially can be used.
+ *
+ * For a top-level element: it is public, or it is private and used in the
+ * defining library.
+ *
+ * For a local variable: its value is used (i.e. purely read or invoked)
+ * somewhere in its scope.
+ *
+ * This information is only available for local variables (including
+ * parameters) and only after the compilation unit containing the element
+ * has been resolved.
+ */
+ bool get isUsed {
+ if (isPublic) {
+ return true;
+ }
+ return hasModifier(Modifier.IS_USED_IN_LIBRARY);
+ }
+
@override
LibraryElement get library => getAncestor((element) => element is LibraryElement);
@@ -3551,6 +3571,13 @@ abstract class ElementImpl implements Element {
bool hasModifier(Modifier modifier) => BooleanArray.getEnum(_modifiers, modifier);
/**
+ * Specifies that the element is used.
+ */
+ void markUsed() {
+ setModifier(Modifier.IS_USED_IN_LIBRARY, true);
+ }
+
+ /**
* If the given child is not `null`, use the given visitor to visit it.
*
* @param child the child to be visited
@@ -8270,6 +8297,11 @@ class LocalVariableElementImpl extends VariableElementImpl implements LocalVaria
accept(ElementVisitor visitor) => visitor.visitLocalVariableElement(this);
@override
+ bool get isUsed {
+ return hasModifier(Modifier.IS_USED_IN_LIBRARY);
+ }
+
+ @override
ElementKind get kind => ElementKind.LOCAL_VARIABLE;
@override
@@ -8295,9 +8327,6 @@ class LocalVariableElementImpl extends VariableElementImpl implements LocalVaria
@override
bool get isPotentiallyMutatedInScope => hasModifier(Modifier.POTENTIALLY_MUTATED_IN_SCOPE);
- @override
- bool get isUsed => hasModifier(Modifier.IS_USED_VARIABLE);
-
/**
* Specifies that this variable is potentially mutated somewhere in closure.
*/
@@ -8313,13 +8342,6 @@ class LocalVariableElementImpl extends VariableElementImpl implements LocalVaria
}
/**
- * Specifies that the value of this variable is used.
- */
- void markUsed() {
- setModifier(Modifier.IS_USED_VARIABLE, true);
- }
-
- /**
* Set the toolkit specific information objects attached to this variable.
*
* @param toolkitObjects the toolkit objects attached to this variable
@@ -8780,9 +8802,16 @@ class Modifier extends Enum<Modifier> {
static const Modifier HAS_EXT_URI = const Modifier('HAS_EXT_URI', 9);
/**
- * Indicates that the value of a variable is used - read or invoked.
+ * Indicates that the element is used in the declaring library.
+ *
+ *
+ * For a top-level element: it is public, or it is private and used in the
+ * defining library.
+ *
+ * For a local variable: its value is used (i.e. purely read or invoked)
+ * somewhere in its scope.
*/
- static const Modifier IS_USED_VARIABLE = const Modifier('IS_USED_VARIABLE', 10);
+ static const Modifier IS_USED_IN_LIBRARY = const Modifier('IS_USED_IN_LIBRARY', 10);
/**
* Indicates that a class can validly be used as a mixin.
@@ -8838,7 +8867,7 @@ class Modifier extends Enum<Modifier> {
GENERATOR,
GETTER,
HAS_EXT_URI,
- IS_USED_VARIABLE,
+ IS_USED_IN_LIBRARY,
MIXIN,
POTENTIALLY_MUTATED_IN_CONTEXT,
POTENTIALLY_MUTATED_IN_SCOPE,
@@ -11621,14 +11650,6 @@ abstract class VariableElementImpl extends ElementImpl implements VariableElemen
bool get isFinal => hasModifier(Modifier.FINAL);
/**
- * Return `true` if this variable is used (i.e. purely read or invoked)
- * somewhere in its scope. This information is only available for local
- * variables (including parameters) and only after the compilation unit
- * containing the variable has been resolved.
- */
- bool get isUsed => false;
-
- /**
* Return `true` if this variable is potentially mutated somewhere in a closure. This
* information is only available for local variables (including parameters) and only after the
* compilation unit containing the variable has been resolved.
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/element_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698