1 19 20 package org.netbeans.api.java.comparators; 21 22 import org.openide.src.ConstructorElement; 23 import org.openide.src.MethodParameter; 24 import org.openide.src.Identifier; 25 import java.util.Comparator ; 26 27 class ConstructorComparator extends MemberNameComparator { 28 protected Comparator idComparator; 29 protected Comparator paramComparator; 30 31 protected ConstructorComparator(int type) { 32 super(type); 33 int source_type=type&SOURCE; 34 int paramType = source_type; 35 36 if ((type & PARAM_NAME) > 0) 37 paramType |= NAME; 38 if ((type & PARAM_MODIFIERS) > 0) 39 paramType |= MODIFIERS; 40 if ((type & PARAM_TYPE) > 0) 41 paramType |= TYPE; 42 43 if ((type&EXCEPTIONS)!=0) idComparator=IdentifierComparator.createComparator(source_type); 44 if ((type&PARAMETERS)!=0) paramComparator=MParameterComparator.createComparator(paramType); 45 } 46 47 public int compare(Object o1, Object o2) { 48 ConstructorElement ce1=(ConstructorElement)o1; 49 ConstructorElement ce2=(ConstructorElement)o2; 50 int result,i; 51 52 if ((type&NAME)!=0) { 53 result=super.compare(ce1,ce2); 54 if (result!=0) return result; 55 } 56 if ((type&EXCEPTIONS)!=0) { 57 Identifier[] excA = ce1.getExceptions(); 58 Identifier[] excB = ce2.getExceptions(); 59 60 if (excA.length != excB.length) { 61 return excA.length-excB.length>0?1:-1; 62 } 63 for (i = 0; i < excA.length; i++) { 64 result=idComparator.compare(excA[i],excB[i]); 65 if (result!=0) return result; 66 } 67 } 68 if (paramComparator!=null) { 69 MethodParameter[] paramA = ce1.getParameters(); 70 MethodParameter[] paramB = ce2.getParameters(); 71 72 if (paramA.length != paramB.length) { 73 return paramA.length-paramB.length>0?1:-1; 74 } 75 for (i = 0; i < paramA.length; i++) { 76 result=paramComparator.compare(paramA[i],paramB[i]); 77 if (result!=0) return result; 78 } 79 } 80 return 0; 81 } 82 83 static Comparator createComparator(int type) { 84 return new ConstructorComparator(type); 85 } 86 87 } 88 89 | Popular Tags |