KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > ClasspathAccessRule


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.core;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.jdt.core.IAccessRule;
16 import org.eclipse.jdt.core.compiler.IProblem;
17 import org.eclipse.jdt.internal.compiler.env.AccessRule;
18
19 public class ClasspathAccessRule extends AccessRule implements IAccessRule {
20     
21     public ClasspathAccessRule(IPath pattern, int kind) {
22         this(pattern.toString().toCharArray(), toProblemId(kind));
23     }
24     
25     public ClasspathAccessRule(char[] pattern, int problemId) {
26         super(pattern, problemId);
27     }
28     
29     private static int toProblemId(int kind) {
30         boolean ignoreIfBetter = (kind & IAccessRule.IGNORE_IF_BETTER) != 0;
31         switch (kind & ~IAccessRule.IGNORE_IF_BETTER) {
32             case K_NON_ACCESSIBLE:
33                 return ignoreIfBetter ? IProblem.ForbiddenReference | AccessRule.IgnoreIfBetter : IProblem.ForbiddenReference;
34             case K_DISCOURAGED:
35                 return ignoreIfBetter ? IProblem.DiscouragedReference | AccessRule.IgnoreIfBetter : IProblem.DiscouragedReference;
36             default:
37                 return ignoreIfBetter ? AccessRule.IgnoreIfBetter : 0;
38         }
39     }
40
41     public IPath getPattern() {
42         return new Path(new String JavaDoc(this.pattern));
43     }
44
45     public int getKind() {
46         switch (getProblemId()) {
47             case IProblem.ForbiddenReference:
48                 return K_NON_ACCESSIBLE;
49             case IProblem.DiscouragedReference:
50                 return K_DISCOURAGED;
51             default:
52                 return K_ACCESSIBLE;
53         }
54     }
55
56 }
57
Popular Tags