Search in sources :

Example 1 with JSElementInfo

use of net.vtst.ow.eclipse.js.closure.editor.JSElementInfo in project ow by vtst.

the class ClosureCompletionProposalCollector method collectProposalsFromType.

/**
   * Collect the completion proposal for a type.
   * @param map  The map in which completion proposals are inserted.
   * @param prefix  The last segment of the prefix.
   * @param alternateType  The type to analyze.
   * @param type  The union type which {@code alternateType} belongs to.
   */
private void collectProposalsFromType(Map<String, ClosureCompletionProposal> map, String prefix, JSType alternateType) {
    if (alternateType instanceof ObjectType) {
        ObjectType alternateObjectType = (ObjectType) alternateType;
        for (String propertyName : alternateObjectType.getPropertyNames()) {
            if (isValidForPrefix(propertyName, prefix) && isVisibleName(propertyName)) {
                ClosureCompletionProposal proposal = map.get(propertyName);
                if (proposal == null) {
                    // This is slightly unefficient, because we build the elementInfo before
                    // checking that the node is concrete.  But I'm not sure it is useful to
                    // complicate the code for this particular case.
                    JSElementInfo elementInfo = JSElementInfo.makeFromProperty(context.getCompilerRun(), alternateObjectType, propertyName);
                    if (isConcreteNode(elementInfo.getNode())) {
                        proposal = new ClosureCompletionProposal(context, propertyName, elementInfo);
                        map.put(propertyName, proposal);
                    }
                }
                if (proposal != null) {
                    proposal.addVisibility(getVisibilityOfProperty(alternateObjectType, propertyName));
                }
            }
        }
    }
}
Also used : ObjectType(com.google.javascript.rhino.jstype.ObjectType) JSElementInfo(net.vtst.ow.eclipse.js.closure.editor.JSElementInfo)

Example 2 with JSElementInfo

use of net.vtst.ow.eclipse.js.closure.editor.JSElementInfo in project ow by vtst.

the class ClosureTextHover method getHoverHTML.

/* (non-Javadoc)
   * @see net.vtst.ow.eclipse.js.closure.editor.hover.AbstractTextHover#getHoverHTML(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
   */
@Override
protected String getHoverHTML(ITextViewer viewer, IRegion region) {
    CompilableJSUnit unit = getJSUnit();
    if (unit == null)
        return null;
    CompilerRun run = getCompilerRun(unit);
    if (run == null)
        return null;
    Node node = run.getNode(unit, region.getOffset());
    if (node == null)
        return null;
    JSElementInfo info = getElementInfo(run, node);
    if (info == null)
        return null;
    return info.getHTMLStringForHover();
}
Also used : Node(com.google.javascript.rhino.Node) JSElementInfo(net.vtst.ow.eclipse.js.closure.editor.JSElementInfo) CompilerRun(net.vtst.ow.closure.compiler.compile.CompilerRun) CompilableJSUnit(net.vtst.ow.closure.compiler.compile.CompilableJSUnit)

Aggregations

JSElementInfo (net.vtst.ow.eclipse.js.closure.editor.JSElementInfo)2 Node (com.google.javascript.rhino.Node)1 ObjectType (com.google.javascript.rhino.jstype.ObjectType)1 CompilableJSUnit (net.vtst.ow.closure.compiler.compile.CompilableJSUnit)1 CompilerRun (net.vtst.ow.closure.compiler.compile.CompilerRun)1