1 /******************************************************************************* 2 * Copyright (c) 2000, 2009 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.core; 15 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.jdt.core.IAccessRule; 19 import org.eclipse.jdt.core.compiler.IProblem; 20 import org.eclipse.jdt.internal.compiler.env.AccessRule; 21 22 public class ClasspathAccessRule extends AccessRule implements IAccessRule { 23 ClasspathAccessRule(IPath pattern, int kind)24 public ClasspathAccessRule(IPath pattern, int kind) { 25 this(pattern.toString().toCharArray(), toProblemId(kind)); 26 } 27 ClasspathAccessRule(char[] pattern, int problemId)28 public ClasspathAccessRule(char[] pattern, int problemId) { 29 super(pattern, problemId); 30 } 31 toProblemId(int kind)32 private static int toProblemId(int kind) { 33 boolean ignoreIfBetter = (kind & IAccessRule.IGNORE_IF_BETTER) != 0; 34 switch (kind & ~IAccessRule.IGNORE_IF_BETTER) { 35 case K_NON_ACCESSIBLE: 36 return ignoreIfBetter ? IProblem.ForbiddenReference | AccessRule.IgnoreIfBetter : IProblem.ForbiddenReference; 37 case K_DISCOURAGED: 38 return ignoreIfBetter ? IProblem.DiscouragedReference | AccessRule.IgnoreIfBetter : IProblem.DiscouragedReference; 39 default: 40 return ignoreIfBetter ? AccessRule.IgnoreIfBetter : 0; 41 } 42 } 43 44 @Override getPattern()45 public IPath getPattern() { 46 return new Path(new String(this.pattern)); 47 } 48 49 @Override getKind()50 public int getKind() { 51 switch (getProblemId()) { 52 case IProblem.ForbiddenReference: 53 return K_NON_ACCESSIBLE; 54 case IProblem.DiscouragedReference: 55 return K_DISCOURAGED; 56 default: 57 return K_ACCESSIBLE; 58 } 59 } 60 61 } 62