2 * Copyright 2000-2012 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.
16 package org.jetbrains.jps.incremental;
18 import com.intellij.openapi.diagnostic.Logger;
19 import com.intellij.openapi.util.UserDataHolderBase;
20 import com.intellij.openapi.util.io.FileUtil;
21 import com.intellij.util.Function;
22 import com.intellij.util.containers.ContainerUtil;
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
27 import java.io.IOException;
28 import java.util.Collection;
29 import java.util.Collections;
32 * @author Eugene Zhuravlev
35 public class CompiledClass extends UserDataHolderBase{
36 private final static Logger LOG = Logger.getInstance(CompiledClass.class);
39 private final File myOutputFile;
41 private final Collection<File> mySourceFiles;
43 private final String myClassName;
45 private BinaryContent myContent;
47 private boolean myIsDirty = false;
49 public CompiledClass(@NotNull File outputFile, @NotNull Collection<File> sourceFiles, @Nullable String className, @NotNull BinaryContent content) {
50 myOutputFile = outputFile;
51 mySourceFiles = sourceFiles;
52 myClassName = className;
54 LOG.assertTrue(!mySourceFiles.isEmpty());
57 public CompiledClass(@NotNull File outputFile, @NotNull File sourceFile, @Nullable String className, @NotNull BinaryContent content) {
58 this(outputFile, Collections.singleton(sourceFile), className, content);
61 public void save() throws IOException {
62 myContent.saveToFile(myOutputFile);
67 public File getOutputFile() {
72 public Collection<File> getSourceFiles() {
77 public Collection<String> getSourceFilesPaths() {
78 return ContainerUtil.map(mySourceFiles, new Function<File, String>() {
80 public String fun(File file) {
81 return file.getPath();
87 * @deprecated use {@link CompiledClass#getSourceFiles()} or {{@link CompiledClass#getSourceFilesPaths()}
91 public File getSourceFile() {
92 //noinspection ConstantConditions
93 return ContainerUtil.getFirstItem(getSourceFiles());
97 public String getClassName() {
102 public BinaryContent getContent() {
106 public void setContent(@NotNull BinaryContent content) {
111 public boolean isDirty() {
116 public boolean equals(Object o) {
117 if (this == o) return true;
118 if (o == null || getClass() != o.getClass()) return false;
120 CompiledClass aClass = (CompiledClass)o;
122 if (!FileUtil.filesEqual(myOutputFile, aClass.myOutputFile)) return false;
128 public int hashCode() {
129 return FileUtil.fileHashCode(myOutputFile);
133 public String toString() {
134 return "CompiledClass{" +
135 "myOutputFile=" + myOutputFile +
136 ", mySourceFiles=" + mySourceFiles +
137 ", myIsDirty=" + myIsDirty +