mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
Make injection of the CompositeEValidator work
This commit is contained in:
parent
b2cf16320c
commit
edeb506431
3 changed files with 35 additions and 15 deletions
|
@ -52,7 +52,7 @@ public class XtextRunner extends BlockJUnit4ClassRunner {
|
|||
}
|
||||
}
|
||||
};
|
||||
}else{
|
||||
} else {
|
||||
return superMethodBlock(method);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.eclipse.xtext.validation;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.emf.common.util.BasicDiagnostic;
|
||||
|
@ -17,10 +18,9 @@ import org.eclipse.emf.ecore.ENamedElement;
|
|||
import org.eclipse.emf.ecore.EcoreFactory;
|
||||
import org.eclipse.emf.ecore.util.EcoreValidator;
|
||||
import org.eclipse.xtext.validation.CompositeEValidator.EValidatorEqualitySupport;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
* @author Knut Wannheden - Initial contribution and API
|
||||
*/
|
||||
|
@ -42,14 +42,10 @@ public class CompositeEValidatorTest {
|
|||
}
|
||||
|
||||
/** Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=396726 */
|
||||
@Test public void testNoShortCircuiting() {
|
||||
@Test
|
||||
public void testNoShortCircuiting() {
|
||||
CompositeEValidator compositeValidator = new CompositeEValidator();
|
||||
compositeValidator.setEqualitySupportProvider(new Provider<CompositeEValidator.EValidatorEqualitySupport>() {
|
||||
@Override
|
||||
public EValidatorEqualitySupport get() {
|
||||
return new CompositeEValidator.EValidatorEqualitySupport();
|
||||
}
|
||||
});
|
||||
compositeValidator.setEqualitySupportProvider(CompositeEValidator.EValidatorEqualitySupport::new);
|
||||
assertEquals(1, compositeValidator.getContents().size());
|
||||
|
||||
compositeValidator.addValidator(EcoreValidator.INSTANCE);
|
||||
|
@ -62,4 +58,20 @@ public class CompositeEValidatorTest {
|
|||
compositeValidator.validate(EcoreFactory.eINSTANCE.createEClass(), new BasicDiagnostic(), null);
|
||||
assertTrue(testValidator.wasCalled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyAndClearContents() {
|
||||
class TestMe extends CompositeEValidator {
|
||||
}
|
||||
CompositeEValidator testee = new TestMe();
|
||||
testee.setEqualitySupportProvider(CompositeEValidator.EValidatorEqualitySupport::new);
|
||||
testee.setUseEObjectValidator(true);
|
||||
List<EValidatorEqualitySupport> oldContents = testee.getContents();
|
||||
CompositeEValidator copy = testee.getCopyAndClearContents();
|
||||
Assert.assertEquals(testee.getClass(), copy.getClass());
|
||||
List<EValidatorEqualitySupport> newContents = testee.getContents();
|
||||
Assert.assertEquals(oldContents.size(), newContents.size());
|
||||
Assert.assertSame(oldContents.get(0), copy.getContents().get(0));
|
||||
Assert.assertNotSame(oldContents.get(0), testee.getContents().get(0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.eclipse.xtext.service.OperationCanceledError;
|
|||
import org.eclipse.xtext.service.OperationCanceledManager;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.name.Named;
|
||||
|
@ -33,7 +32,7 @@ import com.google.inject.name.Named;
|
|||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
public class CompositeEValidator implements EValidator {
|
||||
public class CompositeEValidator implements EValidator, Cloneable {
|
||||
|
||||
public static final String USE_EOBJECT_VALIDATOR = "org.eclipse.xtext.validation.CompositeEValidator.USE_EOBJECT_VALIDATOR";
|
||||
|
||||
|
@ -207,6 +206,15 @@ public class CompositeEValidator implements EValidator {
|
|||
public Provider<EValidatorEqualitySupport> getEqualitySupportProvider() {
|
||||
return equalitySupportProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompositeEValidator clone() {
|
||||
try {
|
||||
return (CompositeEValidator) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For testing purpose.
|
||||
|
@ -215,12 +223,12 @@ public class CompositeEValidator implements EValidator {
|
|||
* @since 2.4
|
||||
*/
|
||||
public CompositeEValidator getCopyAndClearContents() {
|
||||
CompositeEValidator result = new CompositeEValidator();
|
||||
CompositeEValidator result = clone();
|
||||
result.equalitySupportProvider = this.equalitySupportProvider;
|
||||
result.useEObjectValidator = this.useEObjectValidator;
|
||||
result.operationCanceledManager = this.operationCanceledManager;
|
||||
result.useEObjectValidator = this.useEObjectValidator;
|
||||
if (this.contents != null) {
|
||||
result.contents = Lists.newArrayList(this.contents);
|
||||
result.contents = new ArrayList<>(this.contents);
|
||||
this.contents = null;
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in a new issue