org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder Java Examples
The following examples show how to use
org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
@Override protected void _format(XForLoopExpression expr, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr); document.append(regionFor.keyword(this.keywords.getForKeyword()), ONE_SPACE); final JvmFormalParameter declaredParam = expr.getDeclaredParam(); document.prepend(declaredParam, NO_SPACE); document.append(declaredParam, ONE_SPACE); document.format(declaredParam); final XExpression forExpression = expr.getForExpression(); document.prepend(forExpression, ONE_SPACE); document.append(forExpression, NO_SPACE); document.format(forExpression); final XExpression eachExpression = expr.getEachExpression(); if (eachExpression != null) { formatBody(eachExpression, true, document); } else { document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE); } }
Example #2
Source File: ReferenceUpdater.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected ISemanticRegion getRegion(ITextRegionAccess access, IReferenceSnapshot ref) { XtextResource resource = access.getResource(); URI objectUri = ref.getSourceEObjectUri(); if (!resource.getURI().equals(objectUri.trimFragment())) { return null; } EObject object = resource.getEObject(objectUri.fragment()); if (object == null) { return null; } ISemanticRegionsFinder finder = access.getExtensions().regionFor(object); int index = ref.getIndexInList(); if (index < 0) { return finder.feature(ref.getEReference()); } else { List<ISemanticRegion> list = finder.features(ref.getEReference()); if (list != null && index < list.size()) { return list.get(index); } } return null; }
Example #3
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
@Override protected void _format(XBlockExpression expr, IFormattableDocument document) { if (getPreferences().getPreference(SARLFormatterPreferenceKeys.ENABLE_SINGLELINE_EXPRESSION).booleanValue()) { super._format(expr, document); } else { // Avoid to format the block expression on a single line. final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr); if (expr.eContainer() == null) { document.surround(expr, NO_SPACE); } final ISemanticRegion open = regionFor.keyword(this.keywords.getLeftCurlyBracketKeyword()); final ISemanticRegion close = regionFor.keyword(this.keywords.getRightCurlyBracketKeyword()); if (open != null && close != null) { formatExpressionsMultiline(expr.getExpressions(), open, close, document); } } }
Example #4
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
@Override protected void _format(XtendField field, IFormattableDocument document) { formatAnnotations(field, document, XbaseFormatterPreferenceKeys.newLineAfterFieldAnnotations); formatModifiers(field, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(field); final ISemanticRegion columnKw = regionFor.keyword(this.keywords.getColonKeyword()); document.prepend(columnKw, ONE_SPACE); document.append(columnKw, ONE_SPACE); final ISemanticRegion equalKw = regionFor.keyword(this.keywords.getEqualsSignKeyword()); document.prepend(equalKw, ONE_SPACE); document.append(equalKw, ONE_SPACE); final ISemanticRegion semicolumn = regionFor.keyword(this.keywords.getSemicolonKeyword()); document.prepend(semicolumn, NO_SPACE); final JvmTypeReference type = field.getType(); document.format(type); final XExpression initialValue = field.getInitialValue(); document.format(initialValue); }
Example #5
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
/** Format the given SARL skill. * * @param skill the SARL component. * @param document the document. */ protected void _format(SarlSkill skill, IFormattableDocument document) { formatAnnotations(skill, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(skill, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(skill); document.append(regionFor.keyword(this.keywords.getSkillKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(skill.getExtends()); document.surround(regionFor.keyword(this.keywords.getImplementsKeyword()), ONE_SPACE); formatCommaSeparatedList(skill.getImplements(), document); formatBody(skill, document); }
Example #6
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format the given SARL behavior. * * @param behavior the SARL component. * @param document the document. */ protected void _format(SarlBehavior behavior, IFormattableDocument document) { formatAnnotations(behavior, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(behavior, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(behavior); document.append(regionFor.keyword(this.keywords.getBehaviorKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(behavior.getExtends()); formatBody(behavior, document); }
Example #7
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForAssignment() throws Exception { Mixed mixed = parseAs("6 (foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder .assignment(grammarAccess.getMixedAccess().getNameAssignment_2_2_0()); List<ISemanticRegion> actuals = finder .assignments(grammarAccess.getMixedAccess().getNameAssignment_2_2_0()); assertEquals("foo", actual, actuals); }
Example #8
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForKeywordPairs() throws Exception { @Extension RegionAccessTestLanguageGrammarAccess.ParenthesizedElements rule = grammarAccess .getParenthesizedAccess(); Expression expr = parseAs("5 (foo)", Expression.class); ISemanticRegionsFinder finder = toAccess(expr).regionForEObject(expr).getRegionFor(); String actual1 = pairsToString(finder.keywordPairs("(", ")")); String actual2 = pairsToString( finder.keywordPairs(rule.getLeftParenthesisKeyword_0(), rule.getRightParenthesisKeyword_2())); String expected = "(foo)"; Assert.assertEquals(expected, actual1); Assert.assertEquals(expected, actual2); }
Example #9
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForKeywordPairs2() throws Exception { @Extension RegionAccessTestLanguageGrammarAccess.ParenthesizedElements rule = grammarAccess .getParenthesizedAccess(); Expression expr = parseAs("5 (a + ((b) + c) + d)", Expression.class); ISemanticRegionsFinder finder = toAccess(expr).regionForRootEObject().getAllRegionsFor(); String actual1 = pairsToString(finder.keywordPairs("(", ")")); String actual2 = pairsToString( finder.keywordPairs(rule.getLeftParenthesisKeyword_0(), rule.getRightParenthesisKeyword_2())); String expected = "(b); ((b) + c); (a + ((b) + c) + d)"; Assert.assertEquals(expected, actual1); Assert.assertEquals(expected, actual2); }
Example #10
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format the given SARL event. * * @param event the SARL component. * @param document the document. */ protected void _format(SarlEvent event, IFormattableDocument document) { formatAnnotations(event, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(event, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(event); document.append(regionFor.keyword(this.keywords.getEventKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(event.getExtends()); formatBody(event, document); }
Example #11
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format the given SARL capacity. * * @param capacity the SARL component. * @param document the document. */ protected void _format(SarlCapacity capacity, IFormattableDocument document) { formatAnnotations(capacity, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(capacity, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(capacity); document.append(regionFor.keyword(this.keywords.getCapacityKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); formatCommaSeparatedList(capacity.getExtends(), document); formatBody(capacity, document); }
Example #12
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format the given SARL agent. * * @param agent the SARL component. * @param document the document. */ protected void _format(SarlAgent agent, IFormattableDocument document) { formatAnnotations(agent, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(agent, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(agent); document.append(regionFor.keyword(this.keywords.getAgentKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(agent.getExtends()); formatBody(agent, document); }
Example #13
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForKeyword() throws Exception { Mixed mixed = parseAs("6 (foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder .keyword(grammarAccess.getMixedAccess().getLeftParenthesisKeyword_0()); List<ISemanticRegion> actuals = finder .keywords(grammarAccess.getMixedAccess().getLeftParenthesisKeyword_0()); assertEquals("(", actual, actuals); }
Example #14
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format a capacity use. * * @param capacityUses the capacity uses. * @param document the document. */ protected void _format(SarlCapacityUses capacityUses, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(capacityUses); document.append(regionFor.keyword(this.keywords.getUsesKeyword()), ONE_SPACE); formatCommaSeparatedList(capacityUses.getCapacities(), document); document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE); }
Example #15
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format a required capacity. * * @param requiredCapacity the element ot format. * @param document the document. */ protected void _format(SarlRequiredCapacity requiredCapacity, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(requiredCapacity); document.append(regionFor.keyword(this.keywords.getRequiresKeyword()), ONE_SPACE); formatCommaSeparatedList(requiredCapacity.getCapacities(), document); document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE); }
Example #16
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
@Override protected void _format(XtendParameter param, IFormattableDocument document) { formatAnnotations(param, document, XbaseFormatterPreferenceKeys.newLineAfterParameterAnnotations); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(param); document.surround(regionFor.keyword(this.keywords.getColonKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getEqualsSignKeyword()), ONE_SPACE); final JvmTypeReference parameterType = param.getParameterType(); if (parameterType != null) { document.format(parameterType); final ISemanticRegion varArgToken = regionFor.keyword(this.keywords.getWildcardAsteriskKeyword()); document.surround(varArgToken, NO_SPACE); } }
Example #17
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
@Override protected void _format(XVariableDeclaration expr, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr); document.append(regionFor.keyword(this.keywords.getExtensionExtensionKeyword()), ONE_SPACE); document.append(regionFor.keyword(this.keywords.getValKeyword()), ONE_SPACE); document.append(regionFor.keyword(this.keywords.getWriteableVarKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getColonKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getEqualsSignKeyword()), ONE_SPACE); document.format(expr.getType()); document.format(expr.getRight()); }
Example #18
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
@Override protected void _format(JvmFormalParameter expr, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr); document.append(regionFor.keyword(this.keywords.getExtensionExtensionKeyword()), ONE_SPACE); final JvmTypeReference parameterType = expr.getParameterType(); if (parameterType != null) { document.surround(regionFor.keyword(this.keywords.getColonKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getAsKeyword()), ONE_SPACE); } document.format(parameterType); }
Example #19
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForRuleCallAssignedTerminal() throws Exception { Mixed mixed = parseAs("6 (foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder.ruleCall( grammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0()); ISemanticRegion actuals = finder.ruleCall( grammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0()); Assert.assertEquals("foo", actual, actuals); }
Example #20
Source File: RichStringToLineModel.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void announceNextLiteral(final RichStringLiteral object) { super.announceNextLiteral(object); if (((this.lastLiteralEndOffset > 0) && (this.contentStartOffset < 0))) { this.contentStartOffset = this.lastLiteralEndOffset; } IEObjectRegion _regionForEObject = this.nodeModelAccess.regionForEObject(object); ISemanticRegionsFinder _regionFor = null; if (_regionForEObject!=null) { _regionFor=_regionForEObject.getRegionFor(); } ISemanticRegion _feature = null; if (_regionFor!=null) { _feature=_regionFor.feature(XbasePackage.Literals.XSTRING_LITERAL__VALUE); } final ISemanticRegion node = _feature; if ((node != null)) { int _offset = node.getOffset(); int _literalPrefixLenght = this.literalPrefixLenght(node); int _plus = (_offset + _literalPrefixLenght); this.offset = _plus; int _endOffset = node.getEndOffset(); int _literalPostfixLenght = this.literalPostfixLenght(node); int _minus = (_endOffset - _literalPostfixLenght); this.lastLiteralEndOffset = _minus; } this.content = true; }
Example #21
Source File: AbstractRegionAccess.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ISemanticRegionsFinder allRegionsFor(EObject object) { AbstractEObjectRegion region = regionForEObject(object); if (region == null) return SemanticRegionNullFinder.INSTANCE; return region.getAllRegionsFor(); }
Example #22
Source File: AbstractRegionAccess.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ISemanticRegionsFinder regionFor(EObject object) { AbstractEObjectRegion region = regionForEObject(object); if (region != null) return region.getRegionFor(); else return SemanticRegionNullFinder.INSTANCE; }
Example #23
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForFeatureAttribute() throws Exception { Mixed mixed = parseAs("6 (foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder.feature(RegionaccesstestlanguagePackage.Literals.MIXED__NAME); List<ISemanticRegion> actuals = finder.features(RegionaccesstestlanguagePackage.Literals.MIXED__NAME); assertEquals("foo", actual, actuals); }
Example #24
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForRuleCallUnassignedTerminal() throws Exception { Mixed mixed = parseAs("6 (unassigned foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder .ruleCall(grammarAccess.getMixedAccess().getIDTerminalRuleCall_1_1_0()); List<ISemanticRegion> actuals = finder .ruleCalls(grammarAccess.getMixedAccess().getIDTerminalRuleCall_1_1_0()); assertEquals("foo", actual, actuals); }
Example #25
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForRuleCallToUnassignedTerminal() throws Exception { Mixed mixed = parseAs("6 (unassigned foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder.ruleCallTo(grammarAccess.getIDRule()); List<ISemanticRegion> actuals = finder.ruleCallsTo(grammarAccess.getIDRule()); assertEquals("foo", actual, actuals); }
Example #26
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForRuleCallUnassignedDataType() throws Exception { Mixed mixed = parseAs("6 (unassigned datatype foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder.ruleCall( grammarAccess.getMixedAccess().getDatatypeParserRuleCall_1_1_1()); List<ISemanticRegion> actuals = finder.ruleCalls( grammarAccess.getMixedAccess().getDatatypeParserRuleCall_1_1_1()); assertEquals("datatype foo", actual, actuals); }
Example #27
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForRuleCallToUnassignedDataType() throws Exception { Mixed mixed = parseAs("6 (unassigned datatype foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder.ruleCallTo(grammarAccess.getDatatypeRule()); List<ISemanticRegion> actuals = finder .ruleCallsTo(grammarAccess.getDatatypeRule()); assertEquals("datatype foo", actual, actuals); }
Example #28
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForCrossReference() throws Exception { AssignedAction mixed = parseAs("6 (ref foo) action (foo) end", AssignedAction.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed.getChild()).getRegionFor(); ISemanticRegion actual = finder.crossRef( grammarAccess.getMixedAccess().getRefMixedCrossReference_2_2_3_1_0()); List<ISemanticRegion> actuals = finder.crossRefs( grammarAccess.getMixedAccess().getRefMixedCrossReference_2_2_3_1_0()); assertEquals("foo", actual, actuals); }
Example #29
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForRuleCallToAssignedTerminal() throws Exception { Mixed mixed = parseAs("6 (foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder.ruleCallTo(grammarAccess.getIDRule()); ISemanticRegion actuals = finder.ruleCallTo(grammarAccess.getIDRule()); Assert.assertEquals("foo", actual, actuals); }
Example #30
Source File: SemanticRegionFinderTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void regionForRuleCallAssignedDataType() throws Exception { Mixed mixed = parseAs("6 (datatype foo)", Mixed.class); ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor(); ISemanticRegion actual = finder.ruleCall(grammarAccess.getMixedAccess() .getDatatypeDatatypeParserRuleCall_2_2_2_0()); ISemanticRegion actuals = finder.ruleCall(grammarAccess.getMixedAccess() .getDatatypeDatatypeParserRuleCall_2_2_2_0()); Assert.assertEquals("datatype foo", actual, actuals); }