use of org.eclipse.xtext.util.TextRegion in project xtext-xtend by eclipse.
the class CompilerTraceTest method tracesTo.
public void tracesTo(final CharSequence xtend, final CharSequence java) {
try {
final String xtendWithSpaces = ((" " + xtend) + " ");
final Matcher xtendMatcher = this.p.matcher(xtendWithSpaces);
Assert.assertTrue("xtendMatcher.matches", xtendMatcher.matches());
final String xtendGroup1 = xtendMatcher.group(1);
final String xtendGroup2 = xtendMatcher.group(2);
final String xtendGroup3 = xtendMatcher.group(3);
final String actualXtendCode = ((xtendGroup1 + xtendGroup2) + xtendGroup3);
final XtendFile file = this.file(actualXtendCode, true);
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
final JvmGenericType inferredType = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
CharSequence compiledCode = this.generator.generateType(inferredType, this.generatorConfigProvider.get(inferredType));
compiledCode = this.postProcessor.postProcess(null, compiledCode);
final Matcher javaMatcher = this.p.matcher(java.toString());
Assert.assertTrue("javaMatcher.matches", javaMatcher.matches());
final String javaGroup1 = javaMatcher.group(1);
final String javaGroup2 = javaMatcher.group(2);
final String javaGroup3 = javaMatcher.group(3);
final String actualJavaExpectation = ((javaGroup1 + javaGroup2) + javaGroup3);
Assert.assertEquals(actualJavaExpectation, compiledCode.toString());
AbstractTraceRegion _traceRegion = ((ITraceRegionProvider) compiledCode).getTraceRegion();
URI _createURI = URI.createURI(file.eResource().getURI().path());
SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI(_createURI);
URI _createURI_1 = URI.createURI(file.eResource().getURI().path());
SourceRelativeURI _sourceRelativeURI_1 = new SourceRelativeURI(_createURI_1);
AbstractTraceRegion _merge = this.merge(_traceRegion.invertFor(_sourceRelativeURI, _sourceRelativeURI_1));
final SimpleTrace trace = new SimpleTrace(_merge);
int _length = xtendGroup1.length();
int _length_1 = xtendGroup2.length();
TextRegion _textRegion = new TextRegion(_length, _length_1);
final Iterable<? extends ILocationInResource> locations = trace.getAllAssociatedLocations(_textRegion);
int _length_2 = javaGroup1.length();
int _length_3 = javaGroup2.length();
final TextRegion expectedRegion = new TextRegion(_length_2, _length_3);
Assert.assertFalse(IterableExtensions.isEmpty(locations));
for (final ILocationInResource location : locations) {
ITextRegionWithLineInformation _textRegion_1 = location.getTextRegion();
boolean _equals = Objects.equal(_textRegion_1, expectedRegion);
if (_equals) {
return;
}
}
Assert.fail(((("locations did not match expectation: " + locations) + " / ") + expectedRegion));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.util.TextRegion in project xtext-xtend by eclipse.
the class PartialParserBenchmark method doTime.
public int doTime(IParser parser, int windowSize) {
int result = 0;
for (int j = 0; j < contentToParse.length() - windowSize; j++) {
ReplaceRegion replaceRegion = new ReplaceRegion(new TextRegion(j, windowSize), contentToParse.substring(j, j + windowSize));
IParseResult newParseResult = parser.reparse(parseResult, replaceRegion);
if (newParseResult.getRootASTElement() != null) {
result++;
}
}
return result;
}
use of org.eclipse.xtext.util.TextRegion 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.util.TextRegion in project xtext-core by eclipse.
the class FormattingService method format.
/**
* @since 2.14
*/
public List<TextEdit> format(final XtextResource resource, final Document document, final int offset, final int length, final FormattingOptions options) {
String indent = this.indentationInformation.getIndentString();
if ((options != null)) {
boolean _isInsertSpaces = options.isInsertSpaces();
if (_isInsertSpaces) {
indent = Strings.padEnd("", options.getTabSize(), ' ');
}
}
if ((this.formatter2Provider != null)) {
final MapBasedPreferenceValues preferences = new MapBasedPreferenceValues();
preferences.put("indentation", indent);
TextRegion _textRegion = new TextRegion(offset, length);
final List<ITextReplacement> replacements = this.format2(resource, _textRegion, preferences);
final Function1<ITextReplacement, TextEdit> _function = (ITextReplacement r) -> {
return this.toTextEdit(document, r.getReplacementText(), r.getOffset(), r.getLength());
};
return IterableExtensions.<TextEdit>toList(ListExtensions.<ITextReplacement, TextEdit>map(replacements, _function));
} else {
return CollectionLiterals.<TextEdit>newArrayList();
}
}
use of org.eclipse.xtext.util.TextRegion in project xtext-core by eclipse.
the class ContentAssistContextTestHelper method firstSetGrammarElementsToString.
public String firstSetGrammarElementsToString(final ContentAssistContextFactory factory) {
final int offset = this.document.indexOf(this.cursor);
Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor");
final String doc = this.document.replace(this.cursor, "");
final XtextResource res = this.parse(doc);
factory.setPool(Executors.newCachedThreadPool());
TextRegion _textRegion = new TextRegion(0, 0);
final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res);
final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule();
StringConcatenation _builder = new StringConcatenation();
{
Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>) Conversions.doWrapArray(ctxs)));
for (final Pair<Integer, ContentAssistContext> ctx : _indexed) {
_builder.append("context");
Integer _key = ctx.getKey();
_builder.append(_key);
_builder.append(" {");
_builder.newLineIfNotEmpty();
{
ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements();
for (final AbstractElement ele : _firstSetGrammarElements) {
_builder.append("\t");
String _name = ele.eClass().getName();
_builder.append(_name, "\t");
_builder.append(": ");
String _apply = f.apply(ele);
_builder.append(_apply, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
}
}
return _builder.toString();
}
Aggregations