Search in sources :

Example 1 with IMetaTag

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

the class ActionScriptTextDocumentService method addStyleMetadataToAutoCompleteMXML.

private void addStyleMetadataToAutoCompleteMXML(TypeScope typeScope, String prefix, CompletionList result) {
    ArrayList<String> styleNames = new ArrayList<>();
    IDefinition definition = typeScope.getDefinition();
    List<CompletionItem> items = result.getItems();
    while (definition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) definition;
        IMetaTag[] styleMetaTags = typeScope.getDefinition().getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_STYLE);
        for (IMetaTag styleMetaTag : styleMetaTags) {
            String styleName = styleMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_STYLE_NAME);
            if (styleNames.contains(styleName)) {
                //avoid duplicates!
                continue;
            }
            styleNames.add(styleName);
            IDefinition styleDefinition = currentProject.resolveSpecifier(classDefinition, styleName);
            if (styleDefinition == null) {
                continue;
            }
            boolean foundExisting = false;
            for (CompletionItem item : items) {
                if (item.getLabel().equals(styleName)) {
                    //we want to avoid adding a duplicate item with the same
                    //name. if there's a conflict, the compiler will know
                    //how to handle it.
                    foundExisting = true;
                    break;
                }
            }
            if (foundExisting) {
                break;
            }
            CompletionItem item = new CompletionItem();
            item.setKind(CompletionItemKind.Field);
            item.setLabel(styleName);
            if (prefix != null) {
                item.setInsertText(prefix + IMXMLCoreConstants.colon + styleName);
            }
            item.setDetail(getDefinitionDetail(styleDefinition));
            items.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)

Example 2 with IMetaTag

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

the class ActionScriptTextDocumentService method autoCompleteDefinitions.

private void autoCompleteDefinitions(CompletionList result, boolean forMXML, boolean typesOnly, String packageName, IDefinition definitionToSkip) {
    String skipQualifiedName = null;
    if (definitionToSkip != null) {
        skipQualifiedName = definitionToSkip.getQualifiedName();
    }
    for (ICompilationUnit unit : compilationUnits) {
        if (unit == null) {
            continue;
        }
        Collection<IDefinition> definitions = null;
        try {
            definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
        } catch (Exception e) {
            //safe to ignore
            continue;
        }
        for (IDefinition definition : definitions) {
            boolean isType = definition instanceof ITypeDefinition;
            if (!typesOnly || isType) {
                if (packageName == null || definition.getPackageName().equals(packageName)) {
                    if (skipQualifiedName != null && skipQualifiedName.equals(definition.getQualifiedName())) {
                        continue;
                    }
                    if (isType) {
                        IMetaTag excludeClassMetaTag = definition.getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_EXCLUDECLASS);
                        if (excludeClassMetaTag != null) {
                            //skip types with [ExcludeClass] metadata
                            continue;
                        }
                    }
                    if (forMXML && isType) {
                        ITypeDefinition typeDefinition = (ITypeDefinition) definition;
                        addMXMLTypeDefinitionAutoComplete(typeDefinition, result);
                    } else {
                        addDefinitionAutoCompleteActionScript(definition, result);
                    }
                }
            }
        }
    }
    if (packageName == null || packageName.equals("")) {
        CompletionItem item = new CompletionItem();
        item.setKind(CompletionItemKind.Class);
        item.setLabel(IASKeywordConstants.VOID);
        result.getItems().add(item);
    }
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IMetaTag(org.apache.flex.compiler.definitions.metadata.IMetaTag) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) CompletionItem(org.eclipse.lsp4j.CompletionItem) IDefinition(org.apache.flex.compiler.definitions.IDefinition) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with IMetaTag

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

the class ActionScriptTextDocumentService method addDefinitionsInTypeScopeToAutoComplete.

private void addDefinitionsInTypeScopeToAutoComplete(TypeScope typeScope, ASScope otherScope, boolean isStatic, boolean includeSuperStatics, boolean forMXML, String prefix, CompletionList result) {
    IMetaTag[] excludeMetaTags = typeScope.getDefinition().getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_EXCLUDE);
    ArrayList<IDefinition> memberAccessDefinitions = new ArrayList<>();
    Set<INamespaceDefinition> namespaceSet = otherScope.getNamespaceSet(currentProject);
    if (typeScope.getContainingDefinition() instanceof IInterfaceDefinition) {
        //interfaces have a special namespace that isn't actually the same
        //as public, but should be treated the same way
        IInterfaceDefinition interfaceDefinition = (IInterfaceDefinition) typeScope.getContainingDefinition();
        collectInterfaceNamespaces(interfaceDefinition, namespaceSet);
    }
    IClassDefinition otherContainingClass = otherScope.getContainingClass();
    if (otherContainingClass != null) {
        IClassDefinition classDefinition = typeScope.getContainingClass();
        if (classDefinition != null) {
            boolean isSuperClass = Arrays.asList(otherContainingClass.resolveAncestry(currentProject)).contains(classDefinition);
            if (isSuperClass) {
                //namespaces from the super classes
                do {
                    namespaceSet.add(classDefinition.getProtectedNamespaceReference());
                    classDefinition = classDefinition.resolveBaseClass(currentProject);
                } while (classDefinition instanceof IClassDefinition);
            }
        }
    }
    typeScope.getAllPropertiesForMemberAccess(currentProject, memberAccessDefinitions, namespaceSet);
    for (IDefinition localDefinition : memberAccessDefinitions) {
        if (localDefinition.isOverride()) {
            //overrides would add unnecessary duplicates to the list
            continue;
        }
        if (excludeMetaTags != null && excludeMetaTags.length > 0) {
            boolean exclude = false;
            for (IMetaTag excludeMetaTag : excludeMetaTags) {
                String excludeName = excludeMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_EXCLUDE_NAME);
                if (excludeName.equals(localDefinition.getBaseName())) {
                    exclude = true;
                    break;
                }
            }
            if (exclude) {
                continue;
            }
        }
        //there are some things that we need to skip in MXML
        if (forMXML) {
            if (localDefinition instanceof IGetterDefinition) {
                //no getters because we can only set
                continue;
            } else if (localDefinition instanceof IFunctionDefinition && !(localDefinition instanceof ISetterDefinition)) {
                //no calling functions, unless they're setters
                continue;
            }
        } else //actionscript
        {
            if (localDefinition instanceof ISetterDefinition) {
                ISetterDefinition setter = (ISetterDefinition) localDefinition;
                IGetterDefinition getter = setter.resolveGetter(currentProject);
                if (getter != null) {
                    //would add a duplicate entry
                    continue;
                }
            }
        }
        if (isStatic) {
            if (!localDefinition.isStatic()) {
                //static, skip it
                continue;
            }
            if (!includeSuperStatics && localDefinition.getParent() != typeScope.getContainingDefinition()) {
                //aren't available with member access
                continue;
            }
        }
        if (!isStatic && localDefinition.isStatic()) {
            //skip it!
            continue;
        }
        if (forMXML) {
            addDefinitionAutoCompleteMXML(localDefinition, prefix, null, result);
        } else //actionscript
        {
            addDefinitionAutoCompleteActionScript(localDefinition, result);
        }
    }
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) ArrayList(java.util.ArrayList) ISetterDefinition(org.apache.flex.compiler.definitions.ISetterDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IMetaTag(org.apache.flex.compiler.definitions.metadata.IMetaTag) IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) INamespaceDefinition(org.apache.flex.compiler.definitions.INamespaceDefinition) IGetterDefinition(org.apache.flex.compiler.definitions.IGetterDefinition)

Example 4 with IMetaTag

use of org.apache.flex.compiler.definitions.metadata.IMetaTag 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)4 IMetaTag (org.apache.flex.compiler.definitions.metadata.IMetaTag)4 ArrayList (java.util.ArrayList)3 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)1 IGetterDefinition (org.apache.flex.compiler.definitions.IGetterDefinition)1 IInterfaceDefinition (org.apache.flex.compiler.definitions.IInterfaceDefinition)1 INamespaceDefinition (org.apache.flex.compiler.definitions.INamespaceDefinition)1 ISetterDefinition (org.apache.flex.compiler.definitions.ISetterDefinition)1 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)1 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)1