package org.jetbrains.android.augment;

import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.augment.PsiAugmentProvider;
import org.jetbrains.android.dom.converters.ResourceReferenceConverter;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.android.util.AndroidResourceUtil;
import org.jetbrains.android.util.AndroidUtils;
import org.jetbrains.annotations.NotNull;

import java.util.*;

/**
 * @author Eugene.Kudelevsky
 */
public class AndroidPsiAugmentProvider extends PsiAugmentProvider {
  @SuppressWarnings("unchecked")
  @NotNull
  @Override
  public <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement element, @NotNull Class<Psi> type) {
    if (type != PsiClass.class ||
        !(element instanceof PsiClass)) {
      return Collections.emptyList();
    }
    final PsiClass aClass = (PsiClass)element;
    final String className = aClass.getName();

    if (!AndroidUtils.R_CLASS_NAME.equals(className) &&
        !AndroidUtils.MANIFEST_CLASS_NAME.equals(className)) {
      return Collections.emptyList();
    }

    final AndroidFacet facet = AndroidFacet.getInstance(element);
    if (facet == null) {
      return Collections.emptyList();
    }

    final PsiFile containingFile = element.getContainingFile();
    if (containingFile == null) {
      return Collections.emptyList();
    }

    if (AndroidResourceUtil.isRJavaFile(facet, containingFile)) {
      final Set<String> types = ResourceReferenceConverter.getResourceTypesInCurrentModule(facet);
      final List<Psi> result = new ArrayList<Psi>(types.size());

      for (String resType : types) {
        final AndroidLightClass resClass = new ResourceTypeClass(facet, resType, aClass);
        result.add((Psi)resClass);
      }
      return result;
    }
    else if (AndroidResourceUtil.isManifestJavaFile(facet, containingFile)) {
      return Arrays.asList((Psi)new PermissionClass(facet, aClass),
                           (Psi)new PermissionGroupClass(facet, aClass));
    }
    return Collections.emptyList();
  }
}

@@ -33,16 +33,65 @@
 gment;%0A%0A
+import com.intellij.openapi.project.DumbService;%0A
 import c
@@ -116,16 +116,16 @@
 iClass;%0A
-
 import c
@@ -233,24 +233,82 @@
 ntProvider;%0A
+import org.jetbrains.android.compiler.AndroidAptCompiler;%0A
 import org.j
@@ -929,16 +929,68 @@
 siClass)
+ %7C%7C%0A        DumbService.isDumb(element.getProject())
 ) %7B%0A    
@@ -1350,24 +1350,24 @@
 e(element);%0A
-
     if (face
@@ -1367,32 +1367,118 @@
 f (facet == null
+ %7C%7C !AndroidAptCompiler.isToCompileModule(facet.getModule(), facet.getConfiguration())
 ) %7B%0A      return

check dumb mode, do not use augment in maven-based resource compilation mode