blob: 32db63f6ab6057909da58c3a13857d1a98746461 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.dsl.dto.xtext.ui;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.nodemodel.BidiTreeIterator;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.osbp.dsl.dto.xtext.ui.DtoHighlightingConfiguration;
import org.eclipse.osbp.dsl.semantic.dto.LDtoFeature;
import org.eclipse.osbp.dsl.semantic.dto.LDtoMapper;
public class DtoGrammarHighlightingCalculator implements
ISemanticHighlightingCalculator {
@Override
public void provideHighlightingFor(XtextResource resource,
IHighlightedPositionAcceptor acceptor) {
if (resource == null || resource.getParseResult() == null)
return;
INode root = resource.getParseResult().getRootNode();
BidiTreeIterator<INode> it = root.getAsTreeIterable().iterator();
while (it.hasNext()) {
INode node = it.next();
String text = node.getText();
EObject semanticElement = node.getSemanticElement();
if (semanticElement instanceof LDtoFeature) {
if ("id".equals(text) || "transient".equals(text)
|| "version".equals(text)) {
if (node.getNextSibling() == null) {
if (!"transient".equals(text)) {
acceptor.addPosition(node.getOffset(),
node.getLength(),
DtoHighlightingConfiguration.DEFAULT_ID);
}
} else {
acceptor.addPosition(node.getOffset(),
node.getLength(),
DtoHighlightingConfiguration.MODIFIER_ID);
}
}
} else if (semanticElement instanceof LDtoMapper) {
if ("toDTO".equals(text) || "fromDTO".equals(text)) {
acceptor.addPosition(node.getOffset(), node.getLength(),
DtoHighlightingConfiguration.MODIFIER_ID);
}
}
}
}
}