use of org.apache.flex.compiler.mxml.IMXMLTextData in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method getOffsetMXMLTag.
private IMXMLTagData getOffsetMXMLTag(TextDocumentIdentifier textDocument, Position position) {
namespaceStartIndex = -1;
namespaceEndIndex = -1;
String uri = textDocument.getUri();
if (!uri.endsWith(MXML_EXTENSION)) {
// don't try to parse ActionScript files as MXML
return null;
}
currentOffset = -1;
importStartIndex = -1;
importEndIndex = -1;
Path path = LanguageServerUtils.getPathFromLanguageServerURI(uri);
if (path == null) {
return null;
}
if (!isInWorkspaceOrSourcePath(path)) {
//the path must be in the workspace or source-path
return null;
}
String code;
if (sourceByPath.containsKey(path)) {
code = sourceByPath.get(path);
} else {
System.err.println("Could not find source " + path.toAbsolutePath().toString());
System.err.println(sourceByPath.keySet().size());
return null;
}
//need to ensure that the compilation unit exists, even though we don't
//use it directly
ICompilationUnit unit = getCompilationUnit(path);
if (unit == null) {
//should have been logged already
return null;
}
IMXMLDataManager mxmlDataManager = currentWorkspace.getMXMLDataManager();
MXMLData mxmlData = (MXMLData) mxmlDataManager.get(fileSpecGetter.getFileSpecification(path.toAbsolutePath().toString()));
if (mxmlData == null) {
return null;
}
currentOffset = lineAndCharacterToOffset(new StringReader(code), position.getLine(), position.getCharacter());
if (currentOffset == -1) {
System.err.println("Could not find code at position " + position.getLine() + ":" + position.getCharacter() + " in file " + path.toAbsolutePath().toString());
return null;
}
//calculate the location for automatically generated xmlns tags
IMXMLTagData rootTag = mxmlData.getRootTag();
IMXMLTagAttributeData[] attributeDatas = rootTag.getAttributeDatas();
for (IMXMLTagAttributeData attributeData : attributeDatas) {
if (!attributeData.getName().startsWith("xmlns")) {
if (namespaceStartIndex == -1) {
namespaceStartIndex = attributeData.getStart();
namespaceEndIndex = namespaceStartIndex;
}
break;
}
int start = attributeData.getAbsoluteStart();
int end = attributeData.getValueEnd() + 1;
if (brokenMXMLValueEnd) {
end--;
}
if (namespaceStartIndex == -1 || namespaceStartIndex > start) {
namespaceStartIndex = start;
}
if (namespaceEndIndex == -1 || namespaceEndIndex < end) {
namespaceEndIndex = end;
}
}
IMXMLUnitData unitData = mxmlData.findContainmentReferenceUnit(currentOffset);
IMXMLUnitData currentUnitData = unitData;
while (currentUnitData != null) {
if (currentUnitData instanceof IMXMLTagData) {
IMXMLTagData tagData = (IMXMLTagData) currentUnitData;
if (tagData.getXMLName().equals(tagData.getMXMLDialect().resolveScript()) && unitData instanceof IMXMLTextData) {
IMXMLTextData textUnitData = (IMXMLTextData) unitData;
if (textUnitData.getTextType() == IMXMLTextData.TextType.CDATA) {
importStartIndex = textUnitData.getCompilableTextStart();
importEndIndex = textUnitData.getCompilableTextEnd();
}
}
return tagData;
}
currentUnitData = currentUnitData.getParentUnitData();
}
return null;
}
Aggregations