use of org.eclipse.xtext.xbase.lib.Extension in project xtext-lib by eclipse.
the class EqualsHashCodeProcessor method doTransform.
@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
boolean _tripleNotEquals = (_findAnnotation != null);
if (_tripleNotEquals) {
return;
}
@Extension final EqualsHashCodeProcessor.Util util = new EqualsHashCodeProcessor.Util(context);
boolean _hasEquals = util.hasEquals(it);
if (_hasEquals) {
final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(EqualsHashCode.class));
context.addWarning(annotation, "equals is already defined, this annotation has no effect");
} else {
boolean _hasHashCode = util.hasHashCode(it);
if (_hasHashCode) {
context.addWarning(it, "hashCode is already defined, this annotation has no effect");
} else {
final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
return Boolean.valueOf((((!it_1.isStatic()) && (!it_1.isTransient())) && context.isThePrimaryGeneratedJavaElement(it_1)));
};
final Iterable<? extends MutableFieldDeclaration> fields = IterableExtensions.filter(it.getDeclaredFields(), _function);
util.addEquals(it, fields, util.hasSuperEquals(it));
util.addHashCode(it, fields, util.hasSuperHashCode(it));
}
}
}
use of org.eclipse.xtext.xbase.lib.Extension in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testExtensionToAnnotation_01.
@Test
public void testExtensionToAnnotation_01() throws Exception {
XtendFile xtendFile = file("class C { extension String }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmField jvmField = (JvmField) inferredType.getMembers().get(1);
assertEquals("_string", jvmField.getSimpleName());
List<JvmAnnotationReference> annotations = jvmField.getAnnotations();
assertEquals(1, annotations.size());
assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
use of org.eclipse.xtext.xbase.lib.Extension in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testExtensionToAnnotation_02.
@Test
public void testExtensionToAnnotation_02() throws Exception {
XtendFile xtendFile = file("class C { def void m(extension String s) {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
List<JvmFormalParameter> parameters = jvmOperation.getParameters();
JvmFormalParameter singleParameter = parameters.get(0);
List<JvmAnnotationReference> annotations = singleParameter.getAnnotations();
assertEquals(1, annotations.size());
assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testDocumentSymbol.
protected void testDocumentSymbol(final Procedure1<? super DocumentSymbolConfiguraiton> configurator) {
try {
@Extension final DocumentSymbolConfiguraiton configuration = new DocumentSymbolConfiguraiton();
configuration.setFilePath(("MyModel." + this.fileExtension));
configurator.apply(configuration);
final String fileUri = this.initializeContext(configuration).getUri();
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
DocumentSymbolParams _documentSymbolParams = new DocumentSymbolParams(_textDocumentIdentifier);
final CompletableFuture<List<? extends SymbolInformation>> symbolsFuture = this.languageServer.documentSymbol(_documentSymbolParams);
final List<? extends SymbolInformation> symbols = symbolsFuture.get();
Procedure1<? super List<? extends SymbolInformation>> _assertSymbols = configuration.getAssertSymbols();
boolean _tripleNotEquals = (_assertSymbols != null);
if (_tripleNotEquals) {
configuration.getAssertSymbols().apply(symbols);
} else {
final String actualSymbols = this.toExpectation(symbols);
this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testDocumentHighlight.
protected void testDocumentHighlight(final Procedure1<? super DocumentHighlightConfiguration> configurator) {
try {
DocumentHighlightConfiguration _documentHighlightConfiguration = new DocumentHighlightConfiguration();
final Procedure1<DocumentHighlightConfiguration> _function = (DocumentHighlightConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("MyModel.");
_builder.append(this.fileExtension);
it.setFilePath(_builder.toString());
};
@Extension final DocumentHighlightConfiguration configuration = ObjectExtensions.<DocumentHighlightConfiguration>operator_doubleArrow(_documentHighlightConfiguration, _function);
configurator.apply(configuration);
final String fileUri = this.initializeContext(configuration).getUri();
TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
final Procedure1<TextDocumentPositionParams> _function_1 = (TextDocumentPositionParams it) -> {
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
it.setTextDocument(_textDocumentIdentifier);
int _line = configuration.getLine();
int _column = configuration.getColumn();
Position _position = new Position(_line, _column);
it.setPosition(_position);
};
TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function_1);
final CompletableFuture<List<? extends DocumentHighlight>> highlights = this.languageServer.documentHighlight(_doubleArrow);
final Function1<DocumentHighlight, String> _function_2 = (DocumentHighlight it) -> {
return this.toExpectation(it);
};
final String actualDocumentHighlight = IterableExtensions.join(ListExtensions.map(highlights.get(), _function_2), " | ");
this.assertEquals(configuration.getExpectedDocumentHighlight(), actualDocumentHighlight);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations