1 11 package org.eclipse.jdt.internal.compiler.env; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.core.compiler.IProblem; 15 16 19 public class AccessRuleSet { 20 21 private AccessRule[] accessRules; 22 public String [] messageTemplates; 23 public static final int MESSAGE_TEMPLATES_LENGTH = 4; 24 25 34 public AccessRuleSet(AccessRule[] accessRules, String [] messageTemplates) { 35 this.accessRules = accessRules; 36 if (messageTemplates != null && messageTemplates.length == MESSAGE_TEMPLATES_LENGTH) 37 this.messageTemplates = messageTemplates; 38 else 39 this.messageTemplates = new String [] {"{0}", "{0}", "{0} {1}", "{0} {1}"}; } 41 42 45 public boolean equals(Object object) { 46 if (this == object) 47 return true; 48 if (!(object instanceof AccessRuleSet)) 49 return false; 50 AccessRuleSet otherRuleSet = (AccessRuleSet) object; 51 if (this.messageTemplates.length != MESSAGE_TEMPLATES_LENGTH || 52 otherRuleSet.messageTemplates.length != MESSAGE_TEMPLATES_LENGTH) 53 return false; for (int i = 0; i < MESSAGE_TEMPLATES_LENGTH; i++) 55 if (!this.messageTemplates[i].equals(otherRuleSet.messageTemplates[i])) 56 return false; 57 int rulesLength = this.accessRules.length; 58 if (rulesLength != otherRuleSet.accessRules.length) return false; 59 for (int i = 0; i < rulesLength; i++) 60 if (!this.accessRules[i].equals(otherRuleSet.accessRules[i])) 61 return false; 62 return true; 63 } 64 65 public AccessRule[] getAccessRules() { 66 return this.accessRules; 67 } 68 69 76 public AccessRestriction getViolatedRestriction(char[] targetTypeFilePath) { 77 for (int i = 0, length = this.accessRules.length; i < length; i++) { 78 AccessRule accessRule = this.accessRules[i]; 79 if (CharOperation.pathMatch(accessRule.pattern, targetTypeFilePath, 80 true, '/')) { 81 switch (accessRule.getProblemId()) { 82 case IProblem.ForbiddenReference: 83 case IProblem.DiscouragedReference: 84 return new AccessRestriction(accessRule, this.messageTemplates); 85 default: 86 return null; 87 } 88 } 89 } 90 return null; 91 } 92 93 public String toString() { 94 return toString(true); 95 } 96 97 public String toString(boolean wrap) { 98 StringBuffer buffer = new StringBuffer (200); 99 buffer.append("AccessRuleSet {"); if (wrap) 101 buffer.append('\n'); 102 for (int i = 0, length = this.accessRules.length; i < length; i++) { 103 if (wrap) 104 buffer.append('\t'); 105 AccessRule accessRule = this.accessRules[i]; 106 buffer.append(accessRule); 107 if (wrap) 108 buffer.append('\n'); 109 else if (i < length-1) 110 buffer.append(", "); } 112 buffer.append("} [templates:\""); for (int i = 0; i < messageTemplates.length; i++) 114 buffer.append(this.messageTemplates[i]); 115 buffer.append("\"]"); return buffer.toString(); 117 } 118 } 119 | Popular Tags |