Search in sources :

Example 11 with IClassDefinition

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

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

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

IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)13 IDefinition (org.apache.flex.compiler.definitions.IDefinition)12 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)6 ArrayList (java.util.ArrayList)5 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)4 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)4 IInterfaceDefinition (org.apache.flex.compiler.definitions.IInterfaceDefinition)4 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)4 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)3 IMetaTag (org.apache.flex.compiler.definitions.metadata.IMetaTag)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ConcurrentModificationException (java.util.ConcurrentModificationException)2 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)2 IConstantDefinition (org.apache.flex.compiler.definitions.IConstantDefinition)2 IParameterDefinition (org.apache.flex.compiler.definitions.IParameterDefinition)2 IStyleDefinition (org.apache.flex.compiler.definitions.IStyleDefinition)2 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)2