This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #795 from eclipse/cd_formatterExperiments
change baseclass for xbase formatter
- Loading branch information
Showing
10 changed files
with
228 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...lipse.xtext.purexbase/src/org/eclipse/xtext/purexbase/formatting2/PureXbaseFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2017, 2022 itemis AG (http://www.itemis.eu) and others. | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.xtext.purexbase.formatting2; | ||
|
||
import org.eclipse.xtext.formatting2.IFormattableDocument; | ||
import org.eclipse.xtext.purexbase.pureXbase.Model; | ||
import org.eclipse.xtext.purexbase.services.PureXbaseGrammarAccess; | ||
import org.eclipse.xtext.xbase.XBlockExpression; | ||
import org.eclipse.xtext.xbase.XExpression; | ||
import org.eclipse.xtext.xbase.formatting2.XbaseFormatter; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class PureXbaseFormatter extends XbaseFormatter { | ||
@Inject | ||
private PureXbaseGrammarAccess pureXbaseGrammarAccess; | ||
|
||
protected void _format(Model model, IFormattableDocument document) { | ||
document.format(model.getImportSection()); | ||
document.format(model.getBlock()); | ||
} | ||
|
||
@Override | ||
protected void _format(XBlockExpression xBlockExpression, IFormattableDocument document) { | ||
regionFor(xBlockExpression) | ||
.keywords(pureXbaseGrammarAccess.getSpecialBlockExpressionAccess().getSemicolonKeyword_1_1()) | ||
.forEach(it -> { | ||
document.append(it, this::newLine); | ||
}); | ||
for (XExpression xExpression : xBlockExpression.getExpressions()) { | ||
document.format(xExpression); | ||
} | ||
} | ||
|
||
@Override | ||
public void format(Object expr, IFormattableDocument format) { | ||
formatUsingPolymorphicDispatcher(expr, format); | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...ipse.xtext.purexbase/src/org/eclipse/xtext/purexbase/formatting2/PureXbaseFormatter.xtend
This file was deleted.
Oops, something went wrong.
206 changes: 0 additions & 206 deletions
206
...xtext.purexbase/xtend-gen/org/eclipse/xtext/purexbase/formatting2/PureXbaseFormatter.java
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
...text.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterJavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 itemis AG (http://www.itemis.eu) and others. | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.xtext.xbase.tests.formatting; | ||
|
||
import org.eclipse.xtext.formatting2.IFormattableDocument; | ||
import org.eclipse.xtext.testing.InjectWith; | ||
import org.eclipse.xtext.testing.XtextRunner; | ||
import org.eclipse.xtext.testing.formatter.FormatterTestRequest; | ||
import org.eclipse.xtext.xbase.XPostfixOperation; | ||
import org.eclipse.xtext.xbase.XbasePackage; | ||
import org.eclipse.xtext.xbase.formatting2.XbaseFormatter; | ||
import org.eclipse.xtext.xbase.tests.formatting.XbaseFormatterJavaTest.XbaseFormatterJavaTestInjectorProvider; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
|
||
/** | ||
* @author cdietrich - Initial contribution and API | ||
*/ | ||
@RunWith(XtextRunner.class) | ||
@InjectWith(XbaseFormatterJavaTestInjectorProvider.class) | ||
public class XbaseFormatterJavaTest extends XbaseFormatterTest { | ||
|
||
public static class XbaseFormatterJavaTestInjectorProvider extends XbaseFormatterTestInjectorProvider { | ||
@Override | ||
protected Injector internalCreateInjector() { | ||
return new FunctionTypeRefAwareTestStandaloneSetup() { | ||
@Override | ||
public Injector createInjector() { | ||
return Guice.createInjector(new XbaseTestRuntimeModule() { | ||
@Override | ||
public void configure(com.google.inject.Binder binder) { | ||
super.configure(binder); | ||
binder.bind(XbaseFormatter.class).to(XbaseFormatterJava.class); | ||
} | ||
}); | ||
} | ||
}.createInjectorAndDoEMFRegistration(); | ||
} | ||
} | ||
|
||
public static class XbaseFormatterJava extends XbaseFormatter { | ||
@Override | ||
public void format(Object expr, IFormattableDocument format) { | ||
formatUsingPolymorphicDispatcher(expr, format); | ||
} | ||
|
||
@Override | ||
protected void _format(XPostfixOperation expr, IFormattableDocument doc) { | ||
doc.prepend(regionFor(expr).feature(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE), this::oneSpace); | ||
doc.format(expr.getOperand()); | ||
} | ||
} | ||
|
||
@Override | ||
@Test | ||
public void formatPostfix() { | ||
xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { | ||
String expectation = | ||
"val i = j ++\n"; | ||
it.setExpectation(expectation); | ||
String toBeFormatted = | ||
"val i = j++\n"; | ||
it.setToBeFormatted(toBeFormatted); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.