Make: heuristics for processing removed constant fields added. If precise analysis...
[fedora-idea.git] / java / compiler / impl / src / com / intellij / compiler / CompilerMessageImpl.java
blob350f7ec4d4ee9722b52c2ad8eec0def209975c24
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.
16 package com.intellij.compiler;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.compiler.CompilerBundle;
20 import com.intellij.openapi.compiler.CompilerMessage;
21 import com.intellij.openapi.compiler.CompilerMessageCategory;
22 import com.intellij.openapi.fileEditor.OpenFileDescriptor;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.vfs.VirtualFile;
25 import com.intellij.openapi.vfs.VirtualFileManager;
26 import com.intellij.pom.Navigatable;
27 import org.jetbrains.annotations.Nullable;
29 public final class CompilerMessageImpl implements CompilerMessage {
31 private final Project myProject;
32 private final CompilerMessageCategory myCategory;
33 @Nullable private Navigatable myNavigatable;
34 private final String myMessage;
35 private VirtualFile myFile;
36 private final int myRow;
37 private final int myColumn;
39 public CompilerMessageImpl(Project project,
40 CompilerMessageCategory category,
41 String message,
42 final String url,
43 int row,
44 int column,
45 @Nullable final Navigatable navigatable) {
46 myProject = project;
47 myCategory = category;
48 myNavigatable = navigatable;
49 myMessage = message == null ? "" : message;
50 myRow = row;
51 myColumn = column;
52 ApplicationManager.getApplication().runReadAction(new Runnable() {
53 public void run() {
54 myFile = url == null ? null : VirtualFileManager.getInstance().findFileByUrl(url);
56 });
59 public CompilerMessageCategory getCategory() {
60 return myCategory;
63 public String getMessage() {
64 return myMessage;
67 public Navigatable getNavigatable() {
68 if (myNavigatable != null) {
69 return myNavigatable;
71 final VirtualFile virtualFile = getVirtualFile();
72 if (virtualFile != null && virtualFile.isValid()) {
73 final int line = getLine() - 1; // editor lines are zero-based
74 if (line >= 0) {
75 return myNavigatable = new OpenFileDescriptor(myProject, virtualFile, line, Math.max(0, getColumn()-1));
78 return null;
81 public VirtualFile getVirtualFile() {
82 return myFile;
85 public String getExportTextPrefix() {
86 if (getLine() >= 0) {
87 return CompilerBundle.message("compiler.results.export.text.prefix", getLine());
89 return "";
92 public String getRenderTextPrefix() {
93 if (getLine() >= 0) {
94 return "(" + getLine() + ", " + getColumn() + ")";
96 return "";
99 public int getLine() {
100 return myRow;
103 public int getColumn() {
104 return myColumn;
107 public boolean equals(Object o) {
108 if (this == o) return true;
109 if (!(o instanceof CompilerMessage)) return false;
111 final CompilerMessageImpl compilerMessage = (CompilerMessageImpl)o;
113 if (myColumn != compilerMessage.myColumn) return false;
114 if (myRow != compilerMessage.myRow) return false;
115 if (!myCategory.equals(compilerMessage.myCategory)) return false;
116 if (myFile != null ? !myFile.equals(compilerMessage.myFile) : compilerMessage.myFile != null) return false;
117 if (!myMessage.equals(compilerMessage.myMessage)) return false;
119 return true;
122 public int hashCode() {
123 int result;
124 result = myCategory.hashCode();
125 result = 29 * result + myMessage.hashCode();
126 result = 29 * result + (myFile != null ? myFile.hashCode() : 0);
127 result = 29 * result + myRow;
128 result = 29 * result + myColumn;
129 return result;
132 public String toString() {
133 return myMessage;