use of org.apache.flex.compiler.common.ISourceLocation 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;
}
use of org.apache.flex.compiler.common.ISourceLocation 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);
}
}
}
use of org.apache.flex.compiler.common.ISourceLocation in project vscode-nextgenas by BowlerHatLLC.
the class LanguageServerUtils method getLocationFromSourceLocation.
/**
* Converts a compiler source location to a language server location. May
* return null if the line or column of the source location is -1.
*/
public static Location getLocationFromSourceLocation(ISourceLocation sourceLocation) {
Path sourceLocationPath = Paths.get(sourceLocation.getSourcePath());
Location location = new Location();
location.setUri(sourceLocationPath.toUri().toString());
Range range = getRangeFromSourceLocation(sourceLocation);
if (range == null) {
//this is probably generated by the compiler somehow
return null;
}
location.setRange(range);
return location;
}
Aggregations