Search in sources :

Example 1 with INamespaceDefinition

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

Aggregations

ArrayList (java.util.ArrayList)1 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)1 IDefinition (org.apache.flex.compiler.definitions.IDefinition)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 IMetaTag (org.apache.flex.compiler.definitions.metadata.IMetaTag)1