Java Code Examples for org.eclipse.jdt.core.IAccessRule#K_DISCOURAGED

The following examples show how to use org.eclipse.jdt.core.IAccessRule#K_DISCOURAGED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeFilter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isFiltered(TypeNameMatch match) {
	boolean filteredByPattern= getDefault().filter(match.getFullyQualifiedName());
	if (filteredByPattern) {
		return true;
	}

	int accessibility= match.getAccessibility();
	switch (accessibility) {
		case IAccessRule.K_NON_ACCESSIBLE:
			return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK));
		case IAccessRule.K_DISCOURAGED:
			return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK));
		default:
			return false;
	}
}
 
Example 2
Source File: SerializableAccessRules.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
static AccessRuleKind forInt(int kind) {
  switch (kind) {
    case IAccessRule.K_ACCESSIBLE:
      return ACCESSIBLE;
    case IAccessRule.K_DISCOURAGED:
      return DISCOURAGED;
    case IAccessRule.K_NON_ACCESSIBLE:
      return FORBIDDEN;
    default:
      throw new IllegalArgumentException("Invalid access rule kind value: " + kind);
  }
}
 
Example 3
Source File: XbaseUIValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected RestrictionKind computeRestriction(IJavaProject project, IType type) {
	try {
		IPackageFragmentRoot root = (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
		if (root == null) {
			return RestrictionKind.VALID;
		}
		IClasspathEntry entry = getResolvedClasspathEntry(project, root);
		if (entry == null) {
			return RestrictionKind.VALID;
		}
		IAccessRule[] rules = entry.getAccessRules();
		String typePath = type.getFullyQualifiedName().replace('.', '/');
		char[] typePathAsArray = typePath.toCharArray();
		for(IAccessRule rule: rules) {
			char[] patternArray = ((ClasspathAccessRule)rule).pattern;
			if (CharOperation.pathMatch(patternArray, typePathAsArray, true, '/')) {
				if (rule.getKind() == IAccessRule.K_DISCOURAGED) {
					return RestrictionKind.DISCOURAGED;
				} else if (rule.getKind() == IAccessRule.K_NON_ACCESSIBLE) {
					return RestrictionKind.FORBIDDEN;
				}
				return RestrictionKind.VALID;
			}
		}
	} catch(JavaModelException jme) {
		// ignore
	}
	return RestrictionKind.VALID;
}
 
Example 4
Source File: TypeFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isFiltered(TypeNameMatch match) {
	boolean filteredByPattern= getDefault().filter(match.getFullyQualifiedName());
	if (filteredByPattern)
		return true;
	
	int accessibility= match.getAccessibility();
	switch (accessibility) {
		case IAccessRule.K_NON_ACCESSIBLE:
			return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK));
		case IAccessRule.K_DISCOURAGED:
			return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK));
		default:
			return false;
	}
}
 
Example 5
Source File: AccessRulesLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static Image getResolutionImage(int kind) {
	switch (kind) {
		case IAccessRule.K_ACCESSIBLE:
			return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_NLS_TRANSLATE);
		case IAccessRule.K_DISCOURAGED:
			return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_WARNING);
		case IAccessRule.K_NON_ACCESSIBLE:
			return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_ERROR);
	}
	return null;
}
 
Example 6
Source File: AccessRulesLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String getResolutionLabel(int kind) {
	switch (kind) {
		case IAccessRule.K_ACCESSIBLE:
			return NewWizardMessages.AccessRulesLabelProvider_kind_accessible;
		case IAccessRule.K_DISCOURAGED:
			return NewWizardMessages.AccessRulesLabelProvider_kind_discouraged;
		case IAccessRule.K_NON_ACCESSIBLE:
			return NewWizardMessages.AccessRulesLabelProvider_kind_non_accessible;
	}
	return ""; //$NON-NLS-1$
}
 
Example 7
Source File: ClasspathEntry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static IAccessRule[] decodeAccessRules(NodeList list) {
	if (list == null) return null;
	int length = list.getLength();
	if (length == 0) return null;
	IAccessRule[] result = new IAccessRule[length];
	int index = 0;
	for (int i = 0; i < length; i++) {
		Node accessRule = list.item(i);
		if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
			Element elementAccessRule = (Element) accessRule;
			String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
			if (pattern == null) continue;
			String tagKind =  elementAccessRule.getAttribute(TAG_KIND);
			int kind;
			if (TAG_ACCESSIBLE.equals(tagKind))
				kind = IAccessRule.K_ACCESSIBLE;
			else if (TAG_NON_ACCESSIBLE.equals(tagKind))
				kind = IAccessRule.K_NON_ACCESSIBLE;
			else if (TAG_DISCOURAGED.equals(tagKind))
				kind = IAccessRule.K_DISCOURAGED;
			else
				continue;
			boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(TAG_IGNORE_IF_BETTER)); //$NON-NLS-1$
			result[index++] = new ClasspathAccessRule(new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
		}
	}
	if (index != length)
		System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
	return result;
}
 
Example 8
Source File: JavaClasspathParser.java    From sarl with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:innerassignment" })
private static IAccessRule[] decodeAccessRules(NodeList list) {
    if (list == null) {
        return null;
    }
    final int length = list.getLength();
    if (length == 0) {
        return null;
    }
    IAccessRule[] result = new IAccessRule[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        final Node accessRule = list.item(i);
        if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
            final Element elementAccessRule = (Element) accessRule;
            final String pattern = elementAccessRule.getAttribute(ClasspathEntry.TAG_PATTERN);
            if (pattern == null) {
                continue;
            }
            final String tagKind = elementAccessRule.getAttribute(ClasspathEntry.TAG_KIND);
            final int kind;
            if (ClasspathEntry.TAG_ACCESSIBLE.equals(tagKind)) {
                kind = IAccessRule.K_ACCESSIBLE;
            } else if (ClasspathEntry.TAG_NON_ACCESSIBLE.equals(tagKind)) {
                kind = IAccessRule.K_NON_ACCESSIBLE;
            } else if (ClasspathEntry.TAG_DISCOURAGED.equals(tagKind)) {
                kind = IAccessRule.K_DISCOURAGED;
            } else {
                continue;
            }
            final boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(ClasspathEntry.TAG_IGNORE_IF_BETTER)); //$NON-NLS-1$
            result[index++] = new ClasspathAccessRule(new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
        }
    }
    if (index != length) {
        System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
    }
    return result;
}
 
Example 9
Source File: AccessRuleEntryDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public AccessRuleEntryDialog(Shell parent, IAccessRule ruleToEdit, CPListElement entryToEdit) {
	super(parent);

	String title, message;
	if (ruleToEdit == null) {
		title= NewWizardMessages.TypeRestrictionEntryDialog_add_title;
	} else {
		title= NewWizardMessages.TypeRestrictionEntryDialog_edit_title;
	}
	message= Messages.format(NewWizardMessages.TypeRestrictionEntryDialog_pattern_label, BasicElementLabels.getPathLabel(entryToEdit.getPath(), false));
	setTitle(title);

	fPatternStatus= new StatusInfo();

	TypeRulesAdapter adapter= new TypeRulesAdapter();
	fPatternDialog= new StringDialogField();
	fPatternDialog.setLabelText(message);
	fPatternDialog.setDialogFieldListener(adapter);

	fRuleKindCombo= new ComboDialogField(SWT.READ_ONLY);
	fRuleKindCombo.setLabelText(NewWizardMessages.TypeRestrictionEntryDialog_kind_label);
	fRuleKindCombo.setDialogFieldListener(adapter);
	String[] items= {
			NewWizardMessages.TypeRestrictionEntryDialog_kind_non_accessible,
			NewWizardMessages.TypeRestrictionEntryDialog_kind_discourraged,
			NewWizardMessages.TypeRestrictionEntryDialog_kind_accessible
	};
	fRuleKinds= new int[] {
			IAccessRule.K_NON_ACCESSIBLE,
			IAccessRule.K_DISCOURAGED,
			IAccessRule.K_ACCESSIBLE
	};
	fRuleKindCombo.setItems(items);


	if (ruleToEdit == null) {
		fPatternDialog.setText(""); //$NON-NLS-1$
		fRuleKindCombo.selectItem(0);
	} else {
		fPatternDialog.setText(ruleToEdit.getPattern().toString());
		for (int i= 0; i < fRuleKinds.length; i++) {
			if (fRuleKinds[i] == ruleToEdit.getKind()) {
				fRuleKindCombo.selectItem(i);
				break;
			}
		}
	}
}