Esempio n. 1
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;
 }
Esempio n. 2
0
 @Override
 public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
     throws CoreException, OperationCanceledException {
   RefactoringStatus refactoringStatus = RefactoringStatus.create(Status.OK_STATUS);
   SubMonitor sm =
       SubMonitor.convert(
           pm,
           new StringBuffer("Checking initial conditions for ")
               .append(context.getLabel())
               .toString(),
           10);
   EObject element = context.getSourceElement();
   EObject container = EcoreUtil.getRootContainer(element);
   refactoringStatus =
       sm.isCanceled() ? RefactoringStatus.create(Status.CANCEL_STATUS) : validate(sm, container);
   sm.done();
   return refactoringStatus;
 }
Esempio n. 3
0
 @Override
 public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
     throws CoreException, OperationCanceledException {
   RefactoringStatus refactoringStatus = RefactoringStatus.create(Status.OK_STATUS);
   if (modelChange == null) {
     createChange(pm);
   }
   RefactoringTickProvider tickProvider = getRefactoringTickProvider();
   StringBuffer taskBuffer = new StringBuffer("Checking final conditions for re-factoring ");
   taskBuffer.append(context.getLabel());
   SubMonitor sm =
       SubMonitor.convert(pm, taskBuffer.toString(), tickProvider.getCheckFinalConditionsTicks());
   Object modified = modelChange.getModifiedElement();
   if (modified instanceof EObject) {
     EObject modifiedEObject = (EObject) modified;
     EObject container = EcoreUtil.getRootContainer(modifiedEObject);
     refactoringStatus =
         pm.isCanceled()
             ? RefactoringStatus.create(Status.CANCEL_STATUS)
             : validate(pm, container);
   }
   sm.done();
   return refactoringStatus;
 }