// Path: src/com/equadon/intellij/mips/lang/MipsFileType.java
// public class MipsFileType extends LanguageFileType {
//   public static final MipsFileType INSTANCE = new MipsFileType();
// 
//   public static final String DEFAULT_EXTENSION = "s";
// 
//   private MipsFileType() {
//     super(MipsLanguage.INSTANCE);
//   }
// 
//   @NotNull
//   @Override
//   public String getName() {
//     return MipsLanguage.NAME;
//   }
// 
//   @NotNull
//   @Override
//   public String getDescription() {
//     return "MIPS File";
//   }
// 
//   @NotNull
//   @Override
//   public String getDefaultExtension() {
//     return DEFAULT_EXTENSION;
//   }
// 
//   @Nullable
//   @Override
//   public Icon getIcon() {
//     return MipsIcons.FILE;
//   }
// }
// 
// Path: src/com/equadon/intellij/mips/lang/psi/MipsFile.java
// public interface MipsFile extends PsiFile {
//   Collection<MipsLabelDefinition> getLabelDefinitions();
// }
// 
// Path: src/com/equadon/intellij/mips/lang/psi/MipsNamedElement.java
// public interface MipsNamedElement extends MipsElement, PsiNameIdentifierOwner {
// }


import java.util.List;
import com.equadon.intellij.mips.lang.MipsFileType;
import com.equadon.intellij.mips.lang.psi.MipsFile;
import com.equadon.intellij.mips.lang.psi.MipsNamedElement;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.indexing.FileBasedIndex;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/*
 * Copyright 2017 Niklas Persson
 *
 * 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.equadon.intellij.mips;



public class MipsUtil {
  /**
   * Find named elements that belong to the given project.
   * @param project Project that the elements belong to
   * @param cls Class type
   * @param <E> MipsNamedElement type
   * @return List of elements
   */
  public static <E extends MipsNamedElement> List<E> findNamedElements(Project project, Class<E> cls) {
    List<E> result = new ArrayList<>();
    Collection<VirtualFile> virtualFiles =
        FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, MipsFileType.INSTANCE, GlobalSearchScope.allScope(project));

    for (VirtualFile virtualFile : virtualFiles) {
// Path: src/com/equadon/intellij/mips/lang/MipsFileType.java
// public class MipsFileType extends LanguageFileType {
//   public static final MipsFileType INSTANCE = new MipsFileType();
// 
//   public static final String DEFAULT_EXTENSION = "s";
// 
//   private MipsFileType() {
//     super(MipsLanguage.INSTANCE);
//   }
// 
//   @NotNull
//   @Override
//   public String getName() {
//     return MipsLanguage.NAME;
//   }
// 
//   @NotNull
//   @Override
//   public String getDescription() {
//     return "MIPS File";
//   }
// 
//   @NotNull
//   @Override
//   public String getDefaultExtension() {
//     return DEFAULT_EXTENSION;
//   }
// 
//   @Nullable
//   @Override
//   public Icon getIcon() {
//     return MipsIcons.FILE;
//   }
// }
// 
// Path: src/com/equadon/intellij/mips/lang/psi/MipsFile.java
// public interface MipsFile extends PsiFile {
//   Collection<MipsLabelDefinition> getLabelDefinitions();
// }
// 
// Path: src/com/equadon/intellij/mips/lang/psi/MipsNamedElement.java
// public interface MipsNamedElement extends MipsElement, PsiNameIdentifierOwner {
// }


// Path: src/com/equadon/intellij/mips/MipsUtil.java
import java.util.List;
import com.equadon.intellij.mips.lang.MipsFileType;
import com.equadon.intellij.mips.lang.psi.MipsFile;
import com.equadon.intellij.mips.lang.psi.MipsNamedElement;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.indexing.FileBasedIndex;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/*
 * Copyright 2017 Niklas Persson
 *
 * 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.equadon.intellij.mips;



public class MipsUtil {
  /**
   * Find named elements that belong to the given project.
   * @param project Project that the elements belong to
   * @param cls Class type
   * @param <E> MipsNamedElement type
   * @return List of elements
   */
  public static <E extends MipsNamedElement> List<E> findNamedElements(Project project, Class<E> cls) {
    List<E> result = new ArrayList<>();
    Collection<VirtualFile> virtualFiles =
        FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, MipsFileType.INSTANCE, GlobalSearchScope.allScope(project));

    for (VirtualFile virtualFile : virtualFiles) {
      MipsFile file = (MipsFile) PsiManager.getInstance(project).findFile(virtualFile);