Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a582ec806571ebd0fa919de8a9f103d1df93ec00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2019 Altran Netherlands B.V. and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Niko Stotz (Altran Netherlands B.V.) - initial implementation
 *******************************************************************************/
package org.eclipse.ui.internal.editors.text.codemining.annotation;

import org.eclipse.jdt.annotation.Nullable;

import org.eclipse.jface.preference.IPreferenceStore;

/**
 * Simplifies access to user preferences related to Annotation-based code minings.
 *
 * <p>
 * All methods fall back to defaults if the preference store is unavailable.
 * </p>
 *
 * <p>
 * The following preferences are available:
 * </p>
 *
 * <dl>
 * <dt>show infos <i>(default: <code>false</code>)</i></dt>
 * <dd>Whether INFO-level annotations should be shown as code minings.</dd>
 *
 * <dt>show warnings <i>(default: <code>false</code>)</i></dt>
 * <dd>Whether WARNING-level annotations should be shown as code minings.</dd>
 *
 * <dt>show errors <i>(default: <code>false</code>)</i></dt>
 * <dd>Whether ERROR-level annotations should be shown as code minings.</dd>
 *
 * <dt>Maximum annotations shown <i>(default: <code>100</code>)</i></dt>
 * <dd>How many annotations should be shown at most as code minings. Mainly to prevent bad editor
 * performance.</dd>
 * </dl>
 *
 * @since 3.13
 */
public class AnnotationCodeMiningPreferences {
	private IPreferenceStore preferenceStore;

	public boolean isInfoEnabled() {
		return (getLevel() & AnnotationCodeMiningPreferenceConstants.SHOW_ANNOTATION_CODE_MINING_LEVEL__INFO) > 0;
	}

	public boolean isWarningEnabled() {
		return (getLevel() & AnnotationCodeMiningPreferenceConstants.SHOW_ANNOTATION_CODE_MINING_LEVEL__WARNING) > 0;
	}

	public boolean isErrorEnabled() {
		return (getLevel() & AnnotationCodeMiningPreferenceConstants.SHOW_ANNOTATION_CODE_MINING_LEVEL__ERROR) > 0;
	}

	public boolean isEnabled() {
		final IPreferenceStore node= getPreferences();
		if (node == null) {
			return false;
		}

		final int max= getMaxMinings();

		return max > 0 && getLevel() > 0;
	}

	int getLevel() {
		IPreferenceStore node= getPreferences();

		return node != null
				? node.getInt(AnnotationCodeMiningPreferenceConstants.SHOW_ANNOTATION_CODE_MINING_LEVEL)
				: AnnotationCodeMiningPreferenceConstants.SHOW_ANNOTATION_CODE_MINING_LEVEL__DEFAULT;
	}

	int getMaxMinings() {
		final IPreferenceStore node= getPreferences();

		return node != null
				? node.getInt(AnnotationCodeMiningPreferenceConstants.SHOW_ANNOTATION_CODE_MINING_MAX)
				: AnnotationCodeMiningPreferenceConstants.SHOW_ANNOTATION_CODE_MINING_MAX__DEFAULT;
	}

	protected @Nullable IPreferenceStore getPreferences() {
		if (preferenceStore == null) {
			preferenceStore= AnnotationCodeMiningPreferenceConstants.getPreferenceStore();
		}

		return preferenceStore;
	}
}

Back to the top