Java Code Examples for com.google.javascript.rhino.jstype.Property#getName()
The following examples show how to use
com.google.javascript.rhino.jstype.Property#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeInspector.java From js-dossier with Apache License 2.0 | 5 votes |
/** 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; }
Example 2
Source File: TypeInspector.java From js-dossier with Apache License 2.0 | 4 votes |
/** * Extracts information on the properties defined directly on the given nominal type. For classes * and interfaces, this will return information on the <em>static</em> properties, not instance * properties. */ public Report inspectType() { List<Property> properties = getProperties(inspectedType); if (properties.isEmpty()) { return Report.empty(); } properties.sort(comparing(Property::getName)); Report.Builder report = Report.builder(); for (Property property : properties) { String name = property.getName(); if (!inspectedType.isModuleExports() && !inspectedType.isNamespace()) { String typeName = dfs.getDisplayName(inspectedType); int index = typeName.lastIndexOf('.'); if (index != -1) { typeName = typeName.substring(index + 1); } name = typeName + "." + name; } PropertyDocs docs = findStaticPropertyJsDoc(inspectedType, property); JsDoc jsdoc = docs.getJsDoc(); if (jsdoc.getVisibility() == JSDocInfo.Visibility.PRIVATE || (name.endsWith(".superClass_") && property.getType().isFunctionPrototypeType())) { continue; } if (jsdoc.isDefine()) { name = dfs.getQualifiedDisplayName(inspectedType) + "." + property.getName(); report .compilerConstantsBuilder() .add(getPropertyData(name, property.getType(), property.getNode(), docs)); } else if (property.getType().isFunctionType()) { report .functionsBuilder() .add( getFunctionData( name, property.getType().toMaybeFunctionType(), property.getNode(), docs)); } else if (!property.getType().isEnumElementType()) { report .propertiesBuilder() .add(getPropertyData(name, property.getType(), property.getNode(), docs)); } } return report.build(); }