From b20e41388381979dfe9991ef9a67b7483688dfdb Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Wed, 30 Jul 2014 21:38:12 +0400 Subject: [PATCH] JS backend: add NotNull annotations --- .../google/dart/compiler/backend/js/ast/JsBlock.java | 6 +++++- .../dart/compiler/backend/js/ast/JsCatchScope.java | 1 + .../dart/compiler/backend/js/ast/JsFunction.java | 10 ++++++++-- .../dart/compiler/backend/js/ast/JsParameter.java | 6 +++++- .../google/dart/compiler/backend/js/ast/JsScope.java | 3 +++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java index f27a4cae049..2193cccbca0 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java @@ -4,6 +4,8 @@ package com.google.dart.compiler.backend.js.ast; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -13,6 +15,7 @@ import java.util.List; * Represents a JavaScript block statement. */ public class JsBlock extends SourceInfoAwareJsNode implements JsStatement { + @NotNull private final List statements; public JsBlock() { @@ -27,10 +30,11 @@ public class JsBlock extends SourceInfoAwareJsNode implements JsStatement { this(Arrays.asList(statements)); } - public JsBlock(List statements) { + public JsBlock(@NotNull List statements) { this.statements = statements; } + @NotNull public List getStatements() { return statements; } diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java index 20f0add6790..6eaa29c49c1 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java @@ -19,6 +19,7 @@ public class JsCatchScope extends JsScope { } @Override + @NotNull public JsName declareName(String identifier) { // Declare into parent scope! return getParent().declareName(identifier); diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java index 1bc7b301b8a..4a498ac7d57 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java @@ -6,13 +6,16 @@ package com.google.dart.compiler.backend.js.ast; import com.google.dart.compiler.common.Symbol; import com.intellij.util.SmartList; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; public final class JsFunction extends JsLiteral implements HasName { + @NotNull private JsBlock body; private List params; + @NotNull private final JsScope scope; private JsName name; @@ -20,7 +23,7 @@ public final class JsFunction extends JsLiteral implements HasName { this(parentScope, (JsName) null); } - public JsFunction(JsScope parentScope, JsBlock body) { + public JsFunction(JsScope parentScope, @NotNull JsBlock body) { this(parentScope, (JsName) null); this.body = body; } @@ -30,6 +33,7 @@ public final class JsFunction extends JsLiteral implements HasName { scope = new JsScope(parentScope, name == null ? null : name.getIdent()); } + @NotNull public JsBlock getBody() { return body; } @@ -44,6 +48,7 @@ public final class JsFunction extends JsLiteral implements HasName { return name; } + @NotNull public List getParameters() { if (params == null) { params = new SmartList(); @@ -51,11 +56,12 @@ public final class JsFunction extends JsLiteral implements HasName { return params; } + @NotNull public JsScope getScope() { return scope; } - public void setBody(JsBlock body) { + public void setBody(@NotNull JsBlock body) { this.body = body; } diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java index 9167a30ece9..3a73c5108e3 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java @@ -5,23 +5,27 @@ package com.google.dart.compiler.backend.js.ast; import com.google.dart.compiler.common.Symbol; +import org.jetbrains.annotations.NotNull; /** * A JavaScript parameter. */ public final class JsParameter extends SourceInfoAwareJsNode implements HasName { + @NotNull private final JsName name; - public JsParameter(JsName name) { + public JsParameter(@NotNull JsName name) { this.name = name; } @Override + @NotNull public JsName getName() { return name; } @Override + @NotNull public Symbol getSymbol() { return name; } diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java index abe81550df7..e390b5a177d 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java @@ -80,6 +80,7 @@ public class JsScope { * * @param identifier An identifier that is unique within this scope. */ + @NotNull public JsName declareName(String identifier) { JsName name = findOwnName(identifier); return name != null ? name : doCreateName(identifier); @@ -112,6 +113,7 @@ public class JsScope { * name) that does not clash with any existing variables in the scope. * Future declarations of variables might however clash with the temporary. */ + @NotNull public JsName declareTemporary() { return declareFreshName(getNextTempName()); } @@ -158,6 +160,7 @@ public class JsScope { } } + @NotNull protected JsName doCreateName(String ident) { JsName name = new JsName(this, ident); names = Maps.put(names, ident, name);