Search in sources :

Example 1 with IStyleDefinition

use of org.apache.flex.compiler.definitions.IStyleDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method mxmlCompletion.

private CompletableFuture<CompletionList> mxmlCompletion(TextDocumentPositionParams position, IMXMLTagData offsetTag) {
    CompletionList result = new CompletionList();
    result.setIsIncomplete(false);
    result.setItems(new ArrayList<>());
    if (isInXMLComment(position)) {
        //if we're inside a comment, no completion!
        return CompletableFuture.completedFuture(result);
    }
    IMXMLTagData parentTag = offsetTag.getParentTag();
    //for some reason, the attributes list includes the >, but that's not
    //what we want here, so check if currentOffset isn't the end of the tag!
    boolean isAttribute = offsetTag.isOffsetInAttributeList(currentOffset) && currentOffset < offsetTag.getAbsoluteEnd();
    if (isAttribute && offsetTag.isCloseTag()) {
        return CompletableFuture.completedFuture(result);
    }
    //inside <fx:Declarations>
    if (isDeclarationsTag(offsetTag)) {
        if (!isAttribute) {
            autoCompleteTypesForMXML(result);
        }
        return CompletableFuture.completedFuture(result);
    }
    IDefinition offsetDefinition = getDefinitionForMXMLTag(offsetTag);
    if (offsetDefinition == null) {
        IDefinition parentDefinition = null;
        if (parentTag != null) {
            parentDefinition = getDefinitionForMXMLTag(parentTag);
        }
        if (parentDefinition != null) {
            if (parentDefinition instanceof IClassDefinition) {
                IClassDefinition classDefinition = (IClassDefinition) parentDefinition;
                String offsetPrefix = offsetTag.getPrefix();
                if (offsetPrefix.length() == 0 || parentTag.getPrefix().equals(offsetPrefix)) {
                    //only add members if the prefix is the same as the
                    //parent tag. members can't have different prefixes.
                    //also allow members when we don't have a prefix.
                    addMembersForMXMLTypeToAutoComplete(classDefinition, parentTag, offsetPrefix.length() == 0, result);
                }
                if (!isAttribute) {
                    //tags can't appear in attributes, so skip types
                    String defaultPropertyName = classDefinition.getDefaultPropertyName(currentProject);
                    if (defaultPropertyName != null) {
                        //only add types if the class defines [DefaultProperty]
                        //metadata
                        autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
                    }
                }
            } else {
                //the parent is something like a property, so matching the
                //prefix is not required
                autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
            }
            return CompletableFuture.completedFuture(result);
        } else if (isDeclarationsTag(parentTag)) {
            autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
            return CompletableFuture.completedFuture(result);
        }
        return CompletableFuture.completedFuture(result);
    }
    if (offsetDefinition instanceof IClassDefinition) {
        IMXMLTagAttributeData attribute = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
        if (attribute != null) {
            return mxmlAttributeCompletion(offsetTag, result);
        }
        IClassDefinition classDefinition = (IClassDefinition) offsetDefinition;
        addMembersForMXMLTypeToAutoComplete(classDefinition, offsetTag, !isAttribute, result);
        String defaultPropertyName = classDefinition.getDefaultPropertyName(currentProject);
        if (defaultPropertyName != null && !isAttribute) {
            //if [DefaultProperty] is set, then we can instantiate
            //types as child elements
            //but we don't want to do that when in an attribute
            autoCompleteTypesForMXML(result);
        }
        return CompletableFuture.completedFuture(result);
    }
    if (offsetDefinition instanceof IVariableDefinition || offsetDefinition instanceof IEventDefinition || offsetDefinition instanceof IStyleDefinition) {
        if (!isAttribute) {
            autoCompleteTypesForMXML(result);
        }
        return CompletableFuture.completedFuture(result);
    }
    System.err.println("Unknown definition for MXML completion: " + offsetDefinition.getClass());
    return CompletableFuture.completedFuture(result);
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) IStyleDefinition(org.apache.flex.compiler.definitions.IStyleDefinition) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) IEventDefinition(org.apache.flex.compiler.definitions.IEventDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IMXMLTagAttributeData(org.apache.flex.compiler.mxml.IMXMLTagAttributeData)

Example 2 with IStyleDefinition

use of org.apache.flex.compiler.definitions.IStyleDefinition in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method getDefinitionDetail.

private String getDefinitionDetail(IDefinition definition) {
    StringBuilder detailBuilder = new StringBuilder();
    if (definition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) definition;
        if (classDefinition.isDynamic()) {
            detailBuilder.append(IASKeywordConstants.DYNAMIC);
            detailBuilder.append(" ");
        }
        detailBuilder.append(IASKeywordConstants.CLASS);
        detailBuilder.append(" ");
        if (classDefinition.getPackageName().startsWith(PACKAGE_NAME_NO_IMPORT)) {
            //classes like __AS3__.vec.Vector should not include the
            //package name
            detailBuilder.append(classDefinition.getBaseName());
        } else {
            detailBuilder.append(classDefinition.getQualifiedName());
        }
        IClassDefinition baseClassDefinition = classDefinition.resolveBaseClass(currentProject);
        if (baseClassDefinition != null && !baseClassDefinition.getQualifiedName().equals(IASLanguageConstants.Object)) {
            detailBuilder.append(" ");
            detailBuilder.append(IASKeywordConstants.EXTENDS);
            detailBuilder.append(" ");
            detailBuilder.append(baseClassDefinition.getBaseName());
        }
        IInterfaceDefinition[] interfaceDefinitions = classDefinition.resolveImplementedInterfaces(currentProject);
        if (interfaceDefinitions.length > 0) {
            detailBuilder.append(" ");
            detailBuilder.append(IASKeywordConstants.IMPLEMENTS);
            detailBuilder.append(" ");
            appendInterfaceNamesToDetail(detailBuilder, interfaceDefinitions);
        }
    } else if (definition instanceof IInterfaceDefinition) {
        IInterfaceDefinition interfaceDefinition = (IInterfaceDefinition) definition;
        detailBuilder.append(IASKeywordConstants.INTERFACE);
        detailBuilder.append(" ");
        detailBuilder.append(interfaceDefinition.getQualifiedName());
        IInterfaceDefinition[] interfaceDefinitions = interfaceDefinition.resolveExtendedInterfaces(currentProject);
        if (interfaceDefinitions.length > 0) {
            detailBuilder.append(" ");
            detailBuilder.append(IASKeywordConstants.EXTENDS);
            detailBuilder.append(" ");
            appendInterfaceNamesToDetail(detailBuilder, interfaceDefinitions);
        }
    } else if (definition instanceof IVariableDefinition) {
        IVariableDefinition variableDefinition = (IVariableDefinition) definition;
        IDefinition parentDefinition = variableDefinition.getParent();
        if (parentDefinition instanceof ITypeDefinition) {
            //IVariableDefinition and IFunctionDefinition 
            if (variableDefinition instanceof IAccessorDefinition) {
                detailBuilder.append("(property) ");
            } else if (variableDefinition instanceof IConstantDefinition) {
                detailBuilder.append("(const) ");
            } else {
                detailBuilder.append("(variable) ");
            }
            detailBuilder.append(parentDefinition.getQualifiedName());
            detailBuilder.append(".");
        } else if (parentDefinition instanceof IFunctionDefinition) {
            if (variableDefinition instanceof IParameterDefinition) {
                detailBuilder.append("(parameter) ");
            } else {
                detailBuilder.append("(local ");
                if (variableDefinition instanceof IConstantDefinition) {
                    detailBuilder.append("const) ");
                } else {
                    detailBuilder.append("var) ");
                }
            }
        } else {
            if (variableDefinition instanceof IConstantDefinition) {
                detailBuilder.append(IASKeywordConstants.CONST);
            } else {
                detailBuilder.append(IASKeywordConstants.VAR);
            }
            detailBuilder.append(" ");
        }
        detailBuilder.append(variableDefinition.getBaseName());
        detailBuilder.append(":");
        detailBuilder.append(variableDefinition.getTypeAsDisplayString());
    } else if (definition instanceof IFunctionDefinition) {
        IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
        IDefinition parentDefinition = functionDefinition.getParent();
        if (parentDefinition instanceof ITypeDefinition) {
            if (functionDefinition.isConstructor()) {
                detailBuilder.append("(constructor) ");
            } else {
                detailBuilder.append("(method) ");
            }
            detailBuilder.append(parentDefinition.getQualifiedName());
            detailBuilder.append(".");
        } else if (parentDefinition instanceof IFunctionDefinition) {
            detailBuilder.append("(local function) ");
        } else {
            detailBuilder.append(IASKeywordConstants.FUNCTION);
            detailBuilder.append(" ");
        }
        detailBuilder.append(getSignatureLabel(functionDefinition));
    } else if (definition instanceof IEventDefinition) {
        IEventDefinition eventDefinition = (IEventDefinition) definition;
        detailBuilder.append("(event) ");
        detailBuilder.append("[");
        detailBuilder.append(IMetaAttributeConstants.ATTRIBUTE_EVENT);
        detailBuilder.append("(");
        detailBuilder.append(IMetaAttributeConstants.NAME_EVENT_NAME);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(eventDefinition.getBaseName());
        detailBuilder.append("\"");
        detailBuilder.append(",");
        detailBuilder.append(IMetaAttributeConstants.NAME_EVENT_TYPE);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(eventDefinition.getTypeAsDisplayString());
        detailBuilder.append("\"");
        detailBuilder.append(")");
        detailBuilder.append("]");
    } else if (definition instanceof IStyleDefinition) {
        IStyleDefinition styleDefinition = (IStyleDefinition) definition;
        detailBuilder.append("(style) ");
        detailBuilder.append("[");
        detailBuilder.append(IMetaAttributeConstants.ATTRIBUTE_STYLE);
        detailBuilder.append("(");
        detailBuilder.append(IMetaAttributeConstants.NAME_STYLE_NAME);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(styleDefinition.getBaseName());
        detailBuilder.append("\"");
        detailBuilder.append(",");
        detailBuilder.append(IMetaAttributeConstants.NAME_STYLE_TYPE);
        detailBuilder.append("=");
        detailBuilder.append("\"");
        detailBuilder.append(styleDefinition.getTypeAsDisplayString());
        detailBuilder.append("\"");
        detailBuilder.append(")");
        detailBuilder.append("]");
    }
    return detailBuilder.toString();
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IAccessorDefinition(org.apache.flex.compiler.definitions.IAccessorDefinition) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) IStyleDefinition(org.apache.flex.compiler.definitions.IStyleDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) IParameterDefinition(org.apache.flex.compiler.definitions.IParameterDefinition) IEventDefinition(org.apache.flex.compiler.definitions.IEventDefinition) IConstantDefinition(org.apache.flex.compiler.definitions.IConstantDefinition)

Aggregations

IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)2 IDefinition (org.apache.flex.compiler.definitions.IDefinition)2 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)2 IStyleDefinition (org.apache.flex.compiler.definitions.IStyleDefinition)2 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)2 IAccessorDefinition (org.apache.flex.compiler.definitions.IAccessorDefinition)1 IConstantDefinition (org.apache.flex.compiler.definitions.IConstantDefinition)1 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)1 IInterfaceDefinition (org.apache.flex.compiler.definitions.IInterfaceDefinition)1 IParameterDefinition (org.apache.flex.compiler.definitions.IParameterDefinition)1 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)1 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)1 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)1 CompletionList (org.eclipse.lsp4j.CompletionList)1