Search in sources :

Example 1 with IPackageDefinition

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

the class ActionScriptTextDocumentService method querySymbolsInScope.

private void querySymbolsInScope(String query, IASScope scope, List<SymbolInformation> result) {
    String lowerCaseQuery = query.toLowerCase();
    Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
    for (IDefinition definition : definitions) {
        if (definition instanceof IPackageDefinition) {
            IPackageDefinition packageDefinition = (IPackageDefinition) definition;
            IASScope packageScope = packageDefinition.getContainedScope();
            querySymbolsInScope(query, packageScope, result);
        } else if (definition instanceof ITypeDefinition) {
            ITypeDefinition typeDefinition = (ITypeDefinition) definition;
            if (!definition.isImplicit() && typeDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
                SymbolInformation symbol = definitionToSymbol(typeDefinition);
                result.add(symbol);
            }
            IASScope typeScope = typeDefinition.getContainedScope();
            querySymbolsInScope(query, typeScope, result);
        } else if (definition instanceof IFunctionDefinition) {
            if (definition.isImplicit()) {
                continue;
            }
            IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
            if (functionDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
                SymbolInformation symbol = definitionToSymbol(functionDefinition);
                result.add(symbol);
            }
            IASScope functionScope = functionDefinition.getContainedScope();
            querySymbolsInScope(query, functionScope, result);
        } else if (definition instanceof IVariableDefinition) {
            if (definition.isImplicit()) {
                continue;
            }
            IVariableDefinition variableDefinition = (IVariableDefinition) definition;
            if (variableDefinition.getQualifiedName().toLowerCase().contains(lowerCaseQuery)) {
                SymbolInformation symbol = definitionToSymbol(variableDefinition);
                result.add(symbol);
            }
        }
    }
}
Also used : IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IASScope(org.apache.flex.compiler.scopes.IASScope) IPackageDefinition(org.apache.flex.compiler.definitions.IPackageDefinition) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 2 with IPackageDefinition

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

the class ActionScriptTextDocumentService method renameDefinition.

private WorkspaceEdit renameDefinition(IDefinition definition, String newName) {
    if (definition == null) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename this element.");
            languageClient.showMessage(message);
        }
        return new WorkspaceEdit(new HashMap<>());
    }
    WorkspaceEdit result = new WorkspaceEdit();
    Map<String, List<TextEdit>> changes = new HashMap<>();
    result.setChanges(changes);
    if (definition.getContainingFilePath().endsWith(SWC_EXTENSION)) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename an element defined in a SWC file.");
            languageClient.showMessage(message);
        }
        return result;
    }
    if (definition instanceof IPackageDefinition) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename a package.");
            languageClient.showMessage(message);
        }
        return result;
    }
    IDefinition parentDefinition = definition.getParent();
    if (parentDefinition != null && parentDefinition instanceof IPackageDefinition) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename this element.");
            languageClient.showMessage(message);
        }
        return result;
    }
    for (ICompilationUnit compilationUnit : compilationUnits) {
        if (compilationUnit == null || compilationUnit instanceof SWCCompilationUnit) {
            continue;
        }
        ArrayList<TextEdit> textEdits = new ArrayList<>();
        if (compilationUnit.getAbsoluteFilename().endsWith(MXML_EXTENSION)) {
            IMXMLDataManager mxmlDataManager = currentWorkspace.getMXMLDataManager();
            MXMLData mxmlData = (MXMLData) mxmlDataManager.get(fileSpecGetter.getFileSpecification(compilationUnit.getAbsoluteFilename()));
            IMXMLTagData rootTag = mxmlData.getRootTag();
            if (rootTag != null) {
                ArrayList<ISourceLocation> units = new ArrayList<>();
                findMXMLUnits(mxmlData.getRootTag(), definition, units);
                for (ISourceLocation otherUnit : units) {
                    TextEdit textEdit = new TextEdit();
                    textEdit.setNewText(newName);
                    Range range = LanguageServerUtils.getRangeFromSourceLocation(otherUnit);
                    if (range == null) {
                        continue;
                    }
                    textEdit.setRange(range);
                    textEdits.add(textEdit);
                }
            }
        }
        IASNode ast = null;
        try {
            ast = compilationUnit.getSyntaxTreeRequest().get().getAST();
        } catch (Exception e) {
        //safe to ignore
        }
        if (ast != null) {
            ArrayList<IIdentifierNode> identifiers = new ArrayList<>();
            findIdentifiers(ast, definition, identifiers);
            for (IIdentifierNode identifierNode : identifiers) {
                TextEdit textEdit = new TextEdit();
                textEdit.setNewText(newName);
                Range range = LanguageServerUtils.getRangeFromSourceLocation(identifierNode);
                if (range == null) {
                    continue;
                }
                textEdit.setRange(range);
                textEdits.add(textEdit);
            }
        }
        if (textEdits.size() == 0) {
            continue;
        }
        URI uri = Paths.get(compilationUnit.getAbsoluteFilename()).toUri();
        changes.put(uri.toString(), textEdits);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) IPackageDefinition(org.apache.flex.compiler.definitions.IPackageDefinition) MXMLData(org.apache.flex.compiler.internal.mxml.MXMLData) ArrayList(java.util.ArrayList) URI(java.net.URI) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IASNode(org.apache.flex.compiler.tree.as.IASNode) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) MessageParams(org.eclipse.lsp4j.MessageParams) IIdentifierNode(org.apache.flex.compiler.tree.as.IIdentifierNode) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Range(org.eclipse.lsp4j.Range) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) IDefinition(org.apache.flex.compiler.definitions.IDefinition) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IMXMLDataManager(org.apache.flex.compiler.mxml.IMXMLDataManager) TextEdit(org.eclipse.lsp4j.TextEdit) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation)

Example 3 with IPackageDefinition

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

the class ActionScriptTextDocumentService method scopeToSymbols.

private void scopeToSymbols(IASScope scope, List<SymbolInformation> result) {
    Collection<IDefinition> definitions = scope.getAllLocalDefinitions();
    for (IDefinition definition : definitions) {
        if (definition instanceof IPackageDefinition) {
            IPackageDefinition packageDefinition = (IPackageDefinition) definition;
            IASScope packageScope = packageDefinition.getContainedScope();
            scopeToSymbols(packageScope, result);
        } else if (definition instanceof ITypeDefinition) {
            ITypeDefinition typeDefinition = (ITypeDefinition) definition;
            if (!definition.isImplicit()) {
                SymbolInformation typeSymbol = definitionToSymbol(typeDefinition);
                result.add(typeSymbol);
            }
            IASScope typeScope = typeDefinition.getContainedScope();
            scopeToSymbols(typeScope, result);
        } else if (definition instanceof IFunctionDefinition || definition instanceof IVariableDefinition) {
            if (definition.isImplicit()) {
                continue;
            }
            SymbolInformation localSymbol = definitionToSymbol(definition);
            result.add(localSymbol);
        }
    }
}
Also used : IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) IASScope(org.apache.flex.compiler.scopes.IASScope) IPackageDefinition(org.apache.flex.compiler.definitions.IPackageDefinition) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) IVariableDefinition(org.apache.flex.compiler.definitions.IVariableDefinition) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Aggregations

IDefinition (org.apache.flex.compiler.definitions.IDefinition)3 IPackageDefinition (org.apache.flex.compiler.definitions.IPackageDefinition)3 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)2 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)2 IVariableDefinition (org.apache.flex.compiler.definitions.IVariableDefinition)2 IASScope (org.apache.flex.compiler.scopes.IASScope)2 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)1 MXMLData (org.apache.flex.compiler.internal.mxml.MXMLData)1 SWCCompilationUnit (org.apache.flex.compiler.internal.units.SWCCompilationUnit)1 IMXMLDataManager (org.apache.flex.compiler.mxml.IMXMLDataManager)1 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)1 IASNode (org.apache.flex.compiler.tree.as.IASNode)1