Java 类org.eclipse.emf.ecore.util.EcoreValidator 实例源码

项目:xtext-core    文件:CompositeEValidatorTest.java   
/** Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=396726 */
@Test public void testNoShortCircuiting() {
    CompositeEValidator compositeValidator = new CompositeEValidator();
    compositeValidator.setEqualitySupportProvider(new Provider<CompositeEValidator.EValidatorEqualitySupport>() {
        @Override
        public EValidatorEqualitySupport get() {
            return new CompositeEValidator.EValidatorEqualitySupport();
        }
    });
    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());
}
项目:xtext-core    文件:XtextValidationTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    EValidator.Registry.INSTANCE.put(EcorePackage.eINSTANCE, EcoreValidator.INSTANCE);
        File tempFile = File.createTempFile("XtextValidationTest", ".ecore");
        tempFile.deleteOnExit();
        Files.write("<?xml version='1.0' encoding='UTF-8'?>" +
                "<ecore:EPackage xmi:version='2.0' xmlns:xmi='http://www.omg.org/XMI'"+
                "                xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
                "                xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'"+
                "                name='XtextValidationBugs'"+
                "                nsURI='http://XtextValidationBugs'"+
                "                nsPrefix='XtextValidationBugs'>"+
                "  <eClassifiers xsi:type='ecore:EClass' name='Bug322875'>"+
                "    <eStructuralFeatures xsi:type='ecore:EReference' name='referencesETypeFromClasspathPackage' eType='ecore:EClass classpath:/org/eclipse/xtext/Xtext.ecore#//Grammar'/>"+
                "  </eClassifiers>"+
                "</ecore:EPackage>"
                , tempFile, StandardCharsets.UTF_8);
        xtextValidationTest_ecore = tempFile.toURI().toURL();
}
项目:DarwinSPL    文件:HyexpressionMarkerHelper.java   
/**
 * <p>
 * Removes all markers that were caused by the given object from the resource.
 * Markers are created and removed asynchronously. Thus, they may not appear when
 * calls to this method return. But, the order of marker additions and removals is
 * preserved.
 * </p>
 * 
 * @param resource The resource where to delete markers from
 * @param causingObject The cause of the problems to remove
 */
public void unmark(Resource resource, final EObject causingObject) {
    final IFile file = getFile(resource);
    if (file == null) {
        return;
    }
    final String markerID = getMarkerID(eu.hyvar.feature.expression.resource.hyexpression.HyexpressionEProblemType.UNKNOWN);
    final String causingObjectURI = getObjectURI(causingObject);
    if (causingObjectURI == null) {
        return;
    }
    COMMAND_QUEUE.addCommand(new eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionCommand<Object>() {
        public boolean execute(Object context) {
            try {
                IMarker[] markers = file.findMarkers(markerID, true, IResource.DEPTH_ZERO);
                for (IMarker marker : markers) {
                    if (causingObjectURI.equals(marker.getAttribute(EcoreValidator.URI_ATTRIBUTE))) {
                        marker.delete();
                    }
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HymanifestMarkerHelper.java   
/**
 * <p>
 * Removes all markers that were caused by the given object from the resource.
 * Markers are created and removed asynchronously. Thus, they may not appear when
 * calls to this method return. But, the order of marker additions and removals is
 * preserved.
 * </p>
 * 
 * @param resource The resource where to delete markers from
 * @param causingObject The cause of the problems to remove
 */
public void unmark(Resource resource, final EObject causingObject) {
    final IFile file = getFile(resource);
    if (file == null) {
        return;
    }
    final String markerID = getMarkerID(eu.hyvar.mspl.manifest.resource.hymanifest.HymanifestEProblemType.UNKNOWN);
    final String causingObjectURI = getObjectURI(causingObject);
    if (causingObjectURI == null) {
        return;
    }
    COMMAND_QUEUE.addCommand(new eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestCommand<Object>() {
        public boolean execute(Object context) {
            try {
                IMarker[] markers = file.findMarkers(markerID, true, IResource.DEPTH_ZERO);
                for (IMarker marker : markers) {
                    if (causingObjectURI.equals(marker.getAttribute(EcoreValidator.URI_ATTRIBUTE))) {
                        marker.delete();
                    }
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HymappingMarkerHelper.java   
/**
 * <p>
 * Removes all markers that were caused by the given object from the resource.
 * Markers are created and removed asynchronously. Thus, they may not appear when
 * calls to this method return. But, the order of marker additions and removals is
 * preserved.
 * </p>
 * 
 * @param resource The resource where to delete markers from
 * @param causingObject The cause of the problems to remove
 */
public void unmark(Resource resource, final EObject causingObject) {
    final IFile file = getFile(resource);
    if (file == null) {
        return;
    }
    final String markerID = getMarkerID(eu.hyvar.feature.mapping.resource.hymapping.HymappingEProblemType.UNKNOWN);
    final String causingObjectURI = getObjectURI(causingObject);
    if (causingObjectURI == null) {
        return;
    }
    COMMAND_QUEUE.addCommand(new eu.hyvar.feature.mapping.resource.hymapping.IHymappingCommand<Object>() {
        public boolean execute(Object context) {
            try {
                IMarker[] markers = file.findMarkers(markerID, true, IResource.DEPTH_ZERO);
                for (IMarker marker : markers) {
                    if (causingObjectURI.equals(marker.getAttribute(EcoreValidator.URI_ATTRIBUTE))) {
                        marker.delete();
                    }
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HyconstraintsMarkerHelper.java   
/**
 * <p>
 * Removes all markers that were caused by the given object from the resource.
 * Markers are created and removed asynchronously. Thus, they may not appear when
 * calls to this method return. But, the order of marker additions and removals is
 * preserved.
 * </p>
 * 
 * @param resource The resource where to delete markers from
 * @param causingObject The cause of the problems to remove
 */
public void unmark(Resource resource, final EObject causingObject) {
    final IFile file = getFile(resource);
    if (file == null) {
        return;
    }
    final String markerID = getMarkerID(eu.hyvar.feature.constraint.resource.hyconstraints.HyconstraintsEProblemType.UNKNOWN);
    final String causingObjectURI = getObjectURI(causingObject);
    if (causingObjectURI == null) {
        return;
    }
    COMMAND_QUEUE.addCommand(new eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsCommand<Object>() {
        public boolean execute(Object context) {
            try {
                IMarker[] markers = file.findMarkers(markerID, true, IResource.DEPTH_ZERO);
                for (IMarker marker : markers) {
                    if (causingObjectURI.equals(marker.getAttribute(EcoreValidator.URI_ATTRIBUTE))) {
                        marker.delete();
                    }
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HydatavalueMarkerHelper.java   
/**
 * <p>
 * Removes all markers that were caused by the given object from the resource.
 * Markers are created and removed asynchronously. Thus, they may not appear when
 * calls to this method return. But, the order of marker additions and removals is
 * preserved.
 * </p>
 * 
 * @param resource The resource where to delete markers from
 * @param causingObject The cause of the problems to remove
 */
public void unmark(Resource resource, final EObject causingObject) {
    final IFile file = getFile(resource);
    if (file == null) {
        return;
    }
    final String markerID = getMarkerID(eu.hyvar.dataValues.resource.hydatavalue.HydatavalueEProblemType.UNKNOWN);
    final String causingObjectURI = getObjectURI(causingObject);
    if (causingObjectURI == null) {
        return;
    }
    COMMAND_QUEUE.addCommand(new eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueCommand<Object>() {
        public boolean execute(Object context) {
            try {
                IMarker[] markers = file.findMarkers(markerID, true, IResource.DEPTH_ZERO);
                for (IMarker marker : markers) {
                    if (causingObjectURI.equals(marker.getAttribute(EcoreValidator.URI_ATTRIBUTE))) {
                        marker.delete();
                    }
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:DwprofileMarkerHelper.java   
/**
 * <p>
 * Removes all markers that were caused by the given object from the resource.
 * Markers are created and removed asynchronously. Thus, they may not appear when
 * calls to this method return. But, the order of marker additions and removals is
 * preserved.
 * </p>
 * 
 * @param resource The resource where to delete markers from
 * @param causingObject The cause of the problems to remove
 */
public void unmark(Resource resource, final EObject causingObject) {
    final IFile file = getFile(resource);
    if (file == null) {
        return;
    }
    final String markerID = getMarkerID(de.darwinspl.preferences.resource.dwprofile.DwprofileEProblemType.UNKNOWN);
    final String causingObjectURI = getObjectURI(causingObject);
    if (causingObjectURI == null) {
        return;
    }
    COMMAND_QUEUE.addCommand(new de.darwinspl.preferences.resource.dwprofile.IDwprofileCommand<Object>() {
        public boolean execute(Object context) {
            try {
                IMarker[] markers = file.findMarkers(markerID, true, IResource.DEPTH_ZERO);
                for (IMarker marker : markers) {
                    if (causingObjectURI.equals(marker.getAttribute(EcoreValidator.URI_ATTRIBUTE))) {
                        marker.delete();
                    }
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:xtext-core    文件:XtextValidator.java   
public boolean createMessageForSource(Diagnostic diagnostic, EObject object, ValidationMessageAcceptor acceptor) {
    String code = XtextValidator.class.getName() + ".PackageValidation." + diagnostic.getCode();
    int severity = diagnostic.getSeverity();
    if (diagnostic.getCode() == EcoreValidator.UNIQUE_CLASSIFIER_NAMES || diagnostic.getCode() == EcoreValidator.UNIQUE_FEATURE_NAMES)
        severity = Diagnostic.ERROR;
    String message = diagnostic.getMessage();
    return createMessageForSource(message, code, severity, object, acceptor);
}
项目:xtext-core    文件:XtextValidator.java   
public void doCreateMessage(Diagnostic diagnostic, EObject object, EStructuralFeature feature, ValidationMessageAcceptor acceptor) {
    String code = XtextValidator.class.getName() + ".PackageValidation." + diagnostic.getCode();
    int severity = diagnostic.getSeverity();
    if (diagnostic.getCode() == EcoreValidator.UNIQUE_CLASSIFIER_NAMES || diagnostic.getCode() == EcoreValidator.UNIQUE_FEATURE_NAMES)
        severity = Diagnostic.ERROR;
    String message = diagnostic.getMessage();
    doCreateMessage(message, code, severity, object, feature, acceptor);
}
项目:eclipse-avro    文件:EcorePackageImpl.java   
/**
 * Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends.
 * 
 * <p>This method is used to initialize {@link EcorePackage#eINSTANCE} when that field is accessed.
 * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @see #eNS_URI
 * @see #createPackageContents()
 * @see #initializePackageContents()
 * @generated
 */
public static EcorePackage init()
{
  if (isInited) return (EcorePackage)EPackage.Registry.INSTANCE.getEPackage(EcorePackage.eNS_URI);

  // Obtain or create and register package
  EcorePackageImpl theEcorePackage = (EcorePackageImpl)(EPackage.Registry.INSTANCE.get(eNS_URI) instanceof EcorePackageImpl ? EPackage.Registry.INSTANCE.get(eNS_URI) : new EcorePackageImpl());

  isInited = true;

  // Create package meta-data objects
  theEcorePackage.createPackageContents();

  // Initialize created meta-data
  theEcorePackage.initializePackageContents();

  // Register package validator
  EValidator.Registry.INSTANCE.put
    (theEcorePackage, 
     new EValidator.Descriptor()
     {
       public EValidator getEValidator()
       {
         return EcoreValidator.INSTANCE;
       }
     });


  // Update the registry and return the package
  EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, theEcorePackage);
  return theEcorePackage;
}
项目:clickwatch    文件:EcorePackageImpl.java   
/**
 * Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends.
 * 
 * <p>This method is used to initialize {@link EcorePackage#eINSTANCE} when that field is accessed.
 * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @see #eNS_URI
 * @see #createPackageContents()
 * @see #initializePackageContents()
 * @generated
 */
public static EcorePackage init()
{
  if (isInited) return (EcorePackage)EPackage.Registry.INSTANCE.getEPackage(EcorePackage.eNS_URI);

  // Obtain or create and register package
  EcorePackageImpl theEcorePackage = (EcorePackageImpl)(EPackage.Registry.INSTANCE.get(eNS_URI) instanceof EcorePackageImpl ? EPackage.Registry.INSTANCE.get(eNS_URI) : new EcorePackageImpl());

  isInited = true;

  // Create package meta-data objects
  theEcorePackage.createPackageContents();

  // Initialize created meta-data
  theEcorePackage.initializePackageContents();

  // Register package validator
  EValidator.Registry.INSTANCE.put
    (theEcorePackage, 
     new EValidator.Descriptor()
     {
       public EValidator getEValidator()
       {
         return EcoreValidator.INSTANCE;
       }
     });


  // Update the registry and return the package
  EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, theEcorePackage);
  return theEcorePackage;
}
项目:DarwinSPL    文件:HyexpressionMarkerHelper.java   
protected void createMarkerFromDiagnostic(final IFile file, final eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionTextDiagnostic diagnostic) {
    final eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionProblem problem = diagnostic.getProblem();
    eu.hyvar.feature.expression.resource.hyexpression.HyexpressionEProblemType problemType = problem.getType();
    final String markerID = getMarkerID(problemType);
    COMMAND_QUEUE.addCommand(new eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionCommand<Object>() {
        public boolean execute(Object context) {
            try {
                // if there are too many markers, we do not add new ones
                if (file.findMarkers(markerID, false, IResource.DEPTH_ZERO).length >= MAXIMUM_MARKERS) {
                    return true;
                }

                IMarker marker = file.createMarker(markerID);
                if (problem.getSeverity() == eu.hyvar.feature.expression.resource.hyexpression.HyexpressionEProblemSeverity.ERROR) {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                } else {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                }
                marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage());
                eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionTextDiagnostic textDiagnostic = (eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionTextDiagnostic) diagnostic;
                marker.setAttribute(IMarker.LINE_NUMBER, textDiagnostic.getLine());
                marker.setAttribute(IMarker.CHAR_START, textDiagnostic.getCharStart());
                marker.setAttribute(IMarker.CHAR_END, textDiagnostic.getCharEnd() + 1);
                if (diagnostic instanceof eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionResource.ElementBasedTextDiagnostic) {
                    EObject element = ((eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionResource.ElementBasedTextDiagnostic) diagnostic).getElement();
                    String elementURI = getObjectURI(element);
                    if (elementURI != null) {
                        marker.setAttribute(EcoreValidator.URI_ATTRIBUTE, elementURI);
                    }
                }
                Collection<eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix> quickFixes = textDiagnostic.getProblem().getQuickFixes();
                Collection<Object> sourceIDs = new ArrayList<Object>();
                if (quickFixes != null) {
                    for (eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix quickFix : quickFixes) {
                        if (quickFix != null) {
                            sourceIDs.add(quickFix.getContextAsString());
                        }
                    }
                }
                if (!sourceIDs.isEmpty()) {
                    marker.setAttribute(IMarker.SOURCE_ID, eu.hyvar.feature.expression.resource.hyexpression.util.HyexpressionStringUtil.explode(sourceIDs, "|"));
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HymanifestMarkerHelper.java   
protected void createMarkerFromDiagnostic(final IFile file, final eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestTextDiagnostic diagnostic) {
    final eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestProblem problem = diagnostic.getProblem();
    eu.hyvar.mspl.manifest.resource.hymanifest.HymanifestEProblemType problemType = problem.getType();
    final String markerID = getMarkerID(problemType);
    COMMAND_QUEUE.addCommand(new eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestCommand<Object>() {
        public boolean execute(Object context) {
            try {
                // if there are too many markers, we do not add new ones
                if (file.findMarkers(markerID, false, IResource.DEPTH_ZERO).length >= MAXIMUM_MARKERS) {
                    return true;
                }

                IMarker marker = file.createMarker(markerID);
                if (problem.getSeverity() == eu.hyvar.mspl.manifest.resource.hymanifest.HymanifestEProblemSeverity.ERROR) {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                } else {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                }
                marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage());
                eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestTextDiagnostic textDiagnostic = (eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestTextDiagnostic) diagnostic;
                marker.setAttribute(IMarker.LINE_NUMBER, textDiagnostic.getLine());
                marker.setAttribute(IMarker.CHAR_START, textDiagnostic.getCharStart());
                marker.setAttribute(IMarker.CHAR_END, textDiagnostic.getCharEnd() + 1);
                if (diagnostic instanceof eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestResource.ElementBasedTextDiagnostic) {
                    EObject element = ((eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestResource.ElementBasedTextDiagnostic) diagnostic).getElement();
                    String elementURI = getObjectURI(element);
                    if (elementURI != null) {
                        marker.setAttribute(EcoreValidator.URI_ATTRIBUTE, elementURI);
                    }
                }
                Collection<eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestQuickFix> quickFixes = textDiagnostic.getProblem().getQuickFixes();
                Collection<Object> sourceIDs = new ArrayList<Object>();
                if (quickFixes != null) {
                    for (eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestQuickFix quickFix : quickFixes) {
                        if (quickFix != null) {
                            sourceIDs.add(quickFix.getContextAsString());
                        }
                    }
                }
                if (!sourceIDs.isEmpty()) {
                    marker.setAttribute(IMarker.SOURCE_ID, eu.hyvar.mspl.manifest.resource.hymanifest.util.HymanifestStringUtil.explode(sourceIDs, "|"));
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HymappingMarkerHelper.java   
protected void createMarkerFromDiagnostic(final IFile file, final eu.hyvar.feature.mapping.resource.hymapping.IHymappingTextDiagnostic diagnostic) {
    final eu.hyvar.feature.mapping.resource.hymapping.IHymappingProblem problem = diagnostic.getProblem();
    eu.hyvar.feature.mapping.resource.hymapping.HymappingEProblemType problemType = problem.getType();
    final String markerID = getMarkerID(problemType);
    COMMAND_QUEUE.addCommand(new eu.hyvar.feature.mapping.resource.hymapping.IHymappingCommand<Object>() {
        public boolean execute(Object context) {
            try {
                // if there are too many markers, we do not add new ones
                if (file.findMarkers(markerID, false, IResource.DEPTH_ZERO).length >= MAXIMUM_MARKERS) {
                    return true;
                }

                IMarker marker = file.createMarker(markerID);
                if (problem.getSeverity() == eu.hyvar.feature.mapping.resource.hymapping.HymappingEProblemSeverity.ERROR) {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                } else {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                }
                marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage());
                eu.hyvar.feature.mapping.resource.hymapping.IHymappingTextDiagnostic textDiagnostic = (eu.hyvar.feature.mapping.resource.hymapping.IHymappingTextDiagnostic) diagnostic;
                marker.setAttribute(IMarker.LINE_NUMBER, textDiagnostic.getLine());
                marker.setAttribute(IMarker.CHAR_START, textDiagnostic.getCharStart());
                marker.setAttribute(IMarker.CHAR_END, textDiagnostic.getCharEnd() + 1);
                if (diagnostic instanceof eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingResource.ElementBasedTextDiagnostic) {
                    EObject element = ((eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingResource.ElementBasedTextDiagnostic) diagnostic).getElement();
                    String elementURI = getObjectURI(element);
                    if (elementURI != null) {
                        marker.setAttribute(EcoreValidator.URI_ATTRIBUTE, elementURI);
                    }
                }
                Collection<eu.hyvar.feature.mapping.resource.hymapping.IHymappingQuickFix> quickFixes = textDiagnostic.getProblem().getQuickFixes();
                Collection<Object> sourceIDs = new ArrayList<Object>();
                if (quickFixes != null) {
                    for (eu.hyvar.feature.mapping.resource.hymapping.IHymappingQuickFix quickFix : quickFixes) {
                        if (quickFix != null) {
                            sourceIDs.add(quickFix.getContextAsString());
                        }
                    }
                }
                if (!sourceIDs.isEmpty()) {
                    marker.setAttribute(IMarker.SOURCE_ID, eu.hyvar.feature.mapping.resource.hymapping.util.HymappingStringUtil.explode(sourceIDs, "|"));
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HyconstraintsMarkerHelper.java   
protected void createMarkerFromDiagnostic(final IFile file, final eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsTextDiagnostic diagnostic) {
    final eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsProblem problem = diagnostic.getProblem();
    eu.hyvar.feature.constraint.resource.hyconstraints.HyconstraintsEProblemType problemType = problem.getType();
    final String markerID = getMarkerID(problemType);
    COMMAND_QUEUE.addCommand(new eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsCommand<Object>() {
        public boolean execute(Object context) {
            try {
                // if there are too many markers, we do not add new ones
                if (file.findMarkers(markerID, false, IResource.DEPTH_ZERO).length >= MAXIMUM_MARKERS) {
                    return true;
                }

                IMarker marker = file.createMarker(markerID);
                if (problem.getSeverity() == eu.hyvar.feature.constraint.resource.hyconstraints.HyconstraintsEProblemSeverity.ERROR) {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                } else {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                }
                marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage());
                eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsTextDiagnostic textDiagnostic = (eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsTextDiagnostic) diagnostic;
                marker.setAttribute(IMarker.LINE_NUMBER, textDiagnostic.getLine());
                marker.setAttribute(IMarker.CHAR_START, textDiagnostic.getCharStart());
                marker.setAttribute(IMarker.CHAR_END, textDiagnostic.getCharEnd() + 1);
                if (diagnostic instanceof eu.hyvar.feature.constraint.resource.hyconstraints.mopp.HyconstraintsResource.ElementBasedTextDiagnostic) {
                    EObject element = ((eu.hyvar.feature.constraint.resource.hyconstraints.mopp.HyconstraintsResource.ElementBasedTextDiagnostic) diagnostic).getElement();
                    String elementURI = getObjectURI(element);
                    if (elementURI != null) {
                        marker.setAttribute(EcoreValidator.URI_ATTRIBUTE, elementURI);
                    }
                }
                Collection<eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsQuickFix> quickFixes = textDiagnostic.getProblem().getQuickFixes();
                Collection<Object> sourceIDs = new ArrayList<Object>();
                if (quickFixes != null) {
                    for (eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsQuickFix quickFix : quickFixes) {
                        if (quickFix != null) {
                            sourceIDs.add(quickFix.getContextAsString());
                        }
                    }
                }
                if (!sourceIDs.isEmpty()) {
                    marker.setAttribute(IMarker.SOURCE_ID, eu.hyvar.feature.constraint.resource.hyconstraints.util.HyconstraintsStringUtil.explode(sourceIDs, "|"));
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:HydatavalueMarkerHelper.java   
protected void createMarkerFromDiagnostic(final IFile file, final eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueTextDiagnostic diagnostic) {
    final eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueProblem problem = diagnostic.getProblem();
    eu.hyvar.dataValues.resource.hydatavalue.HydatavalueEProblemType problemType = problem.getType();
    final String markerID = getMarkerID(problemType);
    COMMAND_QUEUE.addCommand(new eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueCommand<Object>() {
        public boolean execute(Object context) {
            try {
                // if there are too many markers, we do not add new ones
                if (file.findMarkers(markerID, false, IResource.DEPTH_ZERO).length >= MAXIMUM_MARKERS) {
                    return true;
                }

                IMarker marker = file.createMarker(markerID);
                if (problem.getSeverity() == eu.hyvar.dataValues.resource.hydatavalue.HydatavalueEProblemSeverity.ERROR) {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                } else {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                }
                marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage());
                eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueTextDiagnostic textDiagnostic = (eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueTextDiagnostic) diagnostic;
                marker.setAttribute(IMarker.LINE_NUMBER, textDiagnostic.getLine());
                marker.setAttribute(IMarker.CHAR_START, textDiagnostic.getCharStart());
                marker.setAttribute(IMarker.CHAR_END, textDiagnostic.getCharEnd() + 1);
                if (diagnostic instanceof eu.hyvar.dataValues.resource.hydatavalue.mopp.HydatavalueResource.ElementBasedTextDiagnostic) {
                    EObject element = ((eu.hyvar.dataValues.resource.hydatavalue.mopp.HydatavalueResource.ElementBasedTextDiagnostic) diagnostic).getElement();
                    String elementURI = getObjectURI(element);
                    if (elementURI != null) {
                        marker.setAttribute(EcoreValidator.URI_ATTRIBUTE, elementURI);
                    }
                }
                Collection<eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueQuickFix> quickFixes = textDiagnostic.getProblem().getQuickFixes();
                Collection<Object> sourceIDs = new ArrayList<Object>();
                if (quickFixes != null) {
                    for (eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueQuickFix quickFix : quickFixes) {
                        if (quickFix != null) {
                            sourceIDs.add(quickFix.getContextAsString());
                        }
                    }
                }
                if (!sourceIDs.isEmpty()) {
                    marker.setAttribute(IMarker.SOURCE_ID, eu.hyvar.dataValues.resource.hydatavalue.util.HydatavalueStringUtil.explode(sourceIDs, "|"));
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:DarwinSPL    文件:DwprofileMarkerHelper.java   
protected void createMarkerFromDiagnostic(final IFile file, final de.darwinspl.preferences.resource.dwprofile.IDwprofileTextDiagnostic diagnostic) {
    final de.darwinspl.preferences.resource.dwprofile.IDwprofileProblem problem = diagnostic.getProblem();
    de.darwinspl.preferences.resource.dwprofile.DwprofileEProblemType problemType = problem.getType();
    final String markerID = getMarkerID(problemType);
    COMMAND_QUEUE.addCommand(new de.darwinspl.preferences.resource.dwprofile.IDwprofileCommand<Object>() {
        public boolean execute(Object context) {
            try {
                // if there are too many markers, we do not add new ones
                if (file.findMarkers(markerID, false, IResource.DEPTH_ZERO).length >= MAXIMUM_MARKERS) {
                    return true;
                }

                IMarker marker = file.createMarker(markerID);
                if (problem.getSeverity() == de.darwinspl.preferences.resource.dwprofile.DwprofileEProblemSeverity.ERROR) {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                } else {
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                }
                marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage());
                de.darwinspl.preferences.resource.dwprofile.IDwprofileTextDiagnostic textDiagnostic = (de.darwinspl.preferences.resource.dwprofile.IDwprofileTextDiagnostic) diagnostic;
                marker.setAttribute(IMarker.LINE_NUMBER, textDiagnostic.getLine());
                marker.setAttribute(IMarker.CHAR_START, textDiagnostic.getCharStart());
                marker.setAttribute(IMarker.CHAR_END, textDiagnostic.getCharEnd() + 1);
                if (diagnostic instanceof de.darwinspl.preferences.resource.dwprofile.mopp.DwprofileResource.ElementBasedTextDiagnostic) {
                    EObject element = ((de.darwinspl.preferences.resource.dwprofile.mopp.DwprofileResource.ElementBasedTextDiagnostic) diagnostic).getElement();
                    String elementURI = getObjectURI(element);
                    if (elementURI != null) {
                        marker.setAttribute(EcoreValidator.URI_ATTRIBUTE, elementURI);
                    }
                }
                Collection<de.darwinspl.preferences.resource.dwprofile.IDwprofileQuickFix> quickFixes = textDiagnostic.getProblem().getQuickFixes();
                Collection<Object> sourceIDs = new ArrayList<Object>();
                if (quickFixes != null) {
                    for (de.darwinspl.preferences.resource.dwprofile.IDwprofileQuickFix quickFix : quickFixes) {
                        if (quickFix != null) {
                            sourceIDs.add(quickFix.getContextAsString());
                        }
                    }
                }
                if (!sourceIDs.isEmpty()) {
                    marker.setAttribute(IMarker.SOURCE_ID, de.darwinspl.preferences.resource.dwprofile.util.DwprofileStringUtil.explode(sourceIDs, "|"));
                }
            } catch (CoreException ce) {
                handleException(ce);
            }
            return true;
        }
    });
}
项目:SPA    文件:BenchmarkController.java   
/**
 * Loads a configuration from the XMI-File specified as parameter
 * {@code confFile}. The configuration is validated using OCL constraints
 * specified in the ECore Model. If the validation fails, an exception is
 * thrown. Otherwise the parsed configuration is returned.
 * 
 * @param confFile
 *            The config-file which should be loaded.
 * @return A {@code ExperimentSetup} instance containing every information
 *         needed to run the benchmarks.
 * @throws BenchmarkException
 *             if the configuration is invalid.
 */
public static ExperimentSetup loadConfigurationFromXMI(String confFile)
{
    ResourceSet load_resourceSet = new ResourceSetImpl();
    load_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
    load_resourceSet.getPackageRegistry().put(SBHModelPackage.eNS_URI, SBHModelPackage.eINSTANCE);
    Resource load_resource = load_resourceSet.getResource(URI.createURI(confFile), true);

    // Add OCL-Validators to EMF
    String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI;
    EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLInvocationDelegateFactory.Global());
    EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLSettingDelegateFactory.Global());
    EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI, new OCLValidationDelegateFactory.Global());

    EValidator.Registry.INSTANCE.put(SBHModelPackage.eINSTANCE, new EcoreValidator());
    BasicDiagnostic diagnostics = new BasicDiagnostic();

    LOGGER.debug("Validating Objects:");
    for (EObject eObj : ImmutableList.copyOf(load_resource.getAllContents()))
    {

        validate(eObj, diagnostics);
    }

    // Output Error-Messages if errors occured
    if (diagnostics.getSeverity() != Diagnostic.OK)
    {
        LOGGER.error("Validation of %s failed:", confFile);
        for (Diagnostic d : diagnostics.getChildren())
        {
            LOGGER.error("%s", d.getMessage());
        }
        throw new BenchmarkException("Configuration not valid");
    }

    if (load_resource.getContents().size() != 1)
    {
        LOGGER.error("Configuration invalid: There must be one root element, not %d", load_resource.getContents().size());
        throw new BenchmarkException("Configuration not valid");
    }

    EObject o = load_resource.getContents().get(0);

    if (!(o instanceof Configuration))
    {
        LOGGER.error("Configuration invalid: Root Element is %s not 'Configuration'", o);
        throw new BenchmarkException("Rootelement is not 'Configuration'");
    }

    // Start to evaluate Configuration
    Configuration conf = (Configuration) o;

    if (conf.getExperimentSetup() == null)
    {
        LOGGER.error("Configuration invalid: Configuration does not contain a ExperimentSetups");
        throw new BenchmarkException("Configuration does not contain a ExperimentSetups");
    }

    return conf.getExperimentSetup();
}
项目:SPA    文件:BenchmarkController.java   
/**
 * Loads a configuration from the XMI-File specified as parameter
 * {@code confFile}. The configuration is validated using OCL constraints
 * specified in the ECore Model. If the validation fails, an exception is
 * thrown. Otherwise the parsed configuration is returned.
 * 
 * @param confFile
 *            The config-file which should be loaded.
 * @return A {@code ExperimentSetup} instance containing every information
 *         needed to run the benchmarks.
 * @throws BenchmarkException
 *             if the configuration is invalid.
 */
public static ExperimentSetup loadConfigurationFromXMI(String confFile)
{
    ResourceSet load_resourceSet = new ResourceSetImpl();
    load_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
    load_resourceSet.getPackageRegistry().put(SBHModelPackage.eNS_URI, SBHModelPackage.eINSTANCE);
    Resource load_resource = load_resourceSet.getResource(URI.createURI(confFile), true);

    // Add OCL-Validators to EMF
    String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI;
    EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLInvocationDelegateFactory.Global());
    EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLSettingDelegateFactory.Global());
    EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI, new OCLValidationDelegateFactory.Global());

    EValidator.Registry.INSTANCE.put(SBHModelPackage.eINSTANCE, new EcoreValidator());
    BasicDiagnostic diagnostics = new BasicDiagnostic();

    LOGGER.debug("Validating Objects:");
    for (EObject eObj : ImmutableList.copyOf(load_resource.getAllContents()))
    {

        validate(eObj, diagnostics);
    }

    // Output Error-Messages if errors occured
    if (diagnostics.getSeverity() != Diagnostic.OK)
    {
        LOGGER.error("Validation of %s failed:", confFile);
        for (Diagnostic d : diagnostics.getChildren())
        {
            LOGGER.error("%s", d.getMessage());
        }
        throw new BenchmarkException("Configuration not valid");
    }

    if (load_resource.getContents().size() != 1)
    {
        LOGGER.error("Configuration invalid: There must be one root element, not %d", load_resource.getContents().size());
        throw new BenchmarkException("Configuration not valid");
    }

    EObject o = load_resource.getContents().get(0);

    if (!(o instanceof Configuration))
    {
        LOGGER.error("Configuration invalid: Root Element is %s not 'Configuration'", o);
        throw new BenchmarkException("Rootelement is not 'Configuration'");
    }

    // Start to evaluate Configuration
    Configuration conf = (Configuration) o;

    if (conf.getExperimentSetup() == null)
    {
        LOGGER.error("Configuration invalid: Configuration does not contain a ExperimentSetups");
        throw new BenchmarkException("Configuration does not contain a ExperimentSetups");
    }

    return conf.getExperimentSetup();
}