IDEADEV-31824 (Incorrect "manual array copy" warning)
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / InspectionComparator.java
blobadb71911738a7ba7be98c2f723e158c27020d280
1 /*
2 * Copyright 2003-2005 Dave Griffith
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.siyeh.ig;
18 import com.intellij.codeInspection.InspectionProfileEntry;
20 import java.util.Comparator;
22 class InspectionComparator
23 implements Comparator<Class<? extends InspectionProfileEntry>> {
25 public int compare(Class<? extends InspectionProfileEntry> class1,
26 Class<? extends InspectionProfileEntry> class2) {
27 final InspectionProfileEntry inspection1;
28 final InspectionProfileEntry inspection2;
29 try {
30 inspection1 = class1.newInstance();
31 inspection2 = class2.newInstance();
32 } catch (InstantiationException ignore) {
33 return -1;
34 } catch (IllegalAccessException ignore) {
35 return -1;
37 final String groupName1 = inspection1.getGroupDisplayName();
38 final String groupName2 = inspection2.getGroupDisplayName();
39 final int groupNameComparison = groupName1.compareTo(groupName2);
40 if (groupNameComparison != 0) {
41 return groupNameComparison;
43 String displayName1 = inspection1.getDisplayName();
44 String displayName2 = inspection2.getDisplayName();
45 displayName1 = displayName1.toUpperCase();
46 displayName2 = displayName2.toUpperCase();
47 displayName1 = stripQuotes(displayName1);
48 displayName2 = stripQuotes(displayName2);
49 return displayName1.compareTo(displayName2);
52 private static String stripQuotes(String str) {
53 if(str.indexOf((int) '\'') <0 && str.indexOf((int) '"')<0) {
54 return str;
56 final int length = str.length();
57 final StringBuffer buffer = new StringBuffer(length);
58 for (int i = 0; i < length; i++) {
59 final char ch = str.charAt(i);
60 if (ch != '"' && ch != '\'') {
61 buffer.append(ch);
64 return buffer.toString();