Search in sources :

Example 21 with IDefinition

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

the class ActionScriptTextDocumentService method findMXMLUnits.

private void findMXMLUnits(IMXMLTagData tagData, IDefinition definition, List<ISourceLocation> result) {
    IDefinition tagDefinition = currentProject.resolveXMLNameToDefinition(tagData.getXMLName(), tagData.getMXMLDialect());
    if (tagDefinition != null && definition == tagDefinition) {
        result.add(tagData);
    }
    if (tagDefinition instanceof IClassDefinition) {
        IClassDefinition classDefinition = (IClassDefinition) tagDefinition;
        IMXMLTagAttributeData[] attributes = tagData.getAttributeDatas();
        for (IMXMLTagAttributeData attributeData : attributes) {
            IDefinition attributeDefinition = currentProject.resolveSpecifier(classDefinition, attributeData.getShortName());
            if (attributeDefinition != null && definition == attributeDefinition) {
                result.add(attributeData);
            }
        }
    }
    IMXMLTagData childTag = tagData.getFirstChild(true);
    while (childTag != null) {
        if (childTag.isCloseTag()) {
            //only open tags matter
            continue;
        }
        findMXMLUnits(childTag, definition, result);
        childTag = childTag.getNextSibling(true);
    }
}
Also used : IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IMXMLTagAttributeData(org.apache.flex.compiler.mxml.IMXMLTagAttributeData)

Example 22 with IDefinition

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

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

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

the class ActionScriptTextDocumentService method mxmlAttributeCompletion.

private CompletableFuture<CompletionList> mxmlAttributeCompletion(IMXMLTagData offsetTag, CompletionList result) {
    List<CompletionItem> items = result.getItems();
    IDefinition attributeDefinition = getDefinitionForMXMLTagAttribute(offsetTag, currentOffset, true);
    if (attributeDefinition instanceof IVariableDefinition) {
        IVariableDefinition variableDefinition = (IVariableDefinition) attributeDefinition;
        if (variableDefinition.getTypeAsDisplayString().equals(IASLanguageConstants.Boolean)) {
            CompletionItem falseItem = new CompletionItem();
            falseItem.setKind(CompletionItemKind.Value);
            falseItem.setLabel(IASLanguageConstants.FALSE);
            items.add(falseItem);
            CompletionItem trueItem = new CompletionItem();
            trueItem.setKind(CompletionItemKind.Value);
            trueItem.setLabel(IASLanguageConstants.TRUE);
            items.add(trueItem);
            return CompletableFuture.completedFuture(result);
        }
    }
    return CompletableFuture.completedFuture(result);
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 25 with IDefinition

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

the class ActionScriptTextDocumentService method classDefinitionToConstructor.

private IFunctionDefinition classDefinitionToConstructor(IClassDefinition definition) {
    IASScope scope = definition.getContainedScope();
    Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
    for (IDefinition localDefinition : definitions) {
        if (localDefinition instanceof IFunctionDefinition) {
            IFunctionDefinition functionDefinition = (IFunctionDefinition) localDefinition;
            if (functionDefinition.isConstructor()) {
                return functionDefinition;
            }
        }
    }
    return null;
}
Also used : IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IASScope(org.apache.flex.compiler.scopes.IASScope) 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