Search in sources :

Example 6 with IMXMLTagData

use of org.apache.flex.compiler.mxml.IMXMLTagData 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 7 with IMXMLTagData

use of org.apache.flex.compiler.mxml.IMXMLTagData in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method definition.

/**
     * Finds where the definition referenced at the current position in a text
     * document is defined.
     */
@Override
public CompletableFuture<List<? extends Location>> definition(TextDocumentPositionParams position) {
    String textDocumentUri = position.getTextDocument().getUri();
    if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    IMXMLTagData offsetTag = getOffsetMXMLTag(position);
    if (offsetTag != null) {
        IASNode embeddedNode = getEmbeddedActionScriptNodeInMXMLTag(offsetTag, currentOffset, position);
        if (embeddedNode != null) {
            return actionScriptDefinitionWithNode(position, embeddedNode);
        }
        //so that's why we call isMXMLTagValidForCompletion()
        if (isMXMLTagValidForCompletion(offsetTag)) {
            return mxmlDefinition(position, offsetTag);
        }
    }
    return actionScriptDefinition(position);
}
Also used : IASNode(org.apache.flex.compiler.tree.as.IASNode) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData)

Example 8 with IMXMLTagData

use of org.apache.flex.compiler.mxml.IMXMLTagData in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method referencesForDefinition.

private void referencesForDefinition(IDefinition definition, List<Location> result) {
    for (ICompilationUnit compilationUnit : compilationUnits) {
        if (compilationUnit == null || compilationUnit instanceof SWCCompilationUnit) {
            continue;
        }
        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) {
                    Location location = LanguageServerUtils.getLocationFromSourceLocation(otherUnit);
                    if (location == null) {
                        continue;
                    }
                    result.add(location);
                }
            }
        }
        IASNode ast;
        try {
            ast = compilationUnit.getSyntaxTreeRequest().get().getAST();
        } catch (Exception e) {
            continue;
        }
        ArrayList<IIdentifierNode> identifiers = new ArrayList<>();
        findIdentifiers(ast, definition, identifiers);
        for (IIdentifierNode otherNode : identifiers) {
            Location location = LanguageServerUtils.getLocationFromSourceLocation(otherNode);
            if (location == null) {
                continue;
            }
            result.add(location);
        }
    }
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) MXMLData(org.apache.flex.compiler.internal.mxml.MXMLData) ArrayList(java.util.ArrayList) IIdentifierNode(org.apache.flex.compiler.tree.as.IIdentifierNode) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IMXMLDataManager(org.apache.flex.compiler.mxml.IMXMLDataManager) IASNode(org.apache.flex.compiler.tree.as.IASNode) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation) Location(org.eclipse.lsp4j.Location) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation)

Example 9 with IMXMLTagData

use of org.apache.flex.compiler.mxml.IMXMLTagData 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 10 with IMXMLTagData

use of org.apache.flex.compiler.mxml.IMXMLTagData in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method rename.

/**
     * Renames a symbol at the specified document position.
     */
@Override
public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
    String textDocumentUri = params.getTextDocument().getUri();
    if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
        return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
    }
    IMXMLTagData offsetTag = getOffsetMXMLTag(params.getTextDocument(), params.getPosition());
    if (offsetTag != null) {
        IASNode embeddedNode = getEmbeddedActionScriptNodeInMXMLTag(offsetTag, currentOffset, params.getTextDocument(), params.getPosition());
        if (embeddedNode != null) {
            return actionScriptRenameWithNode(params, embeddedNode);
        }
        //so that's why we call isMXMLTagValidForCompletion()
        if (isMXMLTagValidForCompletion(offsetTag)) {
            return mxmlRename(params, offsetTag);
        }
    }
    return actionScriptRename(params);
}
Also used : HashMap(java.util.HashMap) IASNode(org.apache.flex.compiler.tree.as.IASNode) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData)

Aggregations

IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)12 IASNode (org.apache.flex.compiler.tree.as.IASNode)8 IDefinition (org.apache.flex.compiler.definitions.IDefinition)5 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)4 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)4 ArrayList (java.util.ArrayList)3 MXMLData (org.apache.flex.compiler.internal.mxml.MXMLData)3 IMXMLDataManager (org.apache.flex.compiler.mxml.IMXMLDataManager)3 IIdentifierNode (org.apache.flex.compiler.tree.as.IIdentifierNode)3 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)3 CompletionList (org.eclipse.lsp4j.CompletionList)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ConcurrentModificationException (java.util.ConcurrentModificationException)2 HashMap (java.util.HashMap)2 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)2 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)2 SWCCompilationUnit (org.apache.flex.compiler.internal.units.SWCCompilationUnit)2 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)2 StringReader (java.io.StringReader)1