javascript java typeof unknown_Java JSType.equals方法代碼示例

import com.google.javascript.rhino.jstype.JSType; //導入方法依賴的package包/類

/**

* Expect that the given variable has not been declared with a type.

*

* @param sourceName The name of the source file we're in.

* @param n The node where warnings should point to.

* @param parent The parent of {@code n}.

* @param var The variable that we're checking.

* @param variableName The name of the variable.

* @param newType The type being applied to the variable. Mostly just here

* for the benefit of the warning.

*/

void expectUndeclaredVariable(String sourceName, Node n, Node parent, Var var,

String variableName, JSType newType) {

boolean allowDupe = false;

if (n.getType() == Token.GETPROP) {

JSDocInfo info = n.getJSDocInfo();

if (info == null) {

info = parent.getJSDocInfo();

}

allowDupe =

info != null && info.getSuppressions().contains("duplicate");

}

JSType varType = var.getType();

// Only report duplicate declarations that have types. Other duplicates

// will be reported by the syntactic scope creator later in the

// compilation process.

if (varType != null &&

varType != typeRegistry.getNativeType(UNKNOWN_TYPE) &&

newType != null &&

newType != typeRegistry.getNativeType(UNKNOWN_TYPE)) {

// If there are two typed declarations of the same variable, that

// is an error and the second declaration is ignored, except in the

// case of native types. A null input type means that the declaration

// was made in TypedScopeCreator#createInitialScope and is a

// native type.

if (var.input == null) {

n.setJSType(varType);

if (parent.getType() == Token.VAR) {

if (n.getFirstChild() != null) {

n.getFirstChild().setJSType(varType);

}

} else {

Preconditions.checkState(parent.getType() == Token.FUNCTION);

parent.setJSType(varType);

}

} else {

// Always warn about duplicates if the overridden type does not

// match the original type.

//

// If the types match, suppress the warning iff there was a @suppress

// tag, or if the original declaration was a stub.

if (!(allowDupe ||

var.getParentNode().getType() == Token.EXPR_RESULT) ||

!newType.equals(varType)) {

compiler.report(

JSError.make(sourceName, n, DUP_VAR_DECLARATION,

variableName, newType.toString(), var.getInputName(),

String.valueOf(var.nameNode.getLineno()),

varType.toString()));

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值