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

The following examples show how to use org.eclipse.emf.common.util.Diagnostic. 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: 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 #2
Source File: VisualInterfaceEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel ()
{
    URI resourceURI = EditUIUtil.getURI ( getEditorInput () );
    Exception exception = null;
    Resource resource = null;
    try
    {
        // Load the resource through the editing domain.
        //
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, true );
    }
    catch ( Exception e )
    {
        exception = e;
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, false );
    }

    Diagnostic diagnostic = analyzeResourceProblems ( resource, exception );
    if ( diagnostic.getSeverity () != Diagnostic.OK )
    {
        resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) );
    }
    editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter );
}
 
Example #3
Source File: ValidateAction.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
private static void validate(DiagramEditPart diagramEditPart, View view) {
	IFile target = view.eResource() != null ? WorkspaceSynchronizer.getFile(view.eResource()) : null;
	if (target != null) {
		ProcessMarkerNavigationProvider.deleteMarkers(target);
	}
	Diagnostic diagnostic = runEMFValidator(view);
	createMarkers(target, diagnostic, diagramEditPart);
	IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance()
			.newValidator(EvaluationMode.BATCH);
	validator.setIncludeLiveConstraints(true);
	if (view.isSetElement() && view.getElement() != null) {
		IStatus status = validator.validate(view.getElement());
		createMarkers(target, status, diagramEditPart);
	}
}
 
Example #4
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 #5
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 #6
Source File: DefaultCheckImpl.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets a numeric value mapped to a given {@link Severity}. Severities are mapped to
 * <ul>
 * <li>{@link Diagnostic#ERROR}
 * <li>{@link Diagnostic#WARNING}
 * <li>{@link Diagnostic#INFO}
 * </ul>
 *
 * @param severity
 *          the issue severity
 * @return the numeric value representing a severity
 */
protected int toDiagnosticSeverity(final Severity severity) {
  int diagnosticSeverity = -1;
  switch (severity) {
  case ERROR:
    diagnosticSeverity = Diagnostic.ERROR;
    break;
  case WARNING:
    diagnosticSeverity = Diagnostic.WARNING;
    break;
  case INFO:
    diagnosticSeverity = Diagnostic.INFO;
    break;
  default:
    throw new IllegalArgumentException("Unknow severity " + severity); //$NON-NLS-1$
  }
  return diagnosticSeverity;
}
 
Example #7
Source File: ConfigurationEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel ()
{
    URI resourceURI = EditUIUtil.getURI ( getEditorInput () );
    Exception exception = null;
    Resource resource = null;
    try
    {
        // Load the resource through the editing domain.
        //
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, true );
    }
    catch ( Exception e )
    {
        exception = e;
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, false );
    }

    Diagnostic diagnostic = analyzeResourceProblems ( resource, exception );
    if ( diagnostic.getSeverity () != Diagnostic.OK )
    {
        resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) );
    }
    editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter );
}
 
Example #8
Source File: M2DocEvaluator.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public XWPFParagraph caseLink(Link link) {
    XWPFParagraph currentParagraph = currentGeneratedParagraph;
    if (hasError(link)) {
        currentParagraph = insertQuerySyntaxMessages(currentParagraph, link, INVALID_LINK_STATEMENT);
    } else {
        final EvaluationResult nameResult = evaluator.eval(link.getName(), variablesStack.peek());
        if (nameResult.getDiagnostic().getSeverity() != Diagnostic.OK) {
            currentParagraph = insertQueryEvaluationMessages(currentParagraph, link, nameResult.getDiagnostic());
        } else {
            final EvaluationResult textResult = evaluator.eval(link.getText(), variablesStack.peek());
            if (nameResult.getDiagnostic().getSeverity() != Diagnostic.OK) {
                currentParagraph = insertQueryEvaluationMessages(currentParagraph, link,
                        textResult.getDiagnostic());
            } else {
                bookmarkManager.insertReference(currentParagraph, nameResult.getResult().toString(),
                        textResult.getResult().toString());
            }
        }
    }

    return currentParagraph;
}
 
Example #9
Source File: DeploymentEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel ()
{
    URI resourceURI = EditUIUtil.getURI ( getEditorInput (), editingDomain.getResourceSet ().getURIConverter () );
    Exception exception = null;
    Resource resource = null;
    try
    {
        // Load the resource through the editing domain.
        //
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, true );
    }
    catch ( Exception e )
    {
        exception = e;
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, false );
    }

    Diagnostic diagnostic = analyzeResourceProblems ( resource, exception );
    if ( diagnostic.getSeverity () != Diagnostic.OK )
    {
        resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) );
    }
    editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter );
}
 
Example #10
Source File: ValidateAction.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
private static void createMarkers(IFile target, Diagnostic emfValidationStatus, DiagramEditPart diagramEditPart) {
	if (emfValidationStatus.getSeverity() == Diagnostic.OK) {
		return;
	}
	final Diagnostic rootStatus = emfValidationStatus;
	List allDiagnostics = new ArrayList();
	ProcessDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new ProcessDiagramEditorUtil.LazyElement2ViewMap(
			diagramEditPart.getDiagramView(),
			collectTargetElements(rootStatus, new HashSet<EObject>(), allDiagnostics));
	for (Iterator it = emfValidationStatus.getChildren().iterator(); it.hasNext();) {
		Diagnostic nextDiagnostic = (Diagnostic) it.next();
		List data = nextDiagnostic.getData();
		if (data != null && !data.isEmpty() && data.get(0) instanceof EObject) {
			EObject element = (EObject) data.get(0);
			View view = ProcessDiagramEditorUtil.findView(diagramEditPart, element, element2ViewMap);
			addMarker(diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view),
					EMFCoreUtil.getQualifiedName(element, true), nextDiagnostic.getMessage(),
					diagnosticToStatusSeverity(nextDiagnostic.getSeverity()));
		}
	}
}
 
Example #11
Source File: SCTDiagnosticConverterImpl.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void convertValidatorDiagnostic(final Diagnostic diagnostic, final IAcceptor<Issue> acceptor) {
	super.convertValidatorDiagnostic(diagnostic, new IAcceptor<Issue>() {
		@Override
		public void accept(Issue t) {
			boolean notAccepted = true;
			if (diagnostic.getData().get(0) instanceof EObject) {
				EObject eObject = (EObject) diagnostic.getData().get(0);
				if (eObject != null && eObject.eResource() != null) {
					if (NodeModelUtils.getNode(eObject) != null) {
						eObject = EcoreUtil2.getContainerOfType(eObject, SpecificationElement.class);
					}
					if (eObject != null && eObject.eResource() != null) {
						acceptor.accept(issueCreator.create(t, eObject.eResource().getURIFragment(eObject)));
						notAccepted = false;
					}
				}
			}
			if (notAccepted) {
				acceptor.accept(t);
			}
		}
	});
}
 
Example #12
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 #13
Source File: ProfileEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel ()
{
    URI resourceURI = EditUIUtil.getURI ( getEditorInput (), editingDomain.getResourceSet ().getURIConverter () );
    Exception exception = null;
    Resource resource = null;
    try
    {
        // Load the resource through the editing domain.
        //
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, true );
    }
    catch ( Exception e )
    {
        exception = e;
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, false );
    }

    Diagnostic diagnostic = analyzeResourceProblems ( resource, exception );
    if ( diagnostic.getSeverity () != Diagnostic.OK )
    {
        resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) );
    }
    editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter );
}
 
Example #14
Source File: ProfileEditor.java    From neoscada with Eclipse Public License 1.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 )
{
    boolean hasErrors = !resource.getErrors ().isEmpty ();
    if ( hasErrors || !resource.getWarnings ().isEmpty () )
    {
        BasicDiagnostic basicDiagnostic = new BasicDiagnostic ( hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "org.eclipse.scada.configuration.world.editor", //$NON-NLS-1$
        0, getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
        new Object[] { exception == null ? (Object)resource : exception } );
        basicDiagnostic.merge ( EcoreUtil.computeDiagnostic ( resource, true ) );
        return basicDiagnostic;
    }
    else if ( exception != null )
    {
        return new BasicDiagnostic ( Diagnostic.ERROR, "org.eclipse.scada.configuration.world.editor", //$NON-NLS-1$
        0, getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
        new Object[] { exception } );
    }
    else
    {
        return Diagnostic.OK_INSTANCE;
    }
}
 
Example #15
Source File: OsgiEditor.java    From neoscada with Eclipse Public License 1.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 )
{
    boolean hasErrors = !resource.getErrors ().isEmpty ();
    if ( hasErrors || !resource.getWarnings ().isEmpty () )
    {
        BasicDiagnostic basicDiagnostic = new BasicDiagnostic ( hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "org.eclipse.scada.configuration.world.editor", //$NON-NLS-1$
        0, getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
        new Object[] { exception == null ? (Object)resource : exception } );
        basicDiagnostic.merge ( EcoreUtil.computeDiagnostic ( resource, true ) );
        return basicDiagnostic;
    }
    else if ( exception != null )
    {
        return new BasicDiagnostic ( Diagnostic.ERROR, "org.eclipse.scada.configuration.world.editor", //$NON-NLS-1$
        0, getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
        new Object[] { exception } );
    }
    else
    {
        return Diagnostic.OK_INSTANCE;
    }
}
 
Example #16
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void diagnose(Diagnostic diagnostic, URI[] expectedUnresolvedProxies) {
	if (diagnostic.getChildren().isEmpty()) {
		if (diagnostic.getSeverity() != Diagnostic.OK) {
			if (diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_PROXY_RESOLVES) {
				EObject proxy = (EObject) diagnostic.getData().get(2); // magic number ...
				if (org.eclipse.xtext.util.Arrays.contains(expectedUnresolvedProxies, EcoreUtil.getURI(proxy))) {
					return;
				}
			}
			assertEquals(String.valueOf(diagnostic), diagnostic.getSeverity() == Diagnostic.OK);
		}
	} else {
		for (Diagnostic child : diagnostic.getChildren()) {
			diagnose(child, expectedUnresolvedProxies);
		}
	}
}
 
Example #17
Source File: WorldEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel ()
{
    URI resourceURI = EditUIUtil.getURI ( getEditorInput (), editingDomain.getResourceSet ().getURIConverter () );
    Exception exception = null;
    Resource resource = null;
    try
    {
        // Load the resource through the editing domain.
        //
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, true );
    }
    catch ( Exception e )
    {
        exception = e;
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, false );
    }

    Diagnostic diagnostic = analyzeResourceProblems ( resource, exception );
    if ( diagnostic.getSeverity () != Diagnostic.OK )
    {
        resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) );
    }
    editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter );
}
 
Example #18
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testBug322875_04() throws Exception {
	String testGrammarNsURI = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
			" import 'http://www.eclipse.org/emf/2002/Ecore'  " +
			"Model returns EClass: name=ID;";
	String testGrammarPlatformPlugin = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
			" import 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore'  " +
			"Model returns EClass: name=ID;";
	XtextResource resourceOk = getResourceFromString(testGrammarNsURI);
	XtextResource resourceOk2 = (XtextResource) resourceOk.getResourceSet().createResource(URI.createURI("unused.xtext"));
	resourceOk2.load(new StringInputStream(testGrammarPlatformPlugin), null);
	Diagnostic diagOK = Diagnostician.INSTANCE.validate(resourceOk.getContents().get(0));
	assertNotNull("diag", diagOK);
	assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
	diagOK = Diagnostician.INSTANCE.validate(resourceOk2.getContents().get(0));
	assertNotNull("diag", diagOK);
	assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
}
 
Example #19
Source File: MemoryEditor.java    From neoscada with Eclipse Public License 1.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 )
{
    boolean hasErrors = !resource.getErrors ().isEmpty ();
    if ( hasErrors || !resource.getWarnings ().isEmpty () )
    {
        BasicDiagnostic basicDiagnostic = new BasicDiagnostic ( hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "org.eclipse.scada.configuration.memory.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, "org.eclipse.scada.configuration.memory.editor", 0, getString ( "_UI_CreateModelError_message", resource.getURI () ), new Object[] { exception } );
    }
    else
    {
        return Diagnostic.OK_INSTANCE;
    }
}
 
Example #20
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 List<Resource.Diagnostic> 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.isEmpty()) {
      errorMessage.append("  All issues at this position:\n");
      errorMessage.append(diagnosticsToString(diagnosticsOnTargetPosition, false));
    }
    memorizeErrorOnPosition(pos, errorMessage.toString());
  }
}
 
Example #21
Source File: CoreEditor.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel() {
	URI resourceURI = EditUIUtil.getURI(getEditorInput());
	Exception exception = null;
	Resource resource = null;
	try {
		// Load the resource through the editing domain.
		//
		resource = editingDomain.getResourceSet().getResource(resourceURI, true);
	}
	catch (Exception e) {
		exception = e;
		resource = editingDomain.getResourceSet().getResource(resourceURI, false);
	}

	Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
	if (diagnostic.getSeverity() != Diagnostic.OK) {
		resourceToDiagnosticMap.put(resource,  analyzeResourceProblems(resource, exception));
	}
	editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter);
}
 
Example #22
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 #23
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 #24
Source File: XtextDiagnosticConverter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Severity getSeverity(Diagnostic diagnostic) {
	Severity result = super.getSeverity(diagnostic);
	String issueCode = getIssueCode(diagnostic);
	if (result == Severity.WARNING && issueCode != null) {
		// only warnings can be suppressed
		EObject causer = getCauser(diagnostic);
		if (causer != null) {
			if (isMarkedAsIgnored(causer, issueCode)) {
				return null;
			}
			if (!(causer instanceof AbstractRule)) {
				AbstractRule rule = GrammarUtil.containingRule(causer);
				if (rule != null && isMarkedAsIgnored(rule, issueCode)) {
					return null;
				}
			}
			Grammar grammar = GrammarUtil.getGrammar(causer);
			if (grammar != null && isMarkedAsIgnored(grammar, issueCode)) {
				return null;
			}
		}
	}
	return result;
}
 
Example #25
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void createMessageForNameClashes(Multimap<String, ENamedElement> nameToElement) {
	for(Entry<String, Collection<ENamedElement>> entry: nameToElement.asMap().entrySet()) {
		if (entry.getValue().size() > 1) {
			if (!Iterables.isEmpty(Iterables.filter(entry.getValue(), EStructuralFeature.class))
					&&!Iterables.isEmpty(Iterables.filter(entry.getValue(), EClassifier.class))) {
				String constantName = entry.getKey();
				String message = "Name clash in generated code: '" + constantName + "'.";
				for(ENamedElement element: entry.getValue()) {
					String myMessage = message;
					if (element.getName().indexOf('_') >= 0) {
						myMessage = myMessage + " Try to avoid underscores in names to prevent conflicts.";
					}
					createMessageForSource(myMessage, null, Diagnostic.ERROR, element, getMessageAcceptor());
				}
			}
		}
	}
}
 
Example #26
Source File: GlobalizeEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel ()
{
    URI resourceURI = EditUIUtil.getURI ( getEditorInput (), editingDomain.getResourceSet ().getURIConverter () );
    Exception exception = null;
    Resource resource = null;
    try
    {
        // Load the resource through the editing domain.
        //
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, true );
    }
    catch ( Exception e )
    {
        exception = e;
        resource = editingDomain.getResourceSet ().getResource ( resourceURI, false );
    }

    Diagnostic diagnostic = analyzeResourceProblems ( resource, exception );
    if ( diagnostic.getSeverity () != Diagnostic.OK )
    {
        resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) );
    }
    editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter );
}
 
Example #27
Source File: ComponentEditor.java    From neoscada with Eclipse Public License 1.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 )
{
    boolean hasErrors = !resource.getErrors ().isEmpty ();
    if ( hasErrors || !resource.getWarnings ().isEmpty () )
    {
        BasicDiagnostic basicDiagnostic = new BasicDiagnostic ( hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "org.eclipse.scada.configuration.component.editor", //$NON-NLS-1$
        0, getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
        new Object[] { exception == null ? (Object)resource : exception } );
        basicDiagnostic.merge ( EcoreUtil.computeDiagnostic ( resource, true ) );
        return basicDiagnostic;
    }
    else if ( exception != null )
    {
        return new BasicDiagnostic ( Diagnostic.ERROR, "org.eclipse.scada.configuration.component.editor", //$NON-NLS-1$
        0, getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
        new Object[] { exception } );
    }
    else
    {
        return Diagnostic.OK_INSTANCE;
    }
}
 
Example #28
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 #29
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverrideFinal_1() throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" + 
			"generate supergrammar \"http://org.xtext.supergrammar\"\n" + 
			"@Final\n" + 
			"RuleFinal:name=ID;\n" + 
			"Rule: name=ID;","superGrammar.xtext", rs);
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.xtext.Supergrammar\n" +
			"generate bar \"http://org.xtext.Bar\"\n" + 
			"@Override Rule: name=ID;",  "foo.xtext", rs);
	Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
	List<Diagnostic> issues = diag.getChildren();
	assertEquals(issues.toString(), 0, issues.size());
}
 
Example #30
Source File: JdbcExample.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * Prints diagnostics with indentation.
 * <!-- end-user-doc -->
 * @param diagnostic the diagnostic to print.
 * @param indent the indentation for printing.
 * @generated
 */
protected static void printDiagnostic ( Diagnostic diagnostic, String indent )
{
    System.out.print ( indent );
    System.out.println ( diagnostic.getMessage () );
    for ( Diagnostic child : diagnostic.getChildren () )
    {
        printDiagnostic ( child, indent + "  " ); //$NON-NLS-1$
    }
}