mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[textRegionAccess] introducing ISemanticRegion.getEObjectRegion()
Signed-off-by: Moritz Eysholdt <moritz.eysholdt@typefox.io>
This commit is contained in:
parent
8fd3b45a4a
commit
6a810ea3e7
5 changed files with 26 additions and 11 deletions
|
@ -18,14 +18,13 @@ import org.eclipse.xtext.RuleCall;
|
|||
public interface IAstRegion {
|
||||
|
||||
/**
|
||||
* @return The grammar element used to parse this semantic region. Can be an {@link RuleCall},
|
||||
* {@link CrossReference}, or {@link Keyword}.
|
||||
* @return The grammar element used to parse this semantic region. Can be an {@link RuleCall}, {@link CrossReference}, or
|
||||
* {@link Keyword}.
|
||||
*/
|
||||
EObject getGrammarElement();
|
||||
|
||||
/**
|
||||
* The EObject this semantic region belongs to.
|
||||
* The AST-Element represented by this IEObjectRegion.
|
||||
*/
|
||||
EObject getSemanticElement();
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
package org.eclipse.xtext.formatting2.regionaccess;
|
||||
|
||||
import org.eclipse.emf.ecore.EAttribute;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.CrossReference;
|
||||
import org.eclipse.xtext.Keyword;
|
||||
|
||||
|
@ -23,4 +24,8 @@ import org.eclipse.xtext.Keyword;
|
|||
*/
|
||||
public interface ISemanticRegion extends ISequentialRegion, IAstRegion {
|
||||
|
||||
/**
|
||||
* Same as calling {@link ITextRegionAccess#regionForEObject(EObject)} for {@link #getSemanticElement()}, but faster.
|
||||
*/
|
||||
IEObjectRegion getEObjectRegion();
|
||||
}
|
|
@ -10,6 +10,7 @@ package org.eclipse.xtext.formatting2.regionaccess.internal;
|
|||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.AbstractElement;
|
||||
import org.eclipse.xtext.CrossReference;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionFinder;
|
||||
|
@ -28,6 +29,11 @@ public class NodeSemanticRegion extends NodeRegion implements ISemanticRegion {
|
|||
super(access, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEObjectRegion getEObjectRegion() {
|
||||
return eObjectTokens;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractElement getGrammarElement() {
|
||||
EObject element = super.getGrammarElement();
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.eclipse.xtext.formatting2.regionaccess.internal;
|
|||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.AbstractElement;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionFinder;
|
||||
|
@ -18,18 +19,23 @@ import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionFinder;
|
|||
*/
|
||||
public class StringSemanticRegion extends StringRegion implements ISemanticRegion {
|
||||
|
||||
private final AbstractEObjectRegion eObjectRegion;
|
||||
private final AbstractElement grammarElement;
|
||||
private IHiddenRegion leading;
|
||||
private final EObject semanticElement;
|
||||
private IHiddenRegion trailing;
|
||||
|
||||
protected StringSemanticRegion(StringBasedRegionAccess regionAccess, EObject semanticElement,
|
||||
protected StringSemanticRegion(StringBasedRegionAccess regionAccess, AbstractEObjectRegion semanticElement,
|
||||
AbstractElement grammarElement, int offset, int length) {
|
||||
super(regionAccess, offset, length);
|
||||
this.semanticElement = semanticElement;
|
||||
this.eObjectRegion = semanticElement;
|
||||
this.grammarElement = grammarElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEObjectRegion getEObjectRegion() {
|
||||
return eObjectRegion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractElement getGrammarElement() {
|
||||
return grammarElement;
|
||||
|
@ -57,7 +63,7 @@ public class StringSemanticRegion extends StringRegion implements ISemanticRegio
|
|||
|
||||
@Override
|
||||
public EObject getSemanticElement() {
|
||||
return semanticElement;
|
||||
return eObjectRegion.getSemanticElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -113,9 +113,8 @@ public class TextRegionAccessBuildingSequencer implements ISequenceAcceptor {
|
|||
if (token == null || token.length() == 0)
|
||||
return;
|
||||
AbstractEObjectRegion tokens = stack.peek();
|
||||
EObject obj = tokens == null ? null : tokens.getSemanticElement();
|
||||
int offset = regionAccess.append(token);
|
||||
StringSemanticRegion semantic = createSemanticRegion(element, token, obj, offset);
|
||||
StringSemanticRegion semantic = createSemanticRegion(element, token, tokens, offset);
|
||||
last.setNext(semantic);
|
||||
semantic.setLeadingHiddenRegion(last);
|
||||
last = createHiddenRegion();
|
||||
|
@ -135,7 +134,7 @@ public class TextRegionAccessBuildingSequencer implements ISequenceAcceptor {
|
|||
return new StringHiddenRegion(regionAccess);
|
||||
}
|
||||
|
||||
protected StringSemanticRegion createSemanticRegion(AbstractElement element, String token, EObject obj, int offset) {
|
||||
protected StringSemanticRegion createSemanticRegion(AbstractElement element, String token, AbstractEObjectRegion obj, int offset) {
|
||||
return new StringSemanticRegion(regionAccess, obj, element, offset, token.length());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue