Search in sources :

Example 1 with ElementDescriptor

use of org.kie.workbench.common.services.datamodeller.parser.descr.ElementDescriptor in project kie-wb-common by kiegroup.

the class ParserUtil method populateUnManagedElements.

public static void populateUnManagedElements(int startIndex, int endIndex, ElementDescriptor element) {
    String text;
    TextTokenElementDescr unmanagedToken;
    if (element.getElements().size() > 0) {
        List<ElementDescriptor> originalElements = new ArrayList<ElementDescriptor>();
        originalElements.addAll(element.getElements());
        for (ElementDescriptor child : originalElements) {
            if (startIndex < child.getStart()) {
                unmanagedToken = new TextTokenElementDescr();
                unmanagedToken.setStart(startIndex);
                unmanagedToken.setStop(child.getStart() - 1);
                unmanagedToken.setSourceBuffer(child.getSourceBuffer());
                text = unmanagedToken.getSourceBuffer().substring(unmanagedToken.getStart(), unmanagedToken.getStop() + 1);
                unmanagedToken.setText(text);
                element.getElements().addMemberBefore(child, unmanagedToken);
            }
            startIndex = child.getStop() + 1;
            populateUnManagedElements(child);
        }
        if (startIndex < element.getStop()) {
            unmanagedToken = new TextTokenElementDescr();
            unmanagedToken.setStart(startIndex);
            unmanagedToken.setStop(element.getStop());
            unmanagedToken.setSourceBuffer(element.getSourceBuffer());
            text = unmanagedToken.getSourceBuffer().substring(unmanagedToken.getStart(), unmanagedToken.getStop() + 1);
            unmanagedToken.setText(text);
            element.getElements().add(unmanagedToken);
        }
        if (endIndex > 0 && endIndex > element.getStop() && endIndex < element.getSourceBuffer().length()) {
            unmanagedToken = new TextTokenElementDescr();
            unmanagedToken.setStart(element.getStop() + 1);
            unmanagedToken.setStop(endIndex);
            unmanagedToken.setSourceBuffer(element.getSourceBuffer());
            text = unmanagedToken.getSourceBuffer().substring(unmanagedToken.getStart(), unmanagedToken.getStop() + 1);
            unmanagedToken.setText(text);
            element.getElements().add(unmanagedToken);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ElementDescriptor(org.kie.workbench.common.services.datamodeller.parser.descr.ElementDescriptor) TextTokenElementDescr(org.kie.workbench.common.services.datamodeller.parser.descr.TextTokenElementDescr)

Aggregations

ArrayList (java.util.ArrayList)1 ElementDescriptor (org.kie.workbench.common.services.datamodeller.parser.descr.ElementDescriptor)1 TextTokenElementDescr (org.kie.workbench.common.services.datamodeller.parser.descr.TextTokenElementDescr)1