本文整理汇总了Java中com.google.javascript.rhino.JSDocInfo.isConstructor方法的典型用法代码示例。如果您正苦于以下问题:Java JSDocInfo.isConstructor方法的具体用法?Java JSDocInfo.isConstructor怎么用?Java JSDocInfo.isConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.JSDocInfo
的用法示例。
在下文中一共展示了JSDocInfo.isConstructor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isConstructorOrEnumDeclaration
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Determines whether a set operation is a constructor or enumeration
* declaration. The set operation may either be an assignment to a name,
* a variable declaration, or an object literal key mapping.
*
* @param n The node that represents the name being set
* @param parent Parent node of {@code n} (an ASSIGN, VAR, or OBJLIT node)
* @return Whether the set operation is either a constructor or enum
* declaration
*/
private boolean isConstructorOrEnumDeclaration(Node n, Node parent) {
JSDocInfo info;
int valueNodeType;
switch (parent.getType()) {
case Token.ASSIGN:
info = parent.getJSDocInfo();
valueNodeType = n.getNext().getType();
break;
case Token.VAR:
info = n.getJSDocInfo();
if (info == null) {
info = parent.getJSDocInfo();
}
Node valueNode = n.getFirstChild();
valueNodeType = valueNode != null ? valueNode.getType() : Token.VOID;
break;
default:
return false;
}
// Heed the annotations only if they're sensibly used.
return info != null &&
(info.isConstructor() && valueNodeType == Token.FUNCTION ||
info.hasEnumParameterType() && valueNodeType == Token.OBJECTLIT);
}
示例2: checkForHosedThisReferences
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Warns about any references to "this" in the given FUNCTION. The function
* is getting collapsed, so the references will change.
*/
private void checkForHosedThisReferences(Node function, JSDocInfo docInfo,
final Name name) {
// A function is getting collapsed. Make sure that if it refers to
// "this", it must be a constructor or documented with @this.
if (docInfo == null ||
(!docInfo.isConstructor() && !docInfo.hasThisType())) {
NodeTraversal.traverse(compiler, function.getLastChild(),
new NodeTraversal.AbstractShallowCallback() {
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.THIS) {
compiler.report(
JSError.make(name.declaration.sourceName, n,
UNSAFE_THIS, name.fullName()));
}
}
});
}
}
示例3: visitFunctionNode
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
private void visitFunctionNode(Node n, Node parent) {
Node name = null;
JSDocInfo info = parent.getJSDocInfo();
if (info != null && info.isConstructor()) {
name = parent.getFirstChild();
} else {
// look to the child, maybe it's a named function
info = n.getJSDocInfo();
if (info != null && info.isConstructor()) {
name = n.getFirstChild();
}
}
if (name != null && name.isQualifiedName()) {
String qualifiedName = name.getQualifiedName();
if (!this.convention.isPrivate(qualifiedName)) {
Visibility visibility = info.getVisibility();
if (!visibility.equals(JSDocInfo.Visibility.PRIVATE)) {
ctors.put(qualifiedName, name);
}
}
}
}
示例4: checkNameVisibility
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Determines whether the given name is visible in the current context.
* @param t The current traversal.
* @param name The name node.
*/
private void checkNameVisibility(NodeTraversal t, Node name, Node parent) {
Var var = t.getScope().getVar(name.getString());
if (var != null) {
JSDocInfo docInfo = var.getJSDocInfo();
if (docInfo != null) {
// If a name is private, make sure that we're in the same file.
Visibility visibility = docInfo.getVisibility();
if (visibility == Visibility.PRIVATE &&
!t.getInput().getName().equals(docInfo.getSourceName())) {
if (docInfo.isConstructor() &&
isValidPrivateConstructorAccess(parent)) {
return;
}
compiler.report(
JSError.make(t, name, BAD_PRIVATE_GLOBAL_ACCESS,
name.getString(), docInfo.getSourceName()));
}
}
}
}
示例5: defineName
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Defines a variable based on the {@link Token#NAME} node passed.
* @param name The {@link Token#NAME} node.
* @param var The parent of the {@code name} node, which must be a
* {@link Token#VAR} node.
* @param parent {@code var}'s parent.
* @param info the {@link JSDocInfo} information relating to this
* {@code name} node.
*/
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
Node value = name.getFirstChild();
if (value != null && value.getType() == Token.FUNCTION) {
// function
String functionName = name.getString();
FunctionType functionType =
getFunctionType(functionName, value, info, null);
defineSlot(name, var, functionType);
} else {
// variable's type
JSType type = null;
if (info == null) {
// the variable's type will be inferred
CompilerInput input = compiler.getInput(sourceName);
Preconditions.checkNotNull(input, sourceName);
type = input.isExtern() ?
typeRegistry.getNativeType(UNKNOWN_TYPE) : null;
} else if (info.hasEnumParameterType()) {
type = getEnumType(name.getString(), var, value,
info.getEnumParameterType().evaluate(scope));
} else if (info.isConstructor()) {
type = getFunctionType(name.getString(), value, info, name);
} else {
type = getDeclaredTypeInAnnotation(sourceName, name, info);
}
defineSlot(name, var, type);
}
}
示例6: shouldTraverse
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Since this pass reports errors only when a global {@code this} keyword
* is encountered, there is no reason to traverse non global contexts.
*/
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.FUNCTION) {
// Don't traverse functions that are constructors or have the @this
// annotation.
JSDocInfo jsDoc = getFunctionJsDocInfo(n);
if (jsDoc != null && (jsDoc.isConstructor() || jsDoc.hasThisType())) {
return false;
}
}
if (parent != null && parent.getType() == Token.ASSIGN) {
Node lhs = parent.getFirstChild();
Node rhs = lhs.getNext();
if (n == lhs) {
// Always traverse the left side of the assignment. To handle
// nested assignments properly (e.g., (a = this).property = c;),
// assignLhsChild should not be overridden.
if (assignLhsChild == null) {
assignLhsChild = lhs;
}
} else {
// Only traverse the right side if it's not an assignment to a prototype
// property or subproperty.
if (lhs.getType() == Token.GETPROP) {
if (lhs.getLastChild().getString().equals("prototype")) {
return false;
}
String leftName = lhs.getQualifiedName();
if (leftName != null && leftName.contains(".prototype.")) {
return false;
}
}
}
}
return true;
}
示例7: isFunctionTypeDeclaration
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Determines whether the given jsdoc info declares a function type.
*/
static boolean isFunctionTypeDeclaration(JSDocInfo info) {
return info.getParameterCount() > 0 ||
info.hasReturnType() ||
info.hasThisType() ||
info.isConstructor() ||
info.isInterface();
}
示例8: getDeclaredTypeInAnnotation
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
JSType getDeclaredTypeInAnnotation(String sourceName,
Node node, JSDocInfo info) {
JSType jsType = null;
Node objNode = node.getType() == Token.GETPROP ?
node.getFirstChild() : null;
if (info != null) {
if (info.hasType()) {
jsType = info.getType().evaluate(scope);
} else if (FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
String fnName = node.getQualifiedName();
// constructors are often handled separately.
if (info.isConstructor() && typeRegistry.getType(fnName) != null) {
return null;
}
FunctionTypeBuilder builder =
new FunctionTypeBuilder(
fnName, compiler, node, sourceName, scope)
.inferTemplateTypeName(info)
.inferReturnType(info)
.inferParameterTypes(info)
.inferInheritance(info);
// Infer the context type.
boolean searchedForThisType = false;
if (objNode != null) {
if (objNode.getType() == Token.GETPROP &&
objNode.getLastChild().getString().equals("prototype")) {
builder.inferThisType(info, objNode.getFirstChild());
searchedForThisType = true;
} else if (objNode.getType() == Token.THIS) {
builder.inferThisType(info, objNode.getJSType());
searchedForThisType = true;
}
}
if (!searchedForThisType) {
builder.inferThisType(info, (Node) null);
}
jsType = builder.buildAndRegister();
}
}
return jsType;
}
示例9: inferInheritance
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Infer the role of the function (whether it's a constructor or interface)
* and what it inherits from in JSDocInfo.
*/
FunctionTypeBuilder inferInheritance(@Nullable JSDocInfo info) {
if (info != null) {
isConstructor = info.isConstructor();
isInterface = info.isInterface();
// base type
if (info.hasBaseType()) {
if (isConstructor || isInterface) {
baseType = ObjectType.cast(info.getBaseType().evaluate(scope));
if (baseType == null) {
reportWarning(EXTENDS_NON_OBJECT, fnName, baseType.toString());
}
} else {
reportWarning(EXTENDS_WITHOUT_TYPEDEF, fnName);
}
}
// implemented interfaces
if (isConstructor || isInterface) {
implementedInterfaces = Lists.newArrayList();
for (JSTypeExpression t : info.getImplementedInterfaces()) {
ObjectType interType = ObjectType.cast(t.evaluate(scope));
if (interType != null) {
implementedInterfaces.add(interType);
} else {
reportError(BAD_IMPLEMENTED_TYPE, fnName);
}
}
if (baseType != null) {
JSType maybeFunctionType = baseType.getConstructor();
if (maybeFunctionType instanceof FunctionType) {
FunctionType functionType = baseType.getConstructor();
Iterables.addAll(
implementedInterfaces,
functionType.getImplementedInterfaces());
}
}
} else if (info.getImplementedInterfaceCount() > 0) {
reportWarning(IMPLEMENTS_WITHOUT_CONSTRUCTOR, fnName);
}
}
return this;
}