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

The following examples show how to use org.eclipse.emf.common.util.Diagnostic. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 2
Source Project: bonita-studio   Source File: ValidateAction.java    License: 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 3
Source Project: bonita-studio   Source File: ModelValidator.java    License: 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 4
Source Project: neoscada   Source File: VisualInterfaceEditor.java    License: 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 5
/**
 * {@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 Project: dsl-devkit   Source File: DefaultCheckImpl.java    License: 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 Project: neoscada   Source File: ConfigurationEditor.java    License: 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 Project: M2Doc   Source File: M2DocEvaluator.java    License: 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 Project: neoscada   Source File: DeploymentEditor.java    License: 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 Project: bonita-studio   Source File: ValidateAction.java    License: 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
@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
/**
 * 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 Project: neoscada   Source File: ProfileEditor.java    License: 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 Project: neoscada   Source File: ProfileEditor.java    License: 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 Project: neoscada   Source File: OsgiEditor.java    License: 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
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 Project: neoscada   Source File: WorldEditor.java    License: 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 Project: xtext-core   Source File: XtextValidationTest.java    License: 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 Project: neoscada   Source File: MemoryEditor.java    License: 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 Project: dsl-devkit   Source File: AbstractValidationTest.java    License: 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 Project: ifml-editor   Source File: CoreEditor.java    License: 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
/**
 * {@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
/**
 * {@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
@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 Project: xtext-core   Source File: XtextValidator.java    License: 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 Project: neoscada   Source File: GlobalizeEditor.java    License: 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 Project: neoscada   Source File: ComponentEditor.java    License: 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 Project: fixflow   Source File: PlaneImpl.java    License: 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 29
@Override
public void convertValidatorDiagnostic(Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
	super.convertValidatorDiagnostic(diagnostic, new IAcceptor<Issue>() {
		@Override
		public void accept(Issue t) {
			if (!N4JSLanguageConstants.DEFAULT_SUPPRESSED_ISSUE_CODES_FOR_TESTS.contains(t.getCode())) {
				acceptor.accept(t);
			}
		}
	});
}
 
Example 30
Source Project: n4js   Source File: SemverResourceValidator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** Copied from parent class to change language to {@code SemverGlobals.LANGUAGE_NAME} */
@Override
protected void validate(Resource resource, EObject eObject, CheckMode mode, CancelIndicator monitor,
		IAcceptor<Issue> acceptor) {
	try {
		Map<Object, Object> options = Maps.newHashMap();
		options.put(CheckMode.KEY, mode);
		options.put(CancelableDiagnostician.CANCEL_INDICATOR, monitor);
		// disable concrete syntax validation, since a semantic model that has been parsed
		// from the concrete syntax always complies with it - otherwise there are parse errors.
		options.put(ConcreteSyntaxEValidator.DISABLE_CONCRETE_SYNTAX_EVALIDATOR, Boolean.TRUE);
		// see EObjectValidator.getRootEValidator(Map<Object, Object>)
		options.put(EValidator.class, diagnostician);
		options.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, SemverGlobals.LANGUAGE_NAME);

		Diagnostic diagnostic = diagnostician.validate(eObject, options);
		if (!diagnostic.getChildren().isEmpty()) {
			for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
				issueFromEValidatorDiagnostic(childDiagnostic, acceptor);
			}
		} else {
			issueFromEValidatorDiagnostic(diagnostic, acceptor);
		}
	} catch (RuntimeException e) {
		operationCanceledManager.propagateAsErrorIfCancelException(e);
	}
}