@Override
  public IDecorator[] getDecorators(final PictogramElement pe) {
    IFeatureProvider featureProvider = getFeatureProvider();
    Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
    Integer objectId;
    if (bo instanceof Method) {
      System.out.println("CHECKING METHOD");
      objectId = System.identityHashCode(bo.getClass());
      try { // generate decorator and markers
        if (!XcoreValidator.INSTANCE.validateMethod((Method) bo, diagnosticChain, null)) {
          Diagnostic lastDiagnostic =
              diagnosticChain.getChildren().get(diagnosticChain.getChildren().size() - 1);
          markers.put(
              objectId,
              AtomicDesignUtils.createMarker(
                  lastDiagnostic.getMessage(),
                  IMarker.SEVERITY_ERROR,
                  ((Method) bo).getClass().getName()));
          return new ImageDecorator[] {
            AtomicDesignUtils.createImageDecorator(
                lastDiagnostic, lastDiagnostic.getMessage(), 20, 0)
          };

        } else {
          AtomicDesignUtils.destroyMarker(markers.get(objectId));
        }

      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    if (bo instanceof ComputationUnit) {
      System.out.println("CHECKING CU");
      if (!XcoreValidator.INSTANCE.validateComputationUnit(
          (ComputationUnit) bo, diagnosticChain, null)) {
        System.out.println("CHECKING METHOD");
      }
    }
    if (bo instanceof DataElement) {
      System.out.println("CHECKING DATAELEMENT");
      if (!XcoreValidator.INSTANCE.validateDataElement((DataElement) bo, diagnosticChain, null)) {}
    }

    if (bo instanceof Service) {
      System.out.println("CHECKING SERVICE");
      if (!XcoreValidator.INSTANCE.validateService((Service) bo, diagnosticChain, null)) {}
    }

    if (bo instanceof Parameter) {
      System.out.println("CHECKING PARAMETER");
      if (!XcoreValidator.INSTANCE.validateParameter((Parameter) bo, diagnosticChain, null)) {}
    }

    return super.getDecorators(pe);
  }
 public void add(Diagnostic diagnostic) {
   if (diagnostic == null) return;
   List<Diagnostic> kids = diagnostic.getChildren();
   if (!kids.isEmpty()) {
     for (Diagnostic kid : kids) add(kid);
   } else {
     List<?> objects = diagnostic.getData();
     CSTNode cstNode = null;
     if (!objects.isEmpty()) {
       Object object = objects.get(0);
       if (object != null) {
         if (environment != null) cstNode = environment.getASTMapping(object);
         else if (object instanceof CSTNode) cstNode = (CSTNode) object;
       }
     }
     int startOffset = cstNode != null ? cstNode.getStartOffset() : 0;
     int endOffset = cstNode != null ? cstNode.getEndOffset() : 0;
     Severity problemSeverity = Severity.INFO;
     if (diagnostic.getSeverity() >= Diagnostic.ERROR) problemSeverity = Severity.ERROR;
     else if (diagnostic.getSeverity() >= Diagnostic.WARNING) problemSeverity = Severity.WARNING;
     String problemMessage = diagnostic.getMessage();
     String problemContext = diagnostic.getSource();
     handleProblem(problemSeverity, problemMessage, problemContext, startOffset, endOffset);
   }
 }
Пример #3
0
 /**
  *
  * <!-- 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 + "  ");
   }
 }
Пример #4
0
 private RefactoringStatus validate(IProgressMonitor pm, EObject object) {
   RefactoringStatus refactoringStatus = RefactoringStatus.create(Status.OK_STATUS);
   EValidator.Registry validatorRegistry =
       extensions.getInstance(EValidator.Registry.class, object);
   EPackage epackage = object.eClass().getEPackage();
   EValidator validator = validatorRegistry.getEValidator(epackage);
   BasicDiagnostic diagnostics = new BasicDiagnostic();
   if (pm.isCanceled()) {
     refactoringStatus = RefactoringStatus.create(Status.CANCEL_STATUS);
     pm.done();
   } else {
     SubMonitor sm = SubMonitor.convert(pm, "Validating re-factoring.", IProgressMonitor.UNKNOWN);
     validator.validate(object, diagnostics, Maps.newHashMap());
     Iterator<Diagnostic> validationIterator =
         Iterables.filter(
                 diagnostics.getChildren(),
                 new Predicate<Diagnostic>() {
                   @Override
                   public boolean apply(Diagnostic diagnostic) {
                     if (diagnostic instanceof FeatureBasedDiagnostic) {
                       return FeatureBasedDiagnostic.ERROR
                           == ((FeatureBasedDiagnostic) diagnostic).getSeverity();
                     }
                     return false;
                   }
                 })
             .iterator();
     if (validationIterator.hasNext()) {
       Diagnostic diagnostic = validationIterator.next();
       refactoringStatus = RefactoringStatus.createFatalErrorStatus(diagnostic.getMessage());
     }
     sm.done();
   }
   return refactoringStatus;
 }
Пример #5
0
  public MavenMetadata(URI uri) throws CoreException {
    Resource resource = getResourceSet().getResource(uri, true);
    EList<EObject> content = resource.getContents();
    if (content.size() != 1)
      throw ExceptionUtils.fromMessage(
          "ECore Resource did not contain one resource. It had %d",
          Integer.valueOf(content.size()));

    documentRoot = (DocumentRoot) content.get(0);
    Diagnostic diag = Diagnostician.INSTANCE.validate(documentRoot);
    if (diag.getSeverity() == Diagnostic.ERROR) {
      for (Diagnostic childDiag : diag.getChildren()) LogUtils.error(childDiag.getMessage());
      throw ExceptionUtils.fromMessage(
          "Maven Metadata model validation failed: %s", diag.getMessage());
    }
  }
Пример #6
0
 protected void assertProblem(Diagnostic diagnostic, EObject target, int code) {
   Diagnostic problem = findProblem(diagnostic, target, code);
   assertNotNull("Problem not found", problem);
   System.out.println("Found expected problem: " + problem.getMessage());
 }
Пример #7
0
  /**
   * Initializes me with a diagnostic obtained from a problem handler.
   *
   * @param problem the diagnostic
   * @since 1.2
   */
  public ParserException(Diagnostic problem) {
    super(problem.getMessage());

    this.diagnostic = problem;
  }
  @Override
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    try {
      this.launch = launch;
      cleanup();

      final MitraLaunchConfigurationAdapter configAdapter =
          new MitraLaunchConfigurationAdapter(configuration);

      String consoleName = "Mitra Interpreter [" + configAdapter.getName() + "] " + mode;
      console = findConsole(consoleName);
      console.activate();
      initConsoleStream();

      clearConsole();

      final StandaloneExecutor executor =
          MitraStandaloneLaunchFactory.createExecutor(configAdapter);
      executor.getProjectContext().setMessageAcceptor(new ConsoleMessageAcceptor(console));

      console.addPatternMatchListener(new MitraConsoleTracker(executor.getProjectContext()));

      executor.getProjectContext().out = new PrintStream(createMessageStream(SWT.COLOR_BLACK));

      PrintStream err = new PrintStream(createMessageStream(SWT.COLOR_RED));
      executor.getProjectContext().err = err;

      executor.getProjectContext().log = new PrintStream(createMessageStream(SWT.COLOR_BLUE));

      try {
        executor.prepareInterpreter();
      } catch (Exception ex) {
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                MitraDebugPlugin.PLUGIN_ID,
                "Error preparing Mitra interpreter: " + ex.getMessage(),
                ex));
      }

      executor
          .getDebugable()
          .addInterpreterListener(
              new IDebugableListener() {

                @Override
                public void terminated() {

                  out("Mitra interpreter terminated.");
                  try {
                    for (String fileName : configAdapter.getOutputModelFilenames().values()) {
                      URI uri = URI.createFileURI(fileName);
                      refreshPath(uri);
                    }
                    for (String fileName : configAdapter.getInputModelFilenames().values()) {
                      URI uri = URI.createFileURI(fileName);
                      refreshPath(uri);
                    }
                    if (configAdapter.isSaveTraces()) {
                      URI uri = URI.createFileURI(configAdapter.getTraceModelFilename());
                      refreshPath(uri);
                    }
                  } catch (CoreException ex) {
                    out("Error refreshing project path: " + ex);
                  }
                }

                @Override
                public void processDebugableEvent(DebugEventType eventType) {
                  // not interested in
                }

                @Override
                public void suspended() {
                  // not interested in
                }
              });

      ResourceSet rs = executor.getProjectContext().getResourceSet();
      int errorCount = 0;
      int warningCount = 0;
      int moduleCount = 0;
      // iterate over copy, as new resources may be
      // added while resolving proxies
      List<Resource> resources = new ArrayList<Resource>(rs.getResources());
      for (Resource resource : resources) {
        errorCount += resource.getErrors().size();
        warningCount += resource.getWarnings().size();

        if (resource.getContents().size() > 0) {
          for (EObject model : resource.getContents()) {

            if (model instanceof Module) {
              moduleCount++;
            }
            Diagnostic diagnostic = Diagnostician.INSTANCE.validate(model);
            for (Diagnostic child : diagnostic.getChildren()) {
              switch (child.getSeverity()) {
                case Diagnostic.ERROR:
                  if (!(model instanceof Module)) {
                    err.println(model.eResource().getURI() + ": " + child.getMessage());
                  }
                  errorCount++;
                  break;
                case Diagnostic.WARNING:
                  warningCount++;
              }
            }
          }
        }
      }

      MessageFormat form = new MessageFormat("Loaded {0}{1}, {2}.");
      double[] limits = {0, 1, 2};
      String[] moduleparts = {"no module", "1 module", "{0,number} modules"};
      ChoiceFormat moduleform = new ChoiceFormat(limits, moduleparts);
      form.setFormatByArgumentIndex(0, moduleform);
      String[] errorparts = {" successfully: 0 errors", ": 1 error", ": {1,number} errors"};
      ChoiceFormat errorform = new ChoiceFormat(limits, errorparts);
      form.setFormatByArgumentIndex(1, errorform);
      String[] warningparts = {"0 warnings", "1 warning", "{2,number} warnings"};
      ChoiceFormat warningform = new ChoiceFormat(limits, warningparts);
      form.setFormatByArgumentIndex(2, warningform);

      String msg = form.format(new Object[] {moduleCount, errorCount, warningCount});
      if (errorCount > 0) {
        msg += " Cannot start Mitra intpreter.";
      }
      out(msg);
      if (errorCount > 0 || moduleCount == 0) {
        throw new CoreException(new Status(IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, msg));
      }

      IDebuggable debugable = executor.getDebugable(); // debugable
      // supports
      // listeners!

      if (debugable == null) {
        throw new CoreException(
            new Status(
                IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, "No debuggable interpreter prepared."));
      }

      RuleDeclaration decl = debugable.getCalledRule();

      if (decl == null) {
        throw new CoreException(
            new Status(IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, "No rule selected."));
      }
      IDebugTarget debugTarget =
          new MitraDebugTarget(
              launch, new MitraDebugProxy(debugable), decl.eResource().getURI().toFileString());

      Display display = Display.getCurrent();
      if (display == null) { // start in normal thread
        if (log.isLoggable(Level.INFO)) {
          log.info("Start mitra interpreter via new thread");
        }
        out("Start Mitra interpreter on new thread");

        Thread interpreterThread = new Thread(debugable);
        if (mode.equals(ILaunchManager.DEBUG_MODE)) {
          debugable.enableDebug(true);
          interpreterThread.setName("MitraInterpreter");
          interpreterThread.start();
          launch.addDebugTarget(debugTarget);
        } else {
          interpreterThread.start();
        }
      } else { // start via display
        if (log.isLoggable(Level.INFO)) {
          log.info("Start mitra interpreter via display.asyncExec");
        }
        out("Start Mitra interpreter on display thread");

        if (mode.equals(ILaunchManager.DEBUG_MODE)) {
          debugable.enableDebug(true);
          display.asyncExec(debugable);
          // interpreterThread.setName("MitraInterpreter");
          // interpreterThread.start();
          launch.addDebugTarget(debugTarget);
        } else {
          display.asyncExec(debugable);
        }
      }
      out("Interpreter running...");
    } finally {
      console = null;
    }
  }