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
,
45 @Nullable final Navigatable navigatable
) {
47 myCategory
= category
;
48 myNavigatable
= navigatable
;
49 myMessage
= message
== null ?
"" : message
;
52 ApplicationManager
.getApplication().runReadAction(new Runnable() {
54 myFile
= url
== null ?
null : VirtualFileManager
.getInstance().findFileByUrl(url
);
59 public CompilerMessageCategory
getCategory() {
63 public String
getMessage() {
67 public Navigatable
getNavigatable() {
68 if (myNavigatable
!= null) {
71 final VirtualFile virtualFile
= getVirtualFile();
72 if (virtualFile
!= null && virtualFile
.isValid()) {
73 final int line
= getLine() - 1; // editor lines are zero-based
75 return myNavigatable
= new OpenFileDescriptor(myProject
, virtualFile
, line
, Math
.max(0, getColumn()-1));
81 public VirtualFile
getVirtualFile() {
85 public String
getExportTextPrefix() {
87 return CompilerBundle
.message("compiler.results.export.text.prefix", getLine());
92 public String
getRenderTextPrefix() {
94 return "(" + getLine() + ", " + getColumn() + ")";
99 public int getLine() {
103 public int getColumn() {
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;
122 public int hashCode() {
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
;
132 public String
toString() {