/** {@inheritDoc} */
 public void cleanup(IResource resource, IProgressMonitor monitor) throws CoreException {
   if (BeansCoreUtils.isBeansConfig(resource) && resource instanceof IFile) {
     IBeansConfig beansConfig = BeansCorePlugin.getModel().getConfig((IFile) resource);
     for (IBean bean : beansConfig.getBeans()) {
       BeansMetadataPlugin.getMetadataModel().clearBeanMetadata(bean);
       BeansMetadataPlugin.getMetadataModel().clearBeanProperties(bean);
     }
     // Notify that the model has changed.
     // ((BeansModel) BeansCorePlugin.getModel()).notifyListeners(beansConfig, Type.CHANGED);
   }
 }
  /** {@inheritDoc} */
  public Set<IResource> getAffectedResources(IResource resource, int kind, int deltaKind)
      throws CoreException {
    Set<IResource> resources = new HashSet<IResource>();

    if (kind != IncrementalProjectBuilder.FULL_BUILD
        && resource instanceof IFile
        && resource.getName().endsWith(JdtUtils.JAVA_FILE_EXTENSION)) {

      // Make sure that only a structural change to a java source file triggers a rebuild
      TypeStructureState structureState = context.get(TypeStructureState.class);
      BeansTypeHierachyState hierachyState = context.get(BeansTypeHierachyState.class);

      if (structureState == null
          || structureState.hasStructuralChanges(
              resource,
              ITypeStructureCache.FLAG_ANNOTATION | ITypeStructureCache.FLAG_ANNOTATION_VALUE)) {
        for (IBean bean : hierachyState.getBeansByContainingTypes(resource)) {
          IBeansConfig beansConfig = BeansModelUtils.getConfig(bean);
          resources.add(beansConfig.getElementResource());
          if (affectedBeans.containsKey(beansConfig)) {
            affectedBeans.get(beansConfig).add(bean);
          } else {
            Set<IBean> beans = new LinkedHashSet<IBean>();
            beans.add(bean);
            affectedBeans.put(beansConfig, beans);
          }
        }
      }
    } else if (BeansCoreUtils.isBeansConfig(resource, true)) {
      IBeansConfig beansConfig = (IBeansConfig) BeansModelUtils.getResourceModelElement(resource);
      if (beansConfig instanceof IImportedBeansConfig) {
        beansConfig = BeansModelUtils.getParentOfClass(beansConfig, IBeansConfig.class);
      }
      for (IBeansImport beansImport : beansConfig.getImports()) {
        for (IImportedBeansConfig importedBeansConfig : beansImport.getImportedBeansConfigs()) {
          resources.add(importedBeansConfig.getElementResource());
          addBeans(importedBeansConfig);
        }
      }
      resources.add(beansConfig.getElementResource());
      addBeans(beansConfig);
    }
    return resources;
  }