Search in sources :

Example 26 with IDefinition

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

Example 27 with IDefinition

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

the class ActionScriptTextDocumentService method getDefinitionForMXMLTag.

private IDefinition getDefinitionForMXMLTag(IMXMLTagData tag) {
    if (tag == null) {
        return null;
    }
    IDefinition offsetDefinition = currentProject.resolveXMLNameToDefinition(tag.getXMLName(), tag.getMXMLDialect());
    if (offsetDefinition != null) {
        return offsetDefinition;
    }
    if (tag.getXMLName().getXMLNamespace().equals(tag.getMXMLDialect().getLanguageNamespace())) {
        for (String typeName : LANGUAGE_TYPE_NAMES) {
            if (tag.getShortName().equals(typeName)) {
                return currentProject.resolveQNameToDefinition(typeName);
            }
        }
    }
    IMXMLTagData parentTag = tag.getParentTag();
    if (parentTag == null) {
        return null;
    }
    IDefinition parentDefinition = currentProject.resolveXMLNameToDefinition(parentTag.getXMLName(), parentTag.getMXMLDialect());
    if (parentDefinition == null || !(parentDefinition instanceof IClassDefinition)) {
        return null;
    }
    IClassDefinition classDefinition = (IClassDefinition) parentDefinition;
    return currentProject.resolveSpecifier(classDefinition, tag.getShortName());
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 28 with IDefinition

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

the class ActionScriptTextDocumentService method getDefinitionForMXMLTagAttribute.

private IDefinition getDefinitionForMXMLTagAttribute(IMXMLTagData tag, int offset, boolean includeValue) {
    IMXMLTagAttributeData attributeData = null;
    if (includeValue) {
        attributeData = getMXMLTagAttributeAtOffset(tag, offset);
    } else {
        attributeData = getMXMLTagAttributeWithNameAtOffset(tag, offset);
    }
    if (attributeData == null) {
        return null;
    }
    IDefinition tagDefinition = getDefinitionForMXMLTag(tag);
    if (tagDefinition != null && tagDefinition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) tagDefinition;
        return currentProject.resolveSpecifier(classDefinition, attributeData.getShortName());
    }
    return null;
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IMXMLTagAttributeData(org.apache.flex.compiler.mxml.IMXMLTagAttributeData)

Example 29 with IDefinition

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

the class ActionScriptTextDocumentService method mxmlDefinition.

private CompletableFuture<List<? extends Location>> mxmlDefinition(TextDocumentPositionParams position, IMXMLTagData offsetTag) {
    IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
    if (definition == null) {
        //definition referenced at the current position.
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    if (isInsideTagPrefix(offsetTag, currentOffset)) {
        //ignore the tag's prefix
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    List<Location> result = new ArrayList<>();
    resolveDefinition(definition, result);
    return CompletableFuture.completedFuture(result);
}
Also used : ArrayList(java.util.ArrayList) IDefinition(org.apache.flex.compiler.definitions.IDefinition) Location(org.eclipse.lsp4j.Location) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation)

Example 30 with IDefinition

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

the class ActionScriptTextDocumentService method addEventMetadataToAutoCompleteMXML.

private void addEventMetadataToAutoCompleteMXML(TypeScope typeScope, String prefix, CompletionList result) {
    ArrayList<String> eventNames = new ArrayList<>();
    IDefinition definition = typeScope.getDefinition();
    while (definition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) definition;
        IMetaTag[] eventMetaTags = definition.getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_EVENT);
        for (IMetaTag eventMetaTag : eventMetaTags) {
            String eventName = eventMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_EVENT_NAME);
            if (eventNames.contains(eventName)) {
                //avoid duplicates!
                continue;
            }
            eventNames.add(eventName);
            IDefinition eventDefinition = currentProject.resolveSpecifier(classDefinition, eventName);
            if (eventDefinition == null) {
                continue;
            }
            CompletionItem item = new CompletionItem();
            item.setKind(CompletionItemKind.Field);
            item.setLabel(eventName);
            if (prefix != null) {
                item.setInsertText(prefix + IMXMLCoreConstants.colon + eventName);
            }
            item.setDetail(getDefinitionDetail(eventDefinition));
            result.getItems().add(item);
        }
        definition = classDefinition.resolveBaseClass(currentProject);
    }
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IMetaTag(org.apache.flex.compiler.definitions.metadata.IMetaTag) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Aggregations

IDefinition (org.apache.flex.compiler.definitions.IDefinition)30 ArrayList (java.util.ArrayList)12 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)12 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)10 IASScope (org.apache.flex.compiler.scopes.IASScope)7 IIdentifierNode (org.apache.flex.compiler.tree.as.IIdentifierNode)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 ConcurrentModificationException (java.util.ConcurrentModificationException)6 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)6 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)6 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)6 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)5 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)5 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)5 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)4 IMetaTag (org.apache.flex.compiler.definitions.metadata.IMetaTag)4 IASNode (org.apache.flex.compiler.tree.as.IASNode)4 IExpressionNode (org.apache.flex.compiler.tree.as.IExpressionNode)4