KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > env > AccessRule


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 public class AccessRule {
17     
18     public static final int IgnoreIfBetter = 0x02000000; // value must be greater than IProblem#ForbiddenReference and DiscouragedReference
19

20     public char[] pattern;
21     public int problemId;
22     
23     public AccessRule(char[] pattern, int problemId) {
24         this(pattern, problemId, false);
25     }
26     
27     public AccessRule(char[] pattern, int problemId, boolean keepLooking) {
28         this.pattern = pattern;
29         this.problemId = keepLooking ? problemId | IgnoreIfBetter : problemId;
30     }
31     
32     public int hashCode() {
33         return this.problemId * 17 + CharOperation.hashCode(this.pattern);
34     }
35     
36     public boolean equals(Object JavaDoc obj) {
37         if (!(obj instanceof AccessRule)) return false;
38         AccessRule other = (AccessRule) obj;
39         if (this.problemId != other.problemId) return false;
40         return CharOperation.equals(this.pattern, other.pattern);
41     }
42
43     public int getProblemId() {
44         return this.problemId & ~IgnoreIfBetter;
45     }
46     
47     public boolean ignoreIfBetter() {
48         return (this.problemId & IgnoreIfBetter) != 0;
49     }
50
51     public String JavaDoc toString() {
52         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
53         buffer.append("pattern="); //$NON-NLS-1$
54
buffer.append(this.pattern);
55         switch (getProblemId()) {
56             case IProblem.ForbiddenReference:
57                 buffer.append(" (NON ACCESSIBLE"); //$NON-NLS-1$
58
break;
59             case IProblem.DiscouragedReference:
60                 buffer.append(" (DISCOURAGED"); //$NON-NLS-1$
61
break;
62             default:
63                 buffer.append(" (ACCESSIBLE"); //$NON-NLS-1$
64
break;
65         }
66         if (ignoreIfBetter())
67             buffer.append(" | IGNORE IF BETTER"); //$NON-NLS-1$
68
buffer.append(')');
69         return buffer.toString();
70     }
71 }
72
Popular Tags