/*
 * Copyright 2000-2010 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.testFramework;

import com.intellij.codeHighlighting.TextEditorHighlightingPass;
import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory;
import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;

/**
 * @author Konstantin Bulenkov
 */
public class TestDataHighlightingPassFactory extends AbstractProjectComponent implements TextEditorHighlightingPassFactory {
  public static final List<String> SUPPORTED_FILE_TYPES = Arrays.asList(
    StdFileTypes.JAVA.getDefaultExtension()
  );

  public TestDataHighlightingPassFactory(Project project, TextEditorHighlightingPassRegistrar highlightingPassRegistrar) {
    super(project);
    highlightingPassRegistrar.registerTextEditorHighlightingPass(this, null, null, true, -1);
  }

  @NonNls
  @NotNull
  public String getComponentName() {
    return getClass().getName();
  }

  @Nullable
  public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile != null) {      
      if (SUPPORTED_FILE_TYPES.contains(virtualFile.getExtension())) {
        if (ProjectRootManager.getInstance(myProject).getFileIndex().getSourceRootForFile(virtualFile) == null) {
          return new TestDataHighlightingPass(myProject, PsiDocumentManager.getInstance(myProject).getDocument(file));          
        }
      }
    }
    return null;
  }
}


@@ -1685,16 +1685,243 @@
 ()%0A  );%0A
+  public static final List%3CString%3E SUPPORTED_IN_TEST_DATA_FILE_TYPES = Arrays.asList(%22js%22, %22php%22, %22css%22, %22html%22, %22xhtml%22, %22jsp%22);%0A  private static final int MAX_HOPES = 3;%0A  private static final String TEST_DATA = %22testData%22;%0A%0A
 %0A  publi
@@ -2056,16 +2056,52 @@
 oject);%0A
+    if (isIdeaProject(project)) %7B%0A  
     high
@@ -2186,16 +2186,130 @@
 e, -1);%0A
+    %7D%0A  %7D%0A%0A  private static boolean isIdeaProject(Project project) %7B%0A    return %22IDEA%22.equals(project.getName());%0A
   %7D%0A%0A  @
@@ -2617,20 +2617,285 @@
 null
+ && isSupported(virtualFile)
 ) %7B
+%0A
       
-%0A  
+return new TestDataHighlightingPass(myProject, PsiDocumentManager.getInstance(myProject).getDocument(file));%0A    %7D%0A    return null;%0A  %7D%0A%0A  public boolean isSupported(@NotNull VirtualFile file) %7B%0A    final String ext = file.getExtension();%0A
     
@@ -2932,34 +2932,11 @@
 ins(
-virtualFile.getExtension()
+ext
 )) %7B
@@ -2942,22 +2942,23 @@
 %7B%0A      
-  if (
+return 
 ProjectR
@@ -3027,24 +3027,17 @@
 ForFile(
-virtualF
+f
 ile) == 
@@ -3044,150 +3044,328 @@
 null
-) %7B%0A          return new TestDataHighlightingPass(myProject, PsiDocumentManager.getInstance(myProject).getDocument(file));          %0A        %7D
+;%0A    %7D%0A%0A    if (SUPPORTED_IN_TEST_DATA_FILE_TYPES.contains(ext)) %7B%0A      int i = 0;%0A      VirtualFile parent = file.getParent();%0A      while (parent != null && i %3C MAX_HOPES) %7B%0A        if (parent.getName().equalsIgnoreCase(TEST_DATA)) %7B%0A          return true;%0A        %7D%0A        i++;%0A        parent = parent.getParent();
 %0A   
@@ -3382,25 +3382,26 @@
 %0A    return 
-null
+false
 ;%0A  %7D%0A%7D%0A%0A

use for other test data too