use of org.eclipse.xtend.lib.macro.services.Problem in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testValidationPhase.
@Test
public void testValidationPhase() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.ClassDeclaration");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.ValidationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(ValidatingProcessor)");
_builder.newLine();
_builder.append("annotation ValidatingAnnotation {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class ValidatingProcessor extends AbstractClassProcessor {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(MutableClassDeclaration cls, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cls.addWarning(\"Foo\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cls.addWarning(\"Bar\")");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doValidate(ClassDeclaration cls, extension ValidationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cls.addWarning(\"Baz\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cls.addWarning(\"There were \" + cls.problems.size + \" problems\")");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/ValidatingAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import myannotation.*");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@ValidatingAnnotation");
_builder_1.newLine();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration cls = it.getTypeLookup().findClass("myusercode.Foo");
final List<? extends Problem> problems = it.getProblemSupport().getProblems(cls);
Assert.assertEquals(4, problems.size());
Assert.assertEquals("Foo", problems.get(0).getMessage());
Assert.assertEquals("Bar", problems.get(1).getMessage());
Assert.assertEquals("Baz", problems.get(2).getMessage());
Assert.assertEquals("There were 3 problems", problems.get(3).getMessage());
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtend.lib.macro.services.Problem in project xtext-xtend by eclipse.
the class AnnotationWithNestedEnumProcessorTest method testBug487559_01.
@Test
public void testBug487559_01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.core.tests.macro.AnnotationWithNestedEnum");
_builder.newLine();
_builder.newLine();
_builder.append("@org.eclipse.xtend.core.tests.macro.AnnotationWithNestedEnum");
_builder.newLine();
_builder.append("class Client {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final Function1<Problem, String> _function_1 = (Problem it_1) -> {
return it_1.getMessage();
};
Assert.assertTrue(IterableExtensions.join(ListExtensions.map(it.getAllProblems(), _function_1), ", "), it.getAllProblems().isEmpty());
};
this._xtendCompilerTester.compile(_builder, _function);
}
use of org.eclipse.xtend.lib.macro.services.Problem in project xtext-xtend by eclipse.
the class Bug464136Test method testThrownErrorInPreValidation.
@Test
public void testThrownErrorInPreValidation() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@org.eclipse.xtend.core.tests.macro.Bug464136 class C {}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final List<? extends Problem> problems = it.getAllProblems();
final Function1<Problem, String> _function_1 = (Problem it_1) -> {
return it_1.getMessage();
};
Assert.assertEquals(ListExtensions.map(problems, _function_1).toString(), 1, problems.size());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("Error during annotation processing:");
_builder_1.newLine();
_builder_1.append("java.lang.LinkageError: Just a test :-/");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("at org.eclipse.xtend.core.tests.macro.Bug464136Processor.lambda$doTransform$0(Bug464136Processor.java:22)");
_builder_1.newLine();
final String messageJava = _builder_1.toString();
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("Error during annotation processing:");
_builder_2.newLine();
_builder_2.append("java.lang.LinkageError: Just a test :-/");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("at org.eclipse.xtend.core.tests.macro.Bug464136Processor.lambda$0(Bug464136Processor.java:22)");
_builder_2.newLine();
final String messageEclipse = _builder_2.toString();
if (((!Objects.equal(messageJava, IterableExtensions.head(problems).getMessage())) && (!Objects.equal(messageEclipse, IterableExtensions.head(problems).getMessage())))) {
StringConcatenation _builder_3 = new StringConcatenation();
_builder_3.append("Expected one of the following problem messages:");
_builder_3.newLine();
_builder_3.newLine();
_builder_3.append(messageJava);
_builder_3.newLineIfNotEmpty();
_builder_3.newLine();
_builder_3.append(messageEclipse);
_builder_3.newLineIfNotEmpty();
_builder_3.newLine();
_builder_3.append("But got:");
_builder_3.newLine();
_builder_3.newLine();
String _message = IterableExtensions.head(problems).getMessage();
_builder_3.append(_message);
_builder_3.newLineIfNotEmpty();
Assert.fail(_builder_3.toString());
}
};
this._xtendCompilerTester.compile(_builder, _function);
}
use of org.eclipse.xtend.lib.macro.services.Problem in project xtext-xtend by eclipse.
the class ProblemSupportImpl method getProblems.
@Override
public List<? extends Problem> getProblems(final Element element) {
this.checkCanceled();
final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element);
final Resource resource = resAndObj.getKey();
EList<Resource.Diagnostic> _errors = resource.getErrors();
EList<Resource.Diagnostic> _warnings = resource.getWarnings();
final Iterable<EObjectDiagnosticImpl> issues = Iterables.<EObjectDiagnosticImpl>filter((Iterables.<Resource.Diagnostic>concat(_errors, _warnings)), EObjectDiagnosticImpl.class);
final Function1<EObjectDiagnosticImpl, Boolean> _function = (EObjectDiagnosticImpl diag) -> {
EObject _problematicObject = diag.getProblematicObject();
EObject _value = resAndObj.getValue();
return Boolean.valueOf(Objects.equal(_problematicObject, _value));
};
final Function1<EObjectDiagnosticImpl, Problem> _function_1 = (EObjectDiagnosticImpl diag) -> {
String _code = diag.getCode();
String _message = diag.getMessage();
Problem.Severity _translateSeverity = this.translateSeverity(diag.getSeverity());
ProblemImpl _problemImpl = new ProblemImpl(_code, _message, _translateSeverity);
return ((Problem) _problemImpl);
};
final Iterable<Problem> result = IterableExtensions.<EObjectDiagnosticImpl, Problem>map(IterableExtensions.<EObjectDiagnosticImpl>filter(issues, _function), _function_1);
return IterableExtensions.<Problem>toList(result);
}
use of org.eclipse.xtend.lib.macro.services.Problem in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testValidateLater.
@Test
public void testValidateLater() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.AbstractFieldProcessor");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(ValidateLaterProcessor)");
_builder.newLine();
_builder.append("annotation ValidateLater {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class ValidateLaterProcessor extends AbstractFieldProcessor {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(MutableFieldDeclaration it, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("validateLater[ |");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("if (type == primitiveBoolean)");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("addWarning(\"The type was inferred and boolean\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/ValidateLater.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import myannotation.*");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("@ValidateLater val foo = true");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration cls = it.getTypeLookup().findClass("myusercode.Foo");
final List<? extends Problem> problems = it.getProblemSupport().getProblems(IterableExtensions.head(cls.getDeclaredFields()));
Assert.assertEquals(1, problems.size());
Assert.assertEquals("The type was inferred and boolean", problems.get(0).getMessage());
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Aggregations