Search in sources :

Example 1 with IMXMLUnitData

use of org.apache.flex.compiler.mxml.IMXMLUnitData 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;
}
Also used : Path(java.nio.file.Path) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IMXMLDataManager(org.apache.flex.compiler.mxml.IMXMLDataManager) IMXMLUnitData(org.apache.flex.compiler.mxml.IMXMLUnitData) MXMLData(org.apache.flex.compiler.internal.mxml.MXMLData) StringReader(java.io.StringReader) IMXMLTextData(org.apache.flex.compiler.mxml.IMXMLTextData) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) IMXMLTagAttributeData(org.apache.flex.compiler.mxml.IMXMLTagAttributeData)

Aggregations

StringReader (java.io.StringReader)1 Path (java.nio.file.Path)1 MXMLData (org.apache.flex.compiler.internal.mxml.MXMLData)1 IMXMLDataManager (org.apache.flex.compiler.mxml.IMXMLDataManager)1 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)1 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)1 IMXMLTextData (org.apache.flex.compiler.mxml.IMXMLTextData)1 IMXMLUnitData (org.apache.flex.compiler.mxml.IMXMLUnitData)1 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)1