JS backend: add NotNull annotations

This commit is contained in:
Michael Nedzelsky
2014-07-30 21:38:12 +04:00
parent fe4a4e712a
commit b20e413883
5 changed files with 22 additions and 4 deletions
@@ -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<JsStatement> statements;
public JsBlock() {
@@ -27,10 +30,11 @@ public class JsBlock extends SourceInfoAwareJsNode implements JsStatement {
this(Arrays.asList(statements));
}
public JsBlock(List<JsStatement> statements) {
public JsBlock(@NotNull List<JsStatement> statements) {
this.statements = statements;
}
@NotNull
public List<JsStatement> getStatements() {
return statements;
}
@@ -19,6 +19,7 @@ public class JsCatchScope extends JsScope {
}
@Override
@NotNull
public JsName declareName(String identifier) {
// Declare into parent scope!
return getParent().declareName(identifier);
@@ -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<JsParameter> 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<JsParameter> getParameters() {
if (params == null) {
params = new SmartList<JsParameter>();
@@ -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;
}
@@ -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;
}
@@ -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);