Search in sources :

Example 1 with ISetterDefinition

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

the class ActionScriptTextDocumentService method autoCompleteScope.

private void autoCompleteScope(IScopedNode node, boolean typesOnly, CompletionList result) {
    IScopedNode currentNode = node;
    ASScope scope = (ASScope) node.getScope();
    while (currentNode != null) {
        IASScope currentScope = currentNode.getScope();
        boolean isType = currentScope instanceof TypeScope;
        boolean staticOnly = currentNode == node && isType;
        if (currentScope instanceof TypeScope && !typesOnly) {
            TypeScope typeScope = (TypeScope) currentScope;
            addDefinitionsInTypeScopeToAutoComplete(typeScope, scope, true, true, false, null, result);
            if (!staticOnly) {
                addDefinitionsInTypeScopeToAutoCompleteActionScript(typeScope, scope, false, result);
            }
        } else {
            for (IDefinition localDefinition : currentScope.getAllLocalDefinitions()) {
                if (localDefinition.getBaseName().length() == 0) {
                    continue;
                }
                if (typesOnly && !(localDefinition instanceof ITypeDefinition)) {
                    continue;
                }
                if (!staticOnly || localDefinition.isStatic()) {
                    if (localDefinition instanceof ISetterDefinition) {
                        ISetterDefinition setter = (ISetterDefinition) localDefinition;
                        IGetterDefinition getter = setter.resolveGetter(currentProject);
                        if (getter != null) {
                            //it would add a duplicate entry
                            continue;
                        }
                    }
                    addDefinitionAutoCompleteActionScript(localDefinition, result);
                }
            }
        }
        currentNode = currentNode.getContainingScope();
    }
}
Also used : IScopedNode(org.apache.flex.compiler.tree.as.IScopedNode) IASScope(org.apache.flex.compiler.scopes.IASScope) IASScope(org.apache.flex.compiler.scopes.IASScope) ASScope(org.apache.flex.compiler.internal.scopes.ASScope) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) ISetterDefinition(org.apache.flex.compiler.definitions.ISetterDefinition) IGetterDefinition(org.apache.flex.compiler.definitions.IGetterDefinition) TypeScope(org.apache.flex.compiler.internal.scopes.TypeScope) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 2 with ISetterDefinition

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

IDefinition (org.apache.flex.compiler.definitions.IDefinition)2 IGetterDefinition (org.apache.flex.compiler.definitions.IGetterDefinition)2 ISetterDefinition (org.apache.flex.compiler.definitions.ISetterDefinition)2 ArrayList (java.util.ArrayList)1 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)1 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)1 IInterfaceDefinition (org.apache.flex.compiler.definitions.IInterfaceDefinition)1 INamespaceDefinition (org.apache.flex.compiler.definitions.INamespaceDefinition)1 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)1 IMetaTag (org.apache.flex.compiler.definitions.metadata.IMetaTag)1 ASScope (org.apache.flex.compiler.internal.scopes.ASScope)1 TypeScope (org.apache.flex.compiler.internal.scopes.TypeScope)1 IASScope (org.apache.flex.compiler.scopes.IASScope)1 IScopedNode (org.apache.flex.compiler.tree.as.IScopedNode)1