package org.eclipse.jdt.internal.compiler.env;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
public class AccessRule {
public static final int IgnoreIfBetter = 0x02000000;
public char[] pattern;
public int problemId;
public AccessRule(char[] pattern, int problemId) {
this(pattern, problemId, false);
}
public AccessRule(char[] pattern, int problemId, boolean keepLooking) {
this.pattern = pattern;
this.problemId = keepLooking ? problemId | IgnoreIfBetter : problemId;
}
@Override
public int hashCode() {
return this.problemId * 17 + CharOperation.hashCode(this.pattern);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof AccessRule)) return false;
AccessRule other = (AccessRule) obj;
if (this.problemId != other.problemId) return false;
return CharOperation.equals(this.pattern, other.pattern);
}
public int getProblemId() {
return this.problemId & ~IgnoreIfBetter;
}
public boolean ignoreIfBetter() {
return (this.problemId & IgnoreIfBetter) != 0;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("pattern=");
buffer.append(this.pattern);
switch (getProblemId()) {
case IProblem.ForbiddenReference:
buffer.append(" (NON ACCESSIBLE");
break;
case IProblem.DiscouragedReference:
buffer.append(" (DISCOURAGED");
break;
default:
buffer.append(" (ACCESSIBLE");
break;
}
if (ignoreIfBetter())
buffer.append(" | IGNORE IF BETTER");
buffer.append(')');
return buffer.toString();
}
}