sandbox/java.hints/spi.java.hints/src/org/netbeans/modules/java/hints/providers/spi/HintMetadata.java
1.1 --- a/sandbox/java.hints/spi.java.hints/src/org/netbeans/modules/java/hints/providers/spi/HintMetadata.java Mon Dec 19 11:37:36 2016 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,224 +0,0 @@
1.4 -/*
1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 - *
1.7 - * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
1.8 - *
1.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
1.10 - * Other names may be trademarks of their respective owners.
1.11 - *
1.12 - * The contents of this file are subject to the terms of either the GNU
1.13 - * General Public License Version 2 only ("GPL") or the Common
1.14 - * Development and Distribution License("CDDL") (collectively, the
1.15 - * "License"). You may not use this file except in compliance with the
1.16 - * License. You can obtain a copy of the License at
1.17 - * http://www.netbeans.org/cddl-gplv2.html
1.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.19 - * specific language governing permissions and limitations under the
1.20 - * License. When distributing the software, include this License Header
1.21 - * Notice in each file and include the License file at
1.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
1.23 - * particular file as subject to the "Classpath" exception as provided
1.24 - * by Oracle in the GPL Version 2 section of the License file that
1.25 - * accompanied this code. If applicable, add the following below the
1.26 - * License Header, with the fields enclosed by brackets [] replaced by
1.27 - * your own identifying information:
1.28 - * "Portions Copyrighted [year] [name of copyright owner]"
1.29 - *
1.30 - * If you wish your version of this file to be governed by only the CDDL
1.31 - * or only the GPL Version 2, indicate your decision by adding
1.32 - * "[Contributor] elects to include this software in this distribution
1.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
1.34 - * single choice of license, a recipient has the option to distribute
1.35 - * your version of this file under either the CDDL, the GPL Version 2 or
1.36 - * to extend the choice of license to its licensees as provided above.
1.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
1.38 - * Version 2 license, then the option applies only if the new code is
1.39 - * made subject to such option by the copyright holder.
1.40 - *
1.41 - * Contributor(s):
1.42 - *
1.43 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
1.44 - */
1.45 -
1.46 -package org.netbeans.modules.java.hints.providers.spi;
1.47 -
1.48 -import java.util.ArrayList;
1.49 -import java.util.Arrays;
1.50 -import java.util.Collection;
1.51 -import java.util.EnumSet;
1.52 -import java.util.HashSet;
1.53 -import java.util.MissingResourceException;
1.54 -import java.util.ResourceBundle;
1.55 -import java.util.Set;
1.56 -import java.util.logging.Level;
1.57 -import java.util.logging.Logger;
1.58 -import org.netbeans.spi.editor.hints.Severity;
1.59 -import org.netbeans.spi.java.hints.CustomizerProvider;
1.60 -import org.netbeans.spi.java.hints.Hint;
1.61 -import org.openide.util.NbBundle;
1.62 -
1.63 -/**
1.64 - *
1.65 - * @author lahvac
1.66 - */
1.67 -public class HintMetadata {
1.68 -
1.69 - public final String id;
1.70 - public final String displayName;
1.71 - public final String description;
1.72 - public final String category;
1.73 - public final boolean enabled;
1.74 - public final Hint.Kind kind;
1.75 - public final Severity severity;
1.76 - public final Collection<? extends String> suppressWarnings;
1.77 - public final CustomizerProvider customizer;
1.78 - public final boolean showInTaskList = false;
1.79 - public final Set<Options> options;
1.80 -
1.81 - HintMetadata(String id, String displayName, String description, String category, boolean enabled, Hint.Kind kind, Severity severity, Collection<? extends String> suppressWarnings, CustomizerProvider customizer, Set<Options> options) {
1.82 - this.id = id;
1.83 - this.displayName = displayName;
1.84 - this.description = description;
1.85 - this.category = category;
1.86 - this.enabled = enabled;
1.87 - this.kind = kind;
1.88 - this.severity = severity;
1.89 - this.suppressWarnings = suppressWarnings;
1.90 - this.customizer = customizer;
1.91 - this.options = options;
1.92 - }
1.93 -
1.94 - @Override
1.95 - public String toString() {
1.96 - return this.displayName;
1.97 - }
1.98 -
1.99 - private static String lookup(ResourceBundle bundle, String key, String def) {
1.100 - try {
1.101 - return bundle != null ? bundle.getString(key) : def;
1.102 - } catch (MissingResourceException mre) {
1.103 - Logger.getLogger(HintMetadata.class.getName()).log(Level.FINE, null, mre);
1.104 - return def;
1.105 - }
1.106 - }
1.107 -
1.108 - public static final class Builder {
1.109 - private final String id;
1.110 - private String displayName;
1.111 - private String description;
1.112 - private String category;
1.113 - private boolean enabled;
1.114 - private Hint.Kind kind;
1.115 - private Severity severity;
1.116 - private final Collection<String> suppressWarnings = new ArrayList<String>();
1.117 - private CustomizerProvider customizer;
1.118 - private final Set<Options> options = EnumSet.noneOf(Options.class);
1.119 -
1.120 - private Builder(String id) {
1.121 - this.id = id;
1.122 - this.displayName = "";
1.123 - this.description = "";
1.124 - this.category = "";
1.125 - this.enabled = true;
1.126 - this.kind = Hint.Kind.INSPECTION;
1.127 - this.severity = Severity.VERIFIER;
1.128 - }
1.129 -
1.130 - public static Builder create(String id) {
1.131 - return new Builder(id);
1.132 - }
1.133 -
1.134 - public Builder setDescription(String displayName, String description) {
1.135 - this.displayName = displayName;
1.136 - this.description = description;
1.137 - return this;
1.138 - }
1.139 -
1.140 - public Builder setBundle(ResourceBundle bundle) {
1.141 - return setBundle(bundle, null, null);
1.142 - }
1.143 -
1.144 - public Builder setBundle(ResourceBundle bundle, String fallbackDisplayName, String fallbackDescription) {
1.145 - if (fallbackDisplayName == null) fallbackDisplayName = "No Display Name";
1.146 - if (fallbackDescription == null) fallbackDescription = "No Description";
1.147 -
1.148 - this.displayName = lookup(bundle, "DN_" + id.replace('$', '.'), fallbackDisplayName);
1.149 - this.description = lookup(bundle, "DESC_" + id.replace('$', '.'), fallbackDescription);
1.150 - return this;
1.151 - }
1.152 -
1.153 - public Builder setBundle(String bundleForFQN) {
1.154 - ResourceBundle bundle;
1.155 -
1.156 - try {
1.157 - int lastDot = bundleForFQN.lastIndexOf('.');
1.158 -
1.159 - assert lastDot >= 0;
1.160 -
1.161 - bundle = NbBundle.getBundle(bundleForFQN.substring(0, lastDot + 1) + "Bundle");
1.162 - } catch (MissingResourceException mre) {
1.163 - Logger.getLogger(HintMetadata.class.getName()).log(Level.FINE, null, mre);
1.164 - bundle = null;
1.165 - }
1.166 - return setBundle(bundle);
1.167 - }
1.168 -
1.169 - public Builder setCategory(String category) {
1.170 - this.category = category;
1.171 - return this;
1.172 - }
1.173 -
1.174 - public Builder setEnabled(boolean enabled) {
1.175 - this.enabled = enabled;
1.176 - return this;
1.177 - }
1.178 -
1.179 - public Builder setKind(Hint.Kind kind) {
1.180 - this.kind = kind;
1.181 - return this;
1.182 - }
1.183 -
1.184 - public Builder setSeverity(Severity severity) {
1.185 - this.severity = severity;
1.186 - return this;
1.187 - }
1.188 -
1.189 -
1.190 - public Builder addSuppressWarnings(String... keys) {
1.191 - this.suppressWarnings.addAll(Arrays.asList(keys));
1.192 - return this;
1.193 - }
1.194 -
1.195 - public Builder setCustomizerProvider(CustomizerProvider customizer) {
1.196 - this.customizer = customizer;
1.197 - return this;
1.198 - }
1.199 -
1.200 - public Builder addOptions(Options... options) {
1.201 - this.options.addAll(Arrays.asList(options));
1.202 - return this;
1.203 - }
1.204 -
1.205 - public HintMetadata build() {
1.206 - return new HintMetadata(id, displayName, description, category, enabled, kind, severity, suppressWarnings, customizer, options);
1.207 - }
1.208 -
1.209 - }
1.210 -
1.211 - public enum Options {
1.212 - NON_GUI,
1.213 - QUERY,
1.214 - NO_BATCH,
1.215 - HEAVY;
1.216 -
1.217 - public static Set<Options> fromHintOptions(Hint.Options... options) {
1.218 - Set<Options> result = new HashSet<Options>();
1.219 -
1.220 - for (Hint.Options opt : options) {
1.221 - result.add(valueOf(opt.name()));
1.222 - }
1.223 -
1.224 - return result;
1.225 - }
1.226 - }
1.227 -}