use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class IdeContentProposalProvider method _createProposals.
protected void _createProposals(final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
final AbstractElement terminal = assignment.getTerminal();
if ((terminal instanceof CrossReference)) {
this.createProposals(terminal, context, acceptor);
} else {
if ((terminal instanceof RuleCall)) {
final AbstractRule rule = ((RuleCall) terminal).getRule();
if (((rule instanceof TerminalRule) && context.getPrefix().isEmpty())) {
String _xifexpression = null;
String _name = rule.getName();
boolean _equals = Objects.equal(_name, "STRING");
if (_equals) {
String _feature = assignment.getFeature();
String _plus = ("\"" + _feature);
_xifexpression = (_plus + "\"");
} else {
_xifexpression = assignment.getFeature();
}
final String proposal = _xifexpression;
final Procedure1<ContentAssistEntry> _function = (ContentAssistEntry it) -> {
String _name_1 = rule.getName();
boolean _equals_1 = Objects.equal(_name_1, "STRING");
if (_equals_1) {
ArrayList<TextRegion> _editPositions = it.getEditPositions();
int _offset = context.getOffset();
int _plus_1 = (_offset + 1);
int _length = proposal.length();
int _minus = (_length - 2);
TextRegion _textRegion = new TextRegion(_plus_1, _minus);
_editPositions.add(_textRegion);
it.setKind(ContentAssistEntry.KIND_TEXT);
} else {
ArrayList<TextRegion> _editPositions_1 = it.getEditPositions();
int _offset_1 = context.getOffset();
int _length_1 = proposal.length();
TextRegion _textRegion_1 = new TextRegion(_offset_1, _length_1);
_editPositions_1.add(_textRegion_1);
it.setKind(ContentAssistEntry.KIND_VALUE);
}
it.setDescription(rule.getName());
};
final ContentAssistEntry entry = this.proposalCreator.createProposal(proposal, context, _function);
acceptor.accept(entry, this.proposalPriorities.getDefaultPriority(entry));
}
}
}
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class BaseContentAssistParser method getEntryGrammarElement.
protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) {
EObject grammarElement = entryPoint.getGrammarElement();
if (grammarElement instanceof RuleCall) {
AbstractRule rule = ((RuleCall) grammarElement).getRule();
if (rule instanceof ParserRule) {
if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) {
grammarElement = rule.getAlternatives();
}
}
} else if (grammarElement instanceof ParserRule) {
grammarElement = ((ParserRule) grammarElement).getAlternatives();
} else if (grammarElement instanceof CrossReference) {
grammarElement = GrammarUtil.containingAssignment(grammarElement);
}
AbstractElement result = (AbstractElement) grammarElement;
if (result instanceof Action) {
return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild());
}
return result;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class SemanticSequencerNfaProvider method isContentValidationNeeded.
protected boolean isContentValidationNeeded(Collection<AbstractElement> ass) {
if (ass == null || ass.size() < 2)
return false;
Iterator<AbstractElement> it = ass.iterator();
AbstractElement first = it.next();
CrossReference firstRef = GrammarUtil.containingCrossReference(first);
while (it.hasNext()) {
AbstractElement next = it.next();
if (next instanceof Action)
return true;
if (!EcoreUtil.equals(first, next))
return true;
if (firstRef != null) {
CrossReference nextRef = GrammarUtil.containingCrossReference(next);
if (nextRef != null && nextRef.getType().getClassifier() != firstRef.getType().getClassifier())
return true;
}
}
return false;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class HiddenTokenSequencer method getHiddenNodesBetween.
/**
* @return null if the whitespace between these nodes is unknown.
* In this case, the formatter needs to decide.
*/
protected List<INode> getHiddenNodesBetween(INode from, INode to) {
if (from == null && to == null)
return null;
List<INode> out = Lists.newArrayList();
Set<EObject> deletedSemanticElements = Sets.newHashSet();
if (to == null) {
NodeIterator ni = new NodeIterator(from);
while (ni.hasNext()) {
INode next = ni.next();
if (next.getTotalOffset() > rootEndOffset) {
break;
}
if (next == lastEmittedNode) {
break;
} else if (tokenUtil.isWhitespaceOrCommentNode(next)) {
out.add(next);
} else if (belongsToDeletedElement(next)) {
handleDeletedElement(out, deletedSemanticElements, next);
ni.prune();
} else {
break;
}
}
} else if (from == null) {
NodeIterator ni = new NodeIterator(to);
while (ni.hasPrevious()) {
INode prev = ni.previous();
if (prev.getTotalEndOffset() < rootOffset) {
break;
}
if (prev == lastEmittedNode) {
break;
} else if (tokenUtil.isWhitespaceOrCommentNode(prev)) {
out.add(0, prev);
} else if (belongsToDeletedElement(prev)) {
handleDeletedElement(out, deletedSemanticElements, prev);
ni.prune();
} else {
break;
}
}
} else {
NodeIterator ni = new NodeIterator(from);
while (ni.hasNext()) {
INode next = ni.next();
if (tokenUtil.isWhitespaceOrCommentNode(next)) {
out.add(next);
} else if (next.equals(to)) {
if (next instanceof ICompositeNode && (GrammarUtil.isDatatypeRuleCall(next.getGrammarElement()) || GrammarUtil.isEnumRuleCall(next.getGrammarElement()) || next.getGrammarElement() instanceof CrossReference)) {
while (ni.hasNext()) {
INode next2 = ni.next();
if (tokenUtil.isWhitespaceOrCommentNode(next2)) {
out.add(next2);
} else if (next2 instanceof ILeafNode) {
break;
}
}
break;
} else {
break;
}
} else if (belongsToDeletedElement(next)) {
handleDeletedElement(out, deletedSemanticElements, next);
ni.prune();
} else if (tokenUtil.isToken(next)) {
break;
}
}
}
if ((from == null || to == null) && out.isEmpty()) {
return null;
} else {
return filterNodesOfDeletedElements(out, deletedSemanticElements);
}
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class AbstractElementFinder method findCrossReferences.
public List<CrossReference> findCrossReferences(EClassifier... targetEClassifiers) {
Set<EClassifier> classifiers = new HashSet<EClassifier>(Arrays.asList(targetEClassifiers));
Collection<EClass> classes = Lists.newArrayList(Iterables.filter(classifiers, EClass.class));
ArrayList<CrossReference> r = new ArrayList<CrossReference>();
for (AbstractRule ar : getRules()) {
TreeIterator<EObject> i = ar.eAllContents();
while (i.hasNext()) {
EObject o = i.next();
if (o instanceof CrossReference) {
CrossReference c = (CrossReference) o;
if (classifiers.contains(c.getType().getClassifier()))
r.add(c);
else if (c.getType().getClassifier() instanceof EClass)
for (EClass cls : classes) if (EcoreUtil2.isAssignableFrom(cls, (EClass) c.getType().getClassifier())) {
r.add(c);
break;
}
i.prune();
}
}
}
return r;
}
Aggregations