本文整理汇总了Java中com.google.javascript.rhino.jstype.EnumType类的典型用法代码示例。如果您正苦于以下问题:Java EnumType类的具体用法?Java EnumType怎么用?Java EnumType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EnumType类属于com.google.javascript.rhino.jstype包,在下文中一共展示了EnumType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: visitEnumType
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
@Override
protected boolean visitEnumType(EnumType type) {
Type javaType = createJavaType(type.getDisplayName(), NAMESPACE, false);
// you cannot extends an enum
javaType.setFinal(true);
// The class containing the static fields can be mapped to the javascript Object. The static
// fields representing the enum members will define a JsProperty annotation with the right
// name and namespace.
Annotation jsType = javaType.removeAnnotation(JS_TYPE);
javaType.addAnnotation(jsType.withNameAttribute("Object").withNamespaceAttribute(""));
// In closure, the type used for the enum and the type for the enum members are different.
// In our model, it's the same java type. We need to register the java type two times.
getJavaTypeRegistry().registerJavaType(javaType, type);
getJavaTypeRegistry().registerJavaType(javaType, type.getElementsType());
return false;
}
开发者ID:google,项目名称:jsinterop-generator,代码行数:20,代码来源:TypeCollector.java
示例2: checkPropertyAccess
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* Make sure that the access of this property is ok.
*/
private void checkPropertyAccess(JSType childType, String propName,
NodeTraversal t, Node n) {
ObjectType objectType = childType.dereference();
if (objectType != null) {
JSType propType = getJSType(n);
if ((!objectType.hasProperty(propName) ||
objectType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) &&
propType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
if (objectType instanceof EnumType) {
t.report(n, INEXISTENT_ENUM_ELEMENT, propName);
} else if (!objectType.isEmptyType() &&
reportMissingProperties && !isPropertyTest(n)) {
if (!typeRegistry.canPropertyBeDefined(objectType, propName)) {
t.report(n, INEXISTENT_PROPERTY, propName,
validator.getReadableJSTypeName(n.getFirstChild(), true));
}
}
}
} else {
// TODO(nicksantos): might want to flag the access on a non object when
// it's impossible to get a property from this type.
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:TypeCheck.java
示例3: attachJSDocInfoToNominalTypeOrShape
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* Handle cases #1 and #3 in the class doc.
*/
private void attachJSDocInfoToNominalTypeOrShape(
ObjectType objType, JSDocInfo docInfo, @Nullable String qName) {
if (objType.isConstructor() ||
objType.isEnumType() ||
objType.isInterface()) {
// Named types.
if (objType.hasReferenceName() &&
objType.getReferenceName().equals(qName)) {
objType.setJSDocInfo(docInfo);
if (objType.isConstructor() || objType.isInterface()) {
((FunctionType) objType).getInstanceType().setJSDocInfo(
docInfo);
} else if (objType instanceof EnumType) {
((EnumType) objType).getElementsType().setJSDocInfo(docInfo);
}
}
} else if (!objType.isNativeObjectType() &&
objType.isFunctionType()) {
// Structural functions.
objType.setJSDocInfo(docInfo);
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:InferJSDocInfo.java
示例4: checkPropertyAccess
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* Make sure that the access of this property is ok.
*/
private void checkPropertyAccess(JSType childType, String propName,
NodeTraversal t, Node n) {
ObjectType objectType = childType.dereference();
if (objectType != null) {
JSType propType = getJSType(n);
if ((!objectType.hasProperty(propName) ||
objectType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) &&
propType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
if (objectType instanceof EnumType) {
report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
} else if (!objectType.isEmptyType() &&
reportMissingProperties && !isPropertyTest(n)) {
if (!typeRegistry.canPropertyBeDefined(objectType, propName)) {
report(t, n, INEXISTENT_PROPERTY, propName,
validator.getReadableJSTypeName(n.getFirstChild(), true));
}
}
}
} else {
// TODO(nicksantos): might want to flag the access on a non object when
// it's impossible to get a property from this type.
}
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:27,代码来源:TypeCheck.java
示例5: checkEnumAlias
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* <p>Checks enum aliases.
*
* <p>We verify that the enum element type of the enum used
* for initialization is a subtype of the enum element type of
* the enum the value is being copied in.</p>
*
* <p>Example:</p>
* <pre>var myEnum = myOtherEnum;</pre>
*
* <p>Enum aliases are irregular, so we need special code for this :(</p>
*
* @param value the value used for initialization of the enum
*/
private void checkEnumAlias(
NodeTraversal t, JSDocInfo declInfo, Node value) {
if (declInfo == null || !declInfo.hasEnumParameterType()) {
return;
}
JSType valueType = getJSType(value);
if (!valueType.isEnumType()) {
return;
}
EnumType valueEnumType = valueType.toMaybeEnumType();
JSType valueEnumPrimitiveType =
valueEnumType.getElementsType().getPrimitiveType();
validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
declInfo.getEnumParameterType().evaluate(t.getScope(), typeRegistry),
"incompatible enum element types");
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:33,代码来源:TypeCheck.java
示例6: attachJSDocInfoToNominalTypeOrShape
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* Handle cases #1 and #3 in the class doc.
*/
private void attachJSDocInfoToNominalTypeOrShape(
ObjectType objType, JSDocInfo docInfo, @Nullable String qName) {
if (objType.isConstructor() ||
objType.isEnumType() ||
objType.isInterface()) {
// Named types.
if (objType.hasReferenceName() &&
objType.getReferenceName().equals(qName)) {
objType.setJSDocInfo(docInfo);
if (objType.isConstructor() || objType.isInterface()) {
JSType.toMaybeFunctionType(objType).getInstanceType().setJSDocInfo(
docInfo);
} else if (objType instanceof EnumType) {
((EnumType) objType).getElementsType().setJSDocInfo(docInfo);
}
}
} else if (!objType.isNativeObjectType() &&
objType.isFunctionType()) {
// Structural functions.
objType.setJSDocInfo(docInfo);
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:InferJSDocInfo.java
示例7: checkEnumAlias
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* <p>Checks enum aliases.
*
* <p>We verify that the enum element type of the enum used
* for initialization is a subtype of the enum element type of
* the enum the value is being copied in.</p>
*
* <p>Example:</p>
* <pre>var myEnum = myOtherEnum;</pre>
*
* <p>Enum aliases are irregular, so we need special code for this :(</p>
*
* @param value the value used for initialization of the enum
*/
private void checkEnumAlias(
NodeTraversal t, JSDocInfo declInfo, Node value) {
if (declInfo == null || !declInfo.hasEnumParameterType()) {
return;
}
JSType valueType = getJSType(value);
if (!valueType.isEnumType()) {
return;
}
EnumType valueEnumType = valueType.toMaybeEnumType();
JSType valueEnumPrimitiveType =
valueEnumType.getElementsType().getPrimitiveType();
validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
declInfo.getEnumParameterType().evaluate(t.getTypedScope(), typeRegistry),
"incompatible enum element types");
}
开发者ID:google,项目名称:closure-compiler,代码行数:33,代码来源:TypeCheck.java
示例8: attachJSDocInfoToNominalTypeOrShape
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* Handle cases #1 and #3 in the class doc.
*/
private static void attachJSDocInfoToNominalTypeOrShape(
ObjectType objType, JSDocInfo docInfo, @Nullable String qName) {
if (objType.isConstructor() ||
objType.isEnumType() ||
objType.isInterface()) {
// Named types.
if (objType.hasReferenceName() &&
objType.getReferenceName().equals(qName)) {
objType.setJSDocInfo(docInfo);
if (objType.isConstructor() || objType.isInterface()) {
JSType.toMaybeFunctionType(objType).getInstanceType().setJSDocInfo(docInfo);
} else if (objType instanceof EnumType) {
((EnumType) objType).getElementsType().setJSDocInfo(docInfo);
}
}
} else if (!objType.isNativeObjectType() && objType.isFunctionType()) {
// Structural functions.
objType.setJSDocInfo(docInfo);
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:25,代码来源:InferJSDocInfo.java
示例9: attachJSDocInfoToNominalTypeOrShape
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* Handle cases #1 and #3 in the class doc.
*/
private static void attachJSDocInfoToNominalTypeOrShape(
ObjectType objType, JSDocInfo docInfo, @Nullable String qName) {
if (objType.isConstructor() ||
objType.isEnumType() ||
objType.isInterface()) {
// Named types.
if (objType.hasReferenceName() &&
objType.getReferenceName().equals(qName)) {
objType.setJSDocInfo(docInfo);
if (objType.isConstructor() || objType.isInterface()) {
JSType.toMaybeFunctionType(objType).getInstanceType().setJSDocInfo(
docInfo);
} else if (objType instanceof EnumType) {
((EnumType) objType).getElementsType().setJSDocInfo(docInfo);
}
}
} else if (!objType.isNativeObjectType() &&
objType.isFunctionType()) {
// Structural functions.
objType.setJSDocInfo(docInfo);
}
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:27,代码来源:InferJSDocInfo.java
示例10: visitEnumType
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
@Override
protected boolean visitEnumType(EnumType type) {
// Create a method getValue() that returns the real value of the enum member at runtime.
Method m = new Method();
m.setName("getValue");
m.setFinal(true);
m.addAnnotation(Annotation.builder().type(JS_OVERLAY).build());
TypeReference returnType =
getJavaTypeRegistry().createTypeReference(type.getElementsType().getPrimitiveType());
TypeReference uncheckedCastTypeParameter =
getJavaTypeRegistry()
.createTypeReference(type.getElementsType().getPrimitiveType(), IN_TYPE_ARGUMENTS);
m.setReturnType(returnType);
m.setBody(
new ReturnStatement(
new MethodInvocation(
new TypeQualifier(PredefinedTypeReference.JS),
"uncheckedCast",
ImmutableList.of(OBJECT),
ImmutableList.of(LiteralExpression.THIS),
ImmutableList.of(uncheckedCastTypeParameter))));
getCurrentJavaType().addMethod(m);
// add a private constructor to disallow instantiation
Method privateConstructor = Method.newConstructor();
privateConstructor.setAccessModifier(PRIVATE);
getCurrentJavaType().addMethod(privateConstructor);
return true;
}
开发者ID:google,项目名称:jsinterop-generator,代码行数:32,代码来源:EnumMemberCollector.java
示例11: acceptEnumType
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
private void acceptEnumType(EnumType type) {
pushCurrentJavaType(type);
if (visitEnumType(type)) {
type.getOwnPropertyNames()
.stream()
.sorted()
.forEach(propertyName -> acceptEnumMember(type.getOwnSlot(propertyName)));
}
endVisitEnumType(type);
popCurrentJavaType();
}
开发者ID:google,项目名称:jsinterop-generator,代码行数:15,代码来源:AbstractClosureVisitor.java
示例12: checkEnumInitializer
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* <p>Checks the initializer of an enum. An enum can be initialized with an
* object literal whose values must be subtypes of the declared enum element
* type, or by copying another enum.</p>
*
* <p>In the case of an enum copy, we verify that the enum element type of the
* enum used for initialization is a subtype of the enum element type of
* the enum the value is being copied in.</p>
*
* <p>Examples:</p>
* <pre>var myEnum = {FOO: ..., BAR: ...};
* var myEnum = myOtherEnum;</pre>
*
* @param value the value used for initialization of the enum
* @param primitiveType The type of each element of the enum.
*/
private void checkEnumInitializer(
NodeTraversal t, Node value, JSType primitiveType) {
if (value.getType() == Token.OBJECTLIT) {
// re-using value as the value of the object literal and advancing twice
value = value.getFirstChild();
value = (value == null) ? null : value.getNext();
while (value != null) {
// the value's type must be assignable to the enum's primitive type
validator.expectCanAssignTo(t, value, getJSType(value), primitiveType,
"element type must match enum's type");
// advancing twice
value = value.getNext();
value = (value == null) ? null : value.getNext();
}
} else if (value.getJSType() instanceof EnumType) {
// TODO(user): Remove the instanceof check in favor
// of a type.isEnumType() predicate. Currently, not all enum types are
// implemented by the EnumClass, e.g. the unknown type and the any
// type. The types need to be defined by interfaces such that an
// implementation can implement multiple types interface.
EnumType valueEnumType = (EnumType) value.getJSType();
JSType valueEnumPrimitiveType =
valueEnumType.getElementsType().getPrimitiveType();
validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
primitiveType, "incompatible enum element types");
} else {
// The error condition is handled in TypedScopeCreator.
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:47,代码来源:TypeCheck.java
示例13: testEnum
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
public void testEnum() {
testSame("/** @enum */ var Foo = {BAR: 1}; var f = Foo;");
ObjectType f = (ObjectType) findNameType("f", globalScope);
assertTrue(f.hasProperty("BAR"));
assertEquals("Foo.<number>", f.getPropertyType("BAR").toString());
assertTrue(f instanceof EnumType);
}
开发者ID:andyjko,项目名称:feedlack,代码行数:8,代码来源:TypedScopeCreatorTest.java
示例14: testEnumAlias
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
public void testEnumAlias() {
testSame("/** @enum */ var Foo = {BAR: 1}; " +
"/** @enum */ var FooAlias = Foo; var f = FooAlias;");
assertEquals("Foo.<number>",
registry.getType("FooAlias").toString());
assertEquals(registry.getType("FooAlias"),
registry.getType("Foo"));
ObjectType f = (ObjectType) findNameType("f", globalScope);
assertTrue(f.hasProperty("BAR"));
assertEquals("Foo.<number>", f.getPropertyType("BAR").toString());
assertTrue(f instanceof EnumType);
}
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:TypedScopeCreatorTest.java
示例15: checkPropertyAccess
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
/**
* Emit a warning if we can prove that a property cannot possibly be
* defined on an object. Note the difference between JS and a strictly
* statically typed language: we're checking if the property
* *cannot be defined*, whereas a java compiler would check if the
* property *can be undefined*.
*/
private void checkPropertyAccess(JSType childType, String propName,
NodeTraversal t, Node n) {
// If the property type is unknown, check the object type to see if it
// can ever be defined. We explicitly exclude CHECKED_UNKNOWN (for
// properties where we've checked that it exists, or for properties on
// objects that aren't in this binary).
JSType propType = getJSType(n);
if (propType.isEquivalentTo(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
childType = childType.autobox();
ObjectType objectType = ObjectType.cast(childType);
if (objectType != null) {
// We special-case object types so that checks on enums can be
// much stricter, and so that we can use hasProperty (which is much
// faster in most cases).
if (!objectType.hasProperty(propName) ||
objectType.isEquivalentTo(
typeRegistry.getNativeType(UNKNOWN_TYPE))) {
if (objectType instanceof EnumType) {
report(t, n, INEXISTENT_ENUM_ELEMENT, propName);
} else {
checkPropertyAccessHelper(objectType, propName, t, n);
}
}
} else {
checkPropertyAccessHelper(childType, propName, t, n);
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:37,代码来源:TypeCheck.java
示例16: testEnumAlias
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
public void testEnumAlias() {
testSame("/** @enum */ var Foo = {BAR: 1}; " +
"/** @enum */ var FooAlias = Foo; var f = FooAlias;");
assertEquals("Foo.<number>",
registry.getType("FooAlias").toString());
Asserts.assertTypeEquals(registry.getType("FooAlias"),
registry.getType("Foo"));
ObjectType f = (ObjectType) findNameType("f", globalScope);
assertTrue(f.hasProperty("BAR"));
assertEquals("Foo.<number>", f.getPropertyType("BAR").toString());
assertTrue(f instanceof EnumType);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:TypedScopeCreatorTest.java
示例17: testEnum
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
public void testEnum() {
testSame("/** @enum */ var Foo = {BAR: 1}; var f = Foo;");
ObjectType f = (ObjectType) findNameType("f", globalScope);
assertTrue(f.hasProperty("BAR"));
assertEquals("Foo<number>", f.getPropertyType("BAR").toString());
assertThat(f).isInstanceOf(EnumType.class);
}
开发者ID:google,项目名称:closure-compiler,代码行数:8,代码来源:TypedScopeCreatorTest.java
示例18: testEnumAlias
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
public void testEnumAlias() {
testSame("/** @enum */ var Foo = {BAR: 1}; " +
"/** @enum */ var FooAlias = Foo; var f = FooAlias;");
assertEquals("Foo<number>",
registry.getType("FooAlias").toString());
Asserts.assertTypeEquals(registry.getType("FooAlias"),
registry.getType("Foo"));
ObjectType f = (ObjectType) findNameType("f", globalScope);
assertTrue(f.hasProperty("BAR"));
assertEquals("Foo<number>", f.getPropertyType("BAR").toString());
assertThat(f).isInstanceOf(EnumType.class);
}
开发者ID:google,项目名称:closure-compiler,代码行数:15,代码来源:TypedScopeCreatorTest.java
示例19: visitEnumType
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
protected boolean visitEnumType(EnumType type) {
return true;
}
开发者ID:google,项目名称:jsinterop-generator,代码行数:4,代码来源:AbstractClosureVisitor.java
示例20: toEnumType
import com.google.javascript.rhino.jstype.EnumType; //导入依赖的package包/类
private static EnumType toEnumType(JSType type) {
return checkNotNull(type.toMaybeEnumType());
}
开发者ID:google,项目名称:jsinterop-generator,代码行数:4,代码来源:AbstractClosureVisitor.java
注:本文中的com.google.javascript.rhino.jstype.EnumType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论