org.eclipse.emf.common.util.BasicDiagnostic Java Examples

The following examples show how to use org.eclipse.emf.common.util.BasicDiagnostic. 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: ConditionalRoutePropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.ConditionalRoute.Properties.condition == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getConditionalRoute_Condition().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getConditionalRoute_Condition().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #2
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the validType constraint of '<em>Instance</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean validateInstance_validType(Instance instance, DiagnosticChain diagnostics,
	Map<Object, Object> context) {
	if (!validate_validType(instance)) {
		if (diagnostics != null) {
			diagnostics.add
				(new BasicDiagnostic
				(Diagnostic.ERROR,
					DIAGNOSTIC_SOURCE,
					0,
					EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { "validType", //$NON-NLS-1$ //$NON-NLS-2$
						getObjectLabel((EObject) instance, context) }),
					new Object[] { instance }));
		}
		return false;
	}
	return true;
}
 
Example #3
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the validContainment constraint of '<em>Instance</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean validateInstance_validContainment(Instance instance, DiagnosticChain diagnostics,
	Map<Object, Object> context) {
	if (!validate_validContainment(instance)) {
		if (diagnostics != null) {
			diagnostics.add
				(new BasicDiagnostic
				(Diagnostic.ERROR,
					DIAGNOSTIC_SOURCE,
					0,
					EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { //$NON-NLS-1$
						"validContainment", getObjectLabel((EObject) instance, context) }), //$NON-NLS-1$
					new Object[] { instance }));
		}
		return false;
	}
	return true;
}
 
Example #4
Source File: ExtensionsEditor.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * Returns a diagnostic describing the errors and warnings listed in the resource
 * and the specified exception (if any).
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) {
	if (!resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()) {
		BasicDiagnostic basicDiagnostic =
			new BasicDiagnostic
				(Diagnostic.ERROR,
				 "IFMLEditor.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 new Object [] { exception == null ? (Object)resource : exception });
		basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
		return basicDiagnostic;
	}
	else if (exception != null) {
		return
			new BasicDiagnostic
				(Diagnostic.ERROR,
				 "IFMLEditor.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 new Object[] { exception });
	}
	else {
		return Diagnostic.OK_INSTANCE;
	}
}
 
Example #5
Source File: CoreEditor.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * Returns a diagnostic describing the errors and warnings listed in the resource
 * and the specified exception (if any).
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) {
	if (!resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()) {
		BasicDiagnostic basicDiagnostic =
			new BasicDiagnostic
				(Diagnostic.ERROR,
				 "IFMLEditor.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 new Object [] { exception == null ? (Object)resource : exception });
		basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
		return basicDiagnostic;
	}
	else if (exception != null) {
		return
			new BasicDiagnostic
				(Diagnostic.ERROR,
				 "IFMLEditor.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 new Object[] { exception });
	}
	else {
		return Diagnostic.OK_INSTANCE;
	}
}
 
Example #6
Source File: EipEditor.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
   * Returns a diagnostic describing the errors and warnings listed in the resource
   * and the specified exception (if any).
   * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
   * @generated
   */
public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) {
     if (!resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()) {
        BasicDiagnostic basicDiagnostic =
           new BasicDiagnostic
              (Diagnostic.ERROR,
               "com.github.lbroudoux.dsl.eip.editor",
               0,
               getString("_UI_CreateModelError_message", resource.getURI()),
               new Object [] { exception == null ? (Object)resource : exception });
        basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
        return basicDiagnostic;
     }
     else if (exception != null) {
        return
           new BasicDiagnostic
              (Diagnostic.ERROR,
               "com.github.lbroudoux.dsl.eip.editor",
               0,
               getString("_UI_CreateModelError_message", resource.getURI()),
               new Object[] { exception });
     }
     else {
        return Diagnostic.OK_INSTANCE;
     }
  }
 
Example #7
Source File: PlaneImpl.java    From fixflow with Apache License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public boolean plane_element_type(DiagnosticChain diagnostics, Map<Object, Object> context) {
    // TODO: implement this method
    // -> specify the condition that violates the invariant
    // -> verify the details of the diagnostic, including severity and message
    // Ensure that you remove @generated or mark it @generated NOT
    if (false) {
        if (diagnostics != null) {
            diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR,
                    DiValidator.DIAGNOSTIC_SOURCE, DiValidator.PLANE__PLANE_ELEMENT_TYPE,
                    EcorePlugin.INSTANCE.getString(
                            "_UI_GenericInvariant_diagnostic",
                            new Object[] { "plane_element_type",
                                    EObjectValidator.getObjectLabel(this, context) }),
                    new Object[] { this }));
        }
        return false;
    }
    return true;
}
 
Example #8
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the validMultiplicity constraint of '<em>Slot</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean validateSlot_validMultiplicity(Slot slot, DiagnosticChain diagnostics, Map<Object, Object> context) {
	if (!validate_validMultiplicity(slot)) {
		if (diagnostics != null) {
			diagnostics.add
				(new BasicDiagnostic
				(Diagnostic.ERROR,
					DIAGNOSTIC_SOURCE,
					0,
					EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { //$NON-NLS-1$
						"validMultiplicity", getObjectLabel((EObject) slot, context) }), //$NON-NLS-1$
					new Object[] { slot }));
		}
		return false;
	}
	return true;
}
 
Example #9
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the validType constraint of '<em>Reference Slot</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean validateReferenceSlot_validType(ReferenceSlot referenceSlot, DiagnosticChain diagnostics,
	Map<Object, Object> context) {
	if (!validate_validType(referenceSlot)) {
		if (diagnostics != null) {
			diagnostics.add
				(new BasicDiagnostic
				(Diagnostic.ERROR,
					DIAGNOSTIC_SOURCE,
					0,
					EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { "validType", //$NON-NLS-1$ //$NON-NLS-2$
						getObjectLabel((EObject) referenceSlot, context) }),
					new Object[] { referenceSlot }));
		}
		return false;
	}
	return true;
}
 
Example #10
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the noDanglingReference constraint of '<em>Reference Slot</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean validateReferenceSlot_noDanglingReference(ReferenceSlot referenceSlot, DiagnosticChain diagnostics,
	Map<Object, Object> context) {
	if (!validate_noDanglingReference(referenceSlot)) {
		if (diagnostics != null) {
			diagnostics.add
				(new BasicDiagnostic
				(Diagnostic.ERROR,
					DIAGNOSTIC_SOURCE,
					0,
					EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { //$NON-NLS-1$
						"noDanglingReference", getObjectLabel((EObject) referenceSlot, context) }), //$NON-NLS-1$
					new Object[] { referenceSlot }));
		}
		return false;
	}
	return true;
}
 
Example #11
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the validOpposite constraint of '<em>Reference Slot</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean validateReferenceSlot_validOpposite(ReferenceSlot referenceSlot, DiagnosticChain diagnostics,
	Map<Object, Object> context) {
	if (!validate_validOpposite(referenceSlot)) {
		if (diagnostics != null) {
			diagnostics.add
				(new BasicDiagnostic
				(Diagnostic.ERROR,
					DIAGNOSTIC_SOURCE,
					0,
					EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { //$NON-NLS-1$
						"validOpposite", getObjectLabel((EObject) referenceSlot, context) }), //$NON-NLS-1$
					new Object[] { referenceSlot }));
		}
		return false;
	}
	return true;
}
 
Example #12
Source File: jpdl32Validator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the MemberTypes constraint of '<em>Priority Type</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public boolean validatePriorityType_MemberTypes(Object priorityType, DiagnosticChain diagnostics, Map<Object, Object> context) {
	if (diagnostics != null) {
		BasicDiagnostic tempDiagnostics = new BasicDiagnostic();
		if (jpdl32Package.Literals.PRIORITY_TYPE_MEMBER0.isInstance(priorityType)) {
			if (validatePriorityTypeMember0((PriorityTypeMember0)priorityType, tempDiagnostics, context)) return true;
		}
		if (jpdl32Package.Literals.PRIORITY_TYPE_MEMBER1.isInstance(priorityType)) {
			if (validatePriorityTypeMember1((Integer)priorityType, tempDiagnostics, context)) return true;
		}
		for (Diagnostic diagnostic : tempDiagnostics.getChildren()) {
			diagnostics.add(diagnostic);
		}
	}
	else {
		if (jpdl32Package.Literals.PRIORITY_TYPE_MEMBER0.isInstance(priorityType)) {
			if (validatePriorityTypeMember0((PriorityTypeMember0)priorityType, null, context)) return true;
		}
		if (jpdl32Package.Literals.PRIORITY_TYPE_MEMBER1.isInstance(priorityType)) {
			if (validatePriorityTypeMember1((Integer)priorityType, null, context)) return true;
		}
	}
	return false;
}
 
Example #13
Source File: ModelValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the MemberTypes constraint of '<em>TImplementation</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public boolean validateTImplementation_MemberTypes(Object tImplementation, DiagnosticChain diagnostics, Map<Object, Object> context) {
	if (diagnostics != null) {
		BasicDiagnostic tempDiagnostics = new BasicDiagnostic();
		if (XMLTypePackage.Literals.ANY_URI.isInstance(tImplementation)) {
			if (xmlTypeValidator.validateAnyURI((String)tImplementation, tempDiagnostics, context)) return true;
		}
		if (ModelPackage.Literals.TIMPLEMENTATION_MEMBER1.isInstance(tImplementation)) {
			if (validateTImplementationMember1((TImplementationMember1)tImplementation, tempDiagnostics, context)) return true;
		}
		for (Diagnostic diagnostic : tempDiagnostics.getChildren()) {
			diagnostics.add(diagnostic);
		}
	}
	else {
		if (XMLTypePackage.Literals.ANY_URI.isInstance(tImplementation)) {
			if (xmlTypeValidator.validateAnyURI((String)tImplementation, null, context)) return true;
		}
		if (ModelPackage.Literals.TIMPLEMENTATION_MEMBER1.isInstance(tImplementation)) {
			if (validateTImplementationMember1((TImplementationMember1)tImplementation, null, context)) return true;
		}
	}
	return false;
}
 
Example #14
Source File: ModelValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the MemberTypes constraint of '<em>TTransaction Method</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public boolean validateTTransactionMethod_MemberTypes(Object tTransactionMethod, DiagnosticChain diagnostics, Map<Object, Object> context) {
	if (diagnostics != null) {
		BasicDiagnostic tempDiagnostics = new BasicDiagnostic();
		if (XMLTypePackage.Literals.ANY_URI.isInstance(tTransactionMethod)) {
			if (xmlTypeValidator.validateAnyURI((String)tTransactionMethod, tempDiagnostics, context)) return true;
		}
		if (ModelPackage.Literals.TTRANSACTION_METHOD_MEMBER1.isInstance(tTransactionMethod)) {
			if (validateTTransactionMethodMember1((TTransactionMethodMember1)tTransactionMethod, tempDiagnostics, context)) return true;
		}
		for (Diagnostic diagnostic : tempDiagnostics.getChildren()) {
			diagnostics.add(diagnostic);
		}
	}
	else {
		if (XMLTypePackage.Literals.ANY_URI.isInstance(tTransactionMethod)) {
			if (xmlTypeValidator.validateAnyURI((String)tTransactionMethod, null, context)) return true;
		}
		if (ModelPackage.Literals.TTRANSACTION_METHOD_MEMBER1.isInstance(tTransactionMethod)) {
			if (validateTTransactionMethodMember1((TTransactionMethodMember1)tTransactionMethod, null, context)) return true;
		}
	}
	return false;
}
 
Example #15
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates the validFeature constraint of '<em>Slot</em>'.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean validateSlot_validFeature(Slot slot, DiagnosticChain diagnostics, Map<Object, Object> context) {
	if (!validate_validFeature(slot)) {
		if (diagnostics != null) {
			diagnostics.add
				(new BasicDiagnostic
				(Diagnostic.ERROR,
					DIAGNOSTIC_SOURCE,
					0,
					EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { //$NON-NLS-1$
						"validFeature", getObjectLabel((EObject) slot, context) }), //$NON-NLS-1$
					new Object[] { slot }));
		}
		return false;
	}
	return true;
}
 
Example #16
Source File: SplitterPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Splitter.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #17
Source File: CompositeProcessorPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.CompositeProcessor.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #18
Source File: TransformerPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Transformer.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #19
Source File: GatewayPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Gateway.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #20
Source File: InvocableEndpointPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.InvocableEndpoint.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #21
Source File: ServiceActivatorPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.ServiceActivator.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #22
Source File: DomainValidator.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
	if (eObject instanceof DomainElement) {
		DomainStatus status = DomainRegistry.getDomainStatus(((DomainElement) eObject).getDomainID());
		if (status.getSeverity() == Severity.ERROR) {
			diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, "DomainValidator", 0, status.getShortMessage(),
					new Object[] { eObject }));
		} else if (status.getSeverity() == Severity.WARNING) {
			diagnostics.add(new BasicDiagnostic(Diagnostic.WARNING, "DomainValidator", 0, status.getMessage(),
					new Object[] { eObject }));
		} else if (status.getSeverity() == Severity.INFO) {
			diagnostics.add(new BasicDiagnostic(Diagnostic.INFO, "DomainValidator", 0, status.getShortMessage(),
					new Object[] { eObject }));
		}
	}
	return true;
}
 
Example #23
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create an error message (if needed) based on the given input parameters.
 *
 * @param pos
 *          position in the source to associate the message with
 * @param diagnosticsOnTargetPosition
 *          diagnostics on the specifies position
 * @param issueFound
 *          specifies whether an issue has been found at the given position
 * @param expectedSeverityMatches
 *          true if expected severity equals actual one, false otherwise
 * @param actualSeverity
 *          actual severity
 * @param expectedMessageMatches
 *          expected message matches
 * @param actualMessage
 *          actual message
 */
private void createErrorMessage(final Integer pos, final BasicDiagnostic diagnosticsOnTargetPosition, final boolean issueFound, final boolean expectedSeverityMatches, final int actualSeverity, final boolean expectedMessageMatches, final String actualMessage) {
  StringBuilder errorMessage = new StringBuilder(MINIMAL_STRINGBUILDER_CAPACITY);
  if (issueMustBeFound && !issueFound) {
    errorMessage.append("Expected issue not found. Code '" + issueCode + "'\n");
  } else if (!issueMustBeFound && issueFound) {
    errorMessage.append("There should be no issue with the code '" + issueCode + DOT_AND_LINEBREAK);
  }
  if (issueFound && !expectedMessageMatches) {
    errorMessage.append("Expected message does not match. Expected: '" + message + "', Actual: '" + actualMessage + "'\n");
  }
  // If the expected issue has been found, but the actual severity does not match with expected one
  if (issueMustBeFound && issueFound && !expectedSeverityMatches) {
    errorMessage.append("Severity does not match. Expected: " + CODE_TO_NAME.get(expectedSeverity) + ". Actual: " + CODE_TO_NAME.get(actualSeverity)
        + ".\n");
  }
  // Memorize error message
  if (errorMessage.length() > 0) {
    if (!diagnosticsOnTargetPosition.getChildren().isEmpty()) {
      errorMessage.append("  All issues at this position:\n");
      errorMessage.append(diagnosticsToString(diagnosticsOnTargetPosition, false));
    }
    memorizeErrorOnPosition(pos, errorMessage.toString());
  }
}
 
Example #24
Source File: DeclarativeValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testWarningWithCode() {
	AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
		@Check
		public void foo(Object x) {
			warning(
					"Error Message", 
					EcorePackage.Literals.ENAMED_ELEMENT__NAME,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
					"42");
		}
	};
	BasicDiagnostic chain = new BasicDiagnostic();
	test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
	assertEquals(1, chain.getChildren().size());

	Diagnostic diag = chain.getChildren().get(0);
	assertEquals("Error Message", diag.getMessage());
	assertEquals(0, diag.getCode());
	assertTrue(diag instanceof FeatureBasedDiagnostic);
	assertEquals("42", ((FeatureBasedDiagnostic)diag).getIssueCode());
	assertEquals(Diagnostic.WARNING, diag.getSeverity());
}
 
Example #25
Source File: DeclarativeValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testWarning() {
	AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
		@Check
		public void foo(Object x) {
			warning("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME);
		}
	};
	BasicDiagnostic chain = new BasicDiagnostic();
	test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
	assertEquals(1, chain.getChildren().size());

	Diagnostic diag = chain.getChildren().get(0);
	assertEquals("Error Message", diag.getMessage());
	assertEquals(EcorePackage.eINSTANCE.getEClass().toString(), diag.getSource());
	assertEquals(Diagnostic.WARNING, diag.getSeverity());
}
 
Example #26
Source File: DeclarativeValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testErrorWithCode() {
	AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
		@Check
		public void foo(Object x) {
			error(
					"Error Message", 
					EcorePackage.Literals.ENAMED_ELEMENT__NAME,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
					"42");
		}
	};
	BasicDiagnostic chain = new BasicDiagnostic();
	test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
	assertEquals(1, chain.getChildren().size());

	Diagnostic diag = chain.getChildren().get(0);
	assertEquals("Error Message", diag.getMessage());
	assertEquals(0, diag.getCode());
	assertTrue(diag instanceof FeatureBasedDiagnostic);
	assertEquals("42", ((FeatureBasedDiagnostic)diag).getIssueCode());
	assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
 
Example #27
Source File: DeclarativeValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testErrorWithSource() {
	AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
		@Check
		public void foo(Object x) {
			error(
					"Error Message", 
					EcorePackage.eINSTANCE.getEAnnotation(), 
					EcorePackage.Literals.ENAMED_ELEMENT__NAME,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
		}
	};
	BasicDiagnostic chain = new BasicDiagnostic();
	test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
	assertEquals(1, chain.getChildren().size());

	Diagnostic diag = chain.getChildren().get(0);
	assertEquals("Error Message", diag.getMessage());
	assertEquals(EcorePackage.eINSTANCE.getEAnnotation().toString(), diag.getSource());
	assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
 
Example #28
Source File: DeclarativeValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testError() {
	AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
		@Check
		public void foo(Object x) {
			error("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME);
		}
	};
	BasicDiagnostic chain = new BasicDiagnostic();
	test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
	assertEquals(1, chain.getChildren().size());

	Diagnostic diag = chain.getChildren().get(0);
	assertEquals("Error Message", diag.getMessage());
	assertEquals(EcorePackage.eINSTANCE.getEClass().toString(), diag.getSource());
	assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
 
Example #29
Source File: AbstractCompositeValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug_279962() {
	EValidator validator = registry.getEValidator(pack);
	assertTrue(validator instanceof CompositeEValidator);
	CompositeEValidator composite = (CompositeEValidator) validator;
	
	int prevSize = composite.getContents().size();
	
	get(Val_279962_01.class);
	get(Val_279962_04.class);
	assertEquals(prevSize + 2, composite.getContents().size());
	assertNotNull(validator);
	Resource resource = get(XtextResource.class);
	Model model = EnumRulesTestLanguageFactory.eINSTANCE.createModel();
	resource.getContents().add(model);
	// do not expect an exception
	validator.validate(model, new BasicDiagnostic(), null);
	assertEquals(prevSize + 4, composite.getContents().size());
}
 
Example #30
Source File: CompositeEValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/** Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=396726 */
@Test
public void testNoShortCircuiting() {
	CompositeEValidator compositeValidator = new CompositeEValidator();
	compositeValidator.setEqualitySupportProvider(CompositeEValidator.EValidatorEqualitySupport::new);
	assertEquals(1, compositeValidator.getContents().size());

	compositeValidator.addValidator(EcoreValidator.INSTANCE);
	assertEquals(2, compositeValidator.getContents().size());

	TestEcoreValidator testValidator = new TestEcoreValidator();
	compositeValidator.addValidator(testValidator);
	assertEquals(3, compositeValidator.getContents().size());
	
	compositeValidator.validate(EcoreFactory.eINSTANCE.createEClass(), new BasicDiagnostic(), null);
	assertTrue(testValidator.wasCalled());
}