コード例 #1
0
ファイル: DCLBuilder.java プロジェクト: joyeliz/DCL
  private void check(IResource resource, Architecture architecture, boolean reextractDependencies)
      throws CoreException {
    if (resource instanceof IFile && resource.getName().endsWith(".java")) {
      final IFile file = (IFile) resource;
      MarkerUtils.deleteMarkers(file);

      final ICompilationUnit unit = ((ICompilationUnit) JavaCore.create((IFile) resource));

      /* We only consider the units linked to source-folders */
      if (!unit.isOpen()) {
        return;
      }

      final String className = DCLUtil.getClassName(unit);

      /* We only consider the units without compilation errors*/
      if (file.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)
          == IMarker.SEVERITY_ERROR) {
        // MarkerUtils.addErrorMarker(this.getProject(), "DCLcheck has not verified class " +
        // className + " because it contains compilation errors.");
        return;
      }

      try {
        final Collection<Dependency> dependencies;
        if (reextractDependencies) {
          dependencies = DCLUtil.getDependenciesUsingAST(unit);
          architecture.updateDependencies(className, dependencies);
          DCLPersistence.persist(this.getProject(), className, dependencies);
        } else {
          dependencies = architecture.getDependencies(className);
        }

        for (DependencyConstraint dc : architecture.getDependencyConstraints()) {
          Collection<ArchitecturalDrift> result =
              dc.validate(
                  className,
                  architecture.getModules(),
                  architecture.getProjectClasses(),
                  dependencies,
                  this.getProject());
          if (result != null && !result.isEmpty()) {
            for (ArchitecturalDrift ad : result) {
              MarkerUtils.addMarker(file, ad);
            }
          }
        }
      } catch (Exception e) {
        MarkerUtils.addErrorMarker(
            this.getProject(), "There was a problem in extracting dependencies from " + className);
        CoreException ce = new CoreException(Status.CANCEL_STATUS);
        ce.setStackTrace(e.getStackTrace());
        throw ce;
      }
    }
  }