本文整理汇总了Java中com.google.javascript.rhino.jstype.Property类的典型用法代码示例。如果您正苦于以下问题:Java Property类的具体用法?Java Property怎么用?Java Property使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Property类属于com.google.javascript.rhino.jstype包,在下文中一共展示了Property类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitEnumMember
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Override
protected boolean visitEnumMember(Property enumMember) {
Field enumField = new Field();
enumField.setName(enumMember.getName());
enumField.setType(getJavaTypeRegistry().createTypeReference(enumMember.getType()));
enumField.setStatic(true);
enumField.setNativeReadOnly(true);
enumField.addAnnotation(
Annotation.builder()
.type(JS_PROPERTY)
.nameAttribute(enumMember.getName())
.namespaceAttribute(enumMember.getType().getDisplayName())
.build());
getCurrentJavaType().addField(enumField);
return true;
}
示例2: getOwnProperties
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
private Map<String, InstanceProperty> getOwnProperties(ObjectType object) {
ObjectType definingType = object;
if (definingType.isFunctionPrototypeType()) {
definingType = definingType.getOwnerFunction();
} else if (definingType.isInstanceType()) {
definingType = definingType.getConstructor();
}
Map<String, InstanceProperty> properties = new HashMap<>();
for (String name : object.getOwnPropertyNames()) {
if (!"constructor".equals(name)) {
Property property = object.getOwnSlot(name);
properties.put(
property.getName(),
InstanceProperty.builder()
.setOwnerType(getFirst(registry.getTypes(definingType), null))
.setDefinedByType(definingType)
.setName(property.getName())
.setType(getType(object, property))
.setNode(property.getNode())
.setJsDoc(JsDoc.from(property.getJSDocInfo()))
.build());
}
}
return properties;
}
示例3: getPropertyData
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
private com.github.jsdossier.proto.Property getPropertyData(
String name,
JSType type,
Node node,
PropertyDocs docs,
@Nullable NamedType definedBy,
Iterable<InstanceProperty> overrides) {
com.github.jsdossier.proto.Property.Builder builder =
com.github.jsdossier.proto.Property.newBuilder()
.setBase(getBasePropertyDetails(name, type, node, docs, definedBy, overrides));
TypeExpressionParser parser =
expressionParserFactory.create(linkFactory.withTypeContext(docs.getContextType()));
if (docs.getJsDoc().getType() != null) {
JSTypeExpression typeExpression = docs.getJsDoc().getType();
type = evaluate(typeExpression);
}
if (type != null) {
TypeExpression expression = parser.parse(type);
builder.setType(expression);
}
return builder.build();
}
示例4: caseRecordType
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
private void caseRecordType(final ObjectType type) {
Iterable<Property> properties =
type.getOwnPropertyNames()
.stream()
.map(type::getOwnSlot)
.filter(input -> input != null && !input.getType().isNoType())
.sorted((o1, o2) -> o1.getName().compareTo(o2.getName()))
.collect(toList());
RecordType.Builder recordType = currentExpression().getRecordTypeBuilder();
for (Property property : properties) {
RecordType.Entry.Builder entry = recordType.addEntryBuilder();
entry.setKey(property.getName());
expressions.addLast(entry.getValueBuilder());
property.getType().visit(this);
expressions.removeLast();
}
}
示例5: parseExpression_typeIsReferenceToNullableExtern
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Test
public void parseExpression_typeIsReferenceToNullableExtern() {
util.compile(
createSourceFile(
fs.getPath("source/modules/one.js"),
"var stream = require('stream');",
"/** @constructor */",
"function Writer() {}",
"/** @type {stream.Stream} */",
"Writer.prototype.stream = null;",
"exports.Writer = Writer"));
NominalType type = typeRegistry.getType("module$exports$module$source$modules$one.Writer");
Property property = type.getType().toMaybeFunctionType().getInstanceType().getSlot("stream");
TypeExpression expression =
parserFactory.create(linkFactoryBuilder.create(type)).parse(property.getType());
assertThat(expression).isEqualTo(unionType(namedTypeExpression("stream.Stream"), NULL_TYPE));
}
示例6: parsesReturnDescription_oneLineB
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Test
public void parsesReturnDescription_oneLineB() {
util.compile(
path("foo/bar.js"),
"/** @constructor */",
"var Foo = function() {};",
"/**",
" * @return nothing.",
" */",
"Foo.bar = function() { return ''; };");
NominalType foo = getOnlyElement(typeRegistry.getAllTypes());
Property bar = getOnlyElement(getProperties(foo));
assertEquals("bar", bar.getName());
assertTrue(bar.getType().isFunctionType());
assertEquals("nothing.", JsDoc.from(bar.getJSDocInfo()).getReturnClause().getDescription());
}
示例7: parsesReturnDescription_twoLines
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Test
public void parsesReturnDescription_twoLines() {
util.compile(
path("foo/bar.js"),
"/** @constructor */",
"var Foo = function() {};",
"/**",
" * @return nothing over",
" * two lines.",
" */",
"Foo.bar = function() { return ''; };");
NominalType foo = getOnlyElement(typeRegistry.getAllTypes());
Property bar = getOnlyElement(getProperties(foo));
assertEquals("bar", bar.getName());
assertTrue(bar.getType().isFunctionType());
assertEquals(
"nothing over\n two lines.",
JsDoc.from(bar.getJSDocInfo()).getReturnClause().getDescription());
}
示例8: parsesReturnDescription_manyLines
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Test
public void parsesReturnDescription_manyLines() {
util.compile(
path("foo/bar.js"),
"/** @constructor */",
"var Foo = function() {};",
"/**",
" * @return nothing over",
" * many",
" * lines.",
" */",
"Foo.bar = function() { return ''; };");
NominalType foo = getOnlyElement(typeRegistry.getAllTypes());
Property bar = getOnlyElement(getProperties(foo));
assertEquals("bar", bar.getName());
assertTrue(bar.getType().isFunctionType());
assertEquals(
"nothing over\n many\n lines.",
JsDoc.from(bar.getJSDocInfo()).getReturnClause().getDescription());
}
示例9: extractsDefineComments_blockCommentAboveAnnotation
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Test
public void extractsDefineComments_blockCommentAboveAnnotation() {
util.compile(
path("foo/bar.js"),
"goog.provide('foo');",
"",
"/**",
" * Hello, world!",
" * @define {boolean}",
" */",
"foo.bar = false;");
NominalType type = getOnlyElement(typeRegistry.getAllTypes());
assertThat(type.getName()).isEqualTo("foo");
Property property = getOnlyElement(getProperties(type));
assertThat(property.getName()).isEqualTo("bar");
JsDoc doc = JsDoc.from(property.getJSDocInfo());
assertThat(doc).isNotNull();
assertThat(doc.getBlockComment()).isEqualTo("Hello, world!");
}
示例10: extractsDefineComments_commentInlineWithAnnotation
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Test
public void extractsDefineComments_commentInlineWithAnnotation() {
util.compile(
path("foo/bar.js"),
"goog.provide('foo');",
"",
"/**",
" * @define {boolean} Hello, world!",
" * Goodbye, world!",
" */",
"foo.bar = false;");
NominalType type = getOnlyElement(typeRegistry.getAllTypes());
assertThat(type.getName()).isEqualTo("foo");
Property property = getOnlyElement(getProperties(type));
assertThat(property.getName()).isEqualTo("bar");
JsDoc doc = JsDoc.from(property.getJSDocInfo());
assertThat(doc).isNotNull();
assertThat(doc.getBlockComment()).isEqualTo("Hello, world!\n" + " Goodbye, world!");
}
示例11: visitModule
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
@Override
protected boolean visitModule(StaticTypedSlot<JSType> module) {
String jsFqn =
module instanceof Property
? ((Property) module).getNode().getOriginalQualifiedName()
: module.getName();
Type javaType = createJavaType(jsFqn, NAMESPACE, false);
getJavaTypeRegistry().registerJavaType(javaType, module.getType());
super.pushCurrentJavaType(javaType);
return true;
}
示例12: classHasToString
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
/**
* Checks whether class has overridden toString() method. All objects has native toString()
* method but we ignore it as it is not useful so we need user-provided toString() method.
*/
private boolean classHasToString(ObjectType type) {
Property toStringProperty = type.getOwnSlot("toString");
if (toStringProperty != null) {
return toStringProperty.getType().isFunctionType();
}
ObjectType parent = type.getParentScope();
if (parent != null && !parent.isNativeObjectType()) {
return classHasToString(parent);
}
return false;
}
示例13: addInstanceProperties
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
private void addInstanceProperties(JsType.Builder spec) {
TypeInspector.Report report = typeInspector.inspectInstanceType();
for (com.github.jsdossier.proto.Property prop : report.getProperties()) {
spec.addField(prop);
updateInstancePropertyIndex(spec, prop.getBase());
}
for (com.github.jsdossier.proto.Function func : report.getFunctions()) {
spec.addMethod(func);
updateInstancePropertyIndex(spec, func.getBase());
}
}
示例14: getProperties
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
/** Returns the raw properties for the given type. */
public List<Property> getProperties(NominalType nominalType) {
JSType type = nominalType.getType();
ObjectType object = ObjectType.cast(type);
if (object == null) {
return ImmutableList.of();
}
List<Property> properties = new ArrayList<>();
for (String name : object.getOwnPropertyNames()) {
Property property = null;
if (type.isFunctionType()) {
if (!isBuiltInFunctionProperty(type, name)) {
property = object.getOwnSlot(name);
}
} else if (!"prototype".equals(name)) {
property = object.getOwnSlot(name);
}
if (property != null) {
if (property.getType().isConstructor()
&& isConstructorTypeDefinition(
property.getType(), JsDoc.from(property.getJSDocInfo()))) {
continue;
}
// If the property is another module and the inspected type is also a module, then count
// the property as a static property. Otherwise, if the property i registered as a nominal
// type, it does not count as a static property. It should also be ignored if it is not
// registered as a nominal type, but its qualified name has been filtered out by the user.
String qualifiedName = nominalType.getName() + "." + property.getName();
if (((inspectedType.isModuleExports() && registry.isModule(property.getType()))
|| registry.getTypes(property.getType()).isEmpty())
&& !typeFilter.test(qualifiedName)) {
properties.add(property);
}
}
}
return properties;
}
示例15: getType
import com.google.javascript.rhino.jstype.Property; //导入依赖的package包/类
private static JSType getType(ObjectType object, Property property) {
JSType type = object.findPropertyType(property.getName());
if (type.isUnknownType()) {
type = property.getType();
}
return type;
}