Search in sources :

Example 6 with IFunctionDefinition

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

the class ActionScriptTextDocumentService method classDefinitionToConstructor.

private IFunctionDefinition classDefinitionToConstructor(IClassDefinition definition) {
    IASScope scope = definition.getContainedScope();
    Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
    for (IDefinition localDefinition : definitions) {
        if (localDefinition instanceof IFunctionDefinition) {
            IFunctionDefinition functionDefinition = (IFunctionDefinition) localDefinition;
            if (functionDefinition.isConstructor()) {
                return functionDefinition;
            }
        }
    }
    return null;
}
Also used : IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IASScope(org.apache.flex.compiler.scopes.IASScope) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 7 with IFunctionDefinition

use of org.apache.flex.compiler.definitions.IFunctionDefinition 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

IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)7 IDefinition (org.apache.flex.compiler.definitions.IDefinition)6 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)4 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)4 IInterfaceDefinition (org.apache.flex.compiler.definitions.IInterfaceDefinition)3 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)3 IASScope (org.apache.flex.compiler.scopes.IASScope)3 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)3 ArrayList (java.util.ArrayList)2 IConstantDefinition (org.apache.flex.compiler.definitions.IConstantDefinition)2 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)2 IPackageDefinition (org.apache.flex.compiler.definitions.IPackageDefinition)2 IParameterDefinition (org.apache.flex.compiler.definitions.IParameterDefinition)2 StringReader (java.io.StringReader)1 Path (java.nio.file.Path)1 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)1 IAccessorDefinition (org.apache.flex.compiler.definitions.IAccessorDefinition)1 IGetterDefinition (org.apache.flex.compiler.definitions.IGetterDefinition)1 INamespaceDefinition (org.apache.flex.compiler.definitions.INamespaceDefinition)1 ISetterDefinition (org.apache.flex.compiler.definitions.ISetterDefinition)1