/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * 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.intellij.codeInspection;

import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.ArrayFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Comparator;

/**
 * Base class for problems returned by local and global inspection tools.
 *
 * @author anna
 * @since 6.0
 * @see InspectionManager#createProblemDescriptor(String, QuickFix[])
 */
public interface CommonProblemDescriptor {
  Comparator<CommonProblemDescriptor> DESCRIPTOR_COMPARATOR = (c1, c2) -> {
    if (c1 instanceof ProblemDescriptor && c2 instanceof ProblemDescriptor) {
      int diff = ((ProblemDescriptor)c2).getLineNumber() - ((ProblemDescriptor)c1).getLineNumber();
      if (diff != 0) {
        return diff;
      }

      diff = PsiUtilCore.compareElementsByPosition(((ProblemDescriptor)c2).getPsiElement(), ((ProblemDescriptor)c1).getPsiElement());
      if (diff != 0) {
        return diff;
      }
    }
    return c1.getDescriptionTemplate().compareTo(c2.getDescriptionTemplate());
  };

  CommonProblemDescriptor[] EMPTY_ARRAY = new CommonProblemDescriptor[0];
  ArrayFactory<CommonProblemDescriptor> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new CommonProblemDescriptor[count];

  /**
   * Returns the template from which the problem description is built. The template may
   * contain special markers: {@code #ref} is replaced with the text of the element
   * in which the problem has been found, and {@code #loc} is replaced with the filename
   * and line number in exported inspection results and ignored when viewing within IDEA.
   *
   * @return the template for the problem description.
   */
  @NotNull
  String getDescriptionTemplate();

  /**
   * Returns the quickfixes for the problem.
   *
   * @return the list of quickfixes registered for the problem.
   */
  @Nullable
  QuickFix[] getFixes();
}

@@ -1,13 +1,10 @@
 /
-*%0A *
+/
  Copyrig
@@ -18,9 +18,9 @@
 -201
-3
+7
  Jet
@@ -36,566 +36,109 @@
 r.o.
-%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */
+ Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 %0Apac
@@ -1415,16 +1415,31 @@
 template
+ (text or html)
  from wh
@@ -1475,16 +1475,21 @@
 s built.
+%0A   *
  The tem
@@ -1497,21 +1497,16 @@
 late may
-%0A   *
  contain
@@ -1522,16 +1522,29 @@
 markers:
+%0A   *%0A   * 1.
  %7B@code 
@@ -1589,21 +1589,16 @@
  element
-%0A   *
  in whic
@@ -1629,13 +1629,22 @@
 ound
-, and
+;%0A   *%0A   * 2.
  %7B@c
@@ -1682,21 +1682,16 @@
 filename
-%0A   *
  and lin
@@ -1766,16 +1766,199 @@
 hin IDEA
+;%0A   *%0A   * 3. %7B@code #treeend%7D is used as cut-symbol for template when it's shown inside inspection result tree.%0A   * So any content after this marker is not visible in the tree node
 .%0A   *%0A 

improve javadoc for CommonProblemDescriptor.getDescriptionTemplate