update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / compiled / ClassFileDecompiler.java
blobf1b5737a6e0ecf3561e6cf98d2bd04fb1adfb5ae
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author max
20 package com.intellij.psi.impl.compiled;
22 import com.intellij.openapi.application.ApplicationManager;
23 import com.intellij.openapi.fileTypes.BinaryFileDecompiler;
24 import com.intellij.openapi.fileTypes.StdFileTypes;
25 import com.intellij.openapi.fileTypes.ContentBasedClassFileProcessor;
26 import com.intellij.openapi.project.Project;
27 import com.intellij.openapi.project.ProjectManager;
28 import com.intellij.openapi.project.ex.ProjectManagerEx;
29 import com.intellij.openapi.vfs.VirtualFile;
30 import com.intellij.openapi.extensions.Extensions;
31 import com.intellij.psi.PsiManager;
32 import org.jetbrains.annotations.NotNull;
34 public class ClassFileDecompiler implements BinaryFileDecompiler {
35 @NotNull
36 public CharSequence decompile(final VirtualFile file) {
37 assert file.getFileType() == StdFileTypes.CLASS;
39 final Project project;
40 if (ApplicationManager.getApplication().isUnitTestMode()) {
41 project = ((ProjectManagerEx)ProjectManager.getInstance()).getCurrentTestProject();
42 assert project != null;
44 else {
45 final Project[] projects = ProjectManager.getInstance().getOpenProjects();
46 if (projects.length == 0) return "";
47 project = projects[0];
50 final ContentBasedClassFileProcessor[] processors = Extensions.getExtensions(ContentBasedClassFileProcessor.EP_NAME);
51 for (ContentBasedClassFileProcessor processor : processors) {
52 if (processor.isApplicable(project, file)) {
53 return processor.obtainFileText(project, file);
57 return ClsFileImpl.decompile(PsiManager.getInstance(project), file);