01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.env;
11:
12: import org.eclipse.jdt.core.compiler.CharOperation;
13: import org.eclipse.jdt.core.compiler.IProblem;
14:
15: public class AccessRule {
16:
17: public static final int IgnoreIfBetter = 0x02000000; // value must be greater than IProblem#ForbiddenReference and DiscouragedReference
18:
19: public char[] pattern;
20: public int problemId;
21:
22: public AccessRule(char[] pattern, int problemId) {
23: this (pattern, problemId, false);
24: }
25:
26: public AccessRule(char[] pattern, int problemId, boolean keepLooking) {
27: this .pattern = pattern;
28: this .problemId = keepLooking ? problemId | IgnoreIfBetter
29: : problemId;
30: }
31:
32: public int hashCode() {
33: return this .problemId * 17
34: + CharOperation.hashCode(this .pattern);
35: }
36:
37: public boolean equals(Object obj) {
38: if (!(obj instanceof AccessRule))
39: return false;
40: AccessRule other = (AccessRule) obj;
41: if (this .problemId != other.problemId)
42: return false;
43: return CharOperation.equals(this .pattern, other.pattern);
44: }
45:
46: public int getProblemId() {
47: return this .problemId & ~IgnoreIfBetter;
48: }
49:
50: public boolean ignoreIfBetter() {
51: return (this .problemId & IgnoreIfBetter) != 0;
52: }
53:
54: public String toString() {
55: StringBuffer buffer = new StringBuffer();
56: buffer.append("pattern="); //$NON-NLS-1$
57: buffer.append(this .pattern);
58: switch (getProblemId()) {
59: case IProblem.ForbiddenReference:
60: buffer.append(" (NON ACCESSIBLE"); //$NON-NLS-1$
61: break;
62: case IProblem.DiscouragedReference:
63: buffer.append(" (DISCOURAGED"); //$NON-NLS-1$
64: break;
65: default:
66: buffer.append(" (ACCESSIBLE"); //$NON-NLS-1$
67: break;
68: }
69: if (ignoreIfBetter())
70: buffer.append(" | IGNORE IF BETTER"); //$NON-NLS-1$
71: buffer.append(')');
72: return buffer.toString();
73: }
74: }
|