Cleanup: removing hints that were moved to std. distro, replaced by scripts or are simply obsolete.
1.1 --- a/javahints/nbproject/project.properties Thu Nov 17 08:03:22 2011 +0100
1.2 +++ b/javahints/nbproject/project.properties Thu Nov 17 12:37:33 2011 +0100
1.3 @@ -50,7 +50,7 @@
1.4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width=80
1.5 javac.compilerargs=-Xlint:unchecked
1.6 javac.source=1.6
1.7 -spec.version.base=2.51.0
1.8 +spec.version.base=2.52.0
1.9
1.10 nbm.needs.restart=true
1.11 requires.nb.javac=true
2.1 --- a/javahints/src/org/netbeans/modules/javahints/Bundle.properties Thu Nov 17 08:03:22 2011 +0100
2.2 +++ b/javahints/src/org/netbeans/modules/javahints/Bundle.properties Thu Nov 17 12:37:33 2011 +0100
2.3 @@ -142,13 +142,6 @@
2.4 DESC_NegateCondition=Negate if condition
2.5 FIX_NegateCondition=Negate if condition
2.6
2.7 -
2.8 -DESC_ImageUtilities=Deprecation of image related methods in Utilities
2.9 -DN_ImageUtilities=Deprecation of image related methods in Utilities
2.10 -FIX_ImageUtilities=Replace with ImageUtilities
2.11 -
2.12 -CTL_OrganizeImportsAction=Organize Imports
2.13 -
2.14 DSC_Excluded=Visible notice when the Excluder (see Code Completion -> Java) has been violated. Feedback to http://www.netbeans.org/issues/show_bug.cgi?id=125060
2.15 DN_Excluded=Excluded
2.16 HINT_Excluded={0} is in the Exclude list
2.17 @@ -156,9 +149,5 @@
2.18 DN_org.netbeans.modules.javahints.RPD=RequestProcessor.getDefault()
2.19 DESC_org.netbeans.modules.javahints.RPD=RequestProcessor.getDefault()
2.20
2.21 -DN_org.netbeans.modules.javahints.CheckReturnValueHint=@CheckReturnValue
2.22 -DESC_org.netbeans.modules.javahints.CheckReturnValueHint=Verifies that a result of method marked with @CheckReturnValue is really checked.
2.23 -ERR_org.netbeans.modules.javahints.CheckReturnValueHint=Should check the method return value
2.24 -
2.25 DN_MissingReturn=Method Missing a Return Statement
2.26 FIX_AddReturn=Add return statement
3.1 --- a/javahints/src/org/netbeans/modules/javahints/CheckReturnValueHint.java Thu Nov 17 08:03:22 2011 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,100 +0,0 @@
3.4 -/*
3.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3.6 - *
3.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
3.8 - *
3.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
3.10 - * Other names may be trademarks of their respective owners.
3.11 - *
3.12 - * The contents of this file are subject to the terms of either the GNU
3.13 - * General Public License Version 2 only ("GPL") or the Common
3.14 - * Development and Distribution License("CDDL") (collectively, the
3.15 - * "License"). You may not use this file except in compliance with the
3.16 - * License. You can obtain a copy of the License at
3.17 - * http://www.netbeans.org/cddl-gplv2.html
3.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
3.19 - * specific language governing permissions and limitations under the
3.20 - * License. When distributing the software, include this License Header
3.21 - * Notice in each file and include the License file at
3.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
3.23 - * particular file as subject to the "Classpath" exception as provided
3.24 - * by Oracle in the GPL Version 2 section of the License file that
3.25 - * accompanied this code. If applicable, add the following below the
3.26 - * License Header, with the fields enclosed by brackets [] replaced by
3.27 - * your own identifying information:
3.28 - * "Portions Copyrighted [year] [name of copyright owner]"
3.29 - *
3.30 - * If you wish your version of this file to be governed by only the CDDL
3.31 - * or only the GPL Version 2, indicate your decision by adding
3.32 - * "[Contributor] elects to include this software in this distribution
3.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
3.34 - * single choice of license, a recipient has the option to distribute
3.35 - * your version of this file under either the CDDL, the GPL Version 2 or
3.36 - * to extend the choice of license to its licensees as provided above.
3.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
3.38 - * Version 2 license, then the option applies only if the new code is
3.39 - * made subject to such option by the copyright holder.
3.40 - *
3.41 - * Contributor(s):
3.42 - *
3.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
3.44 - */
3.45 -package org.netbeans.modules.javahints;
3.46 -
3.47 -import com.sun.source.tree.ExpressionStatementTree;
3.48 -import com.sun.source.util.TreePath;
3.49 -import java.util.Arrays;
3.50 -import java.util.HashSet;
3.51 -import java.util.Set;
3.52 -import javax.lang.model.element.*;
3.53 -import javax.lang.model.type.TypeKind;
3.54 -import org.netbeans.modules.java.hints.jackpot.code.spi.Hint;
3.55 -import org.netbeans.modules.java.hints.jackpot.code.spi.TriggerPattern;
3.56 -import org.netbeans.modules.java.hints.jackpot.spi.HintContext;
3.57 -import org.netbeans.modules.java.hints.jackpot.spi.support.ErrorDescriptionFactory;
3.58 -import org.netbeans.spi.editor.hints.ErrorDescription;
3.59 -import org.openide.util.NbBundle;
3.60 -
3.61 -/**
3.62 - *
3.63 - * @author lahvac
3.64 - */
3.65 -@Hint(category="bugs", suppressWarnings="ResultOfMethodCallIgnored")
3.66 -public class CheckReturnValueHint {
3.67 -
3.68 - @TriggerPattern("$method($params$);")
3.69 - public static ErrorDescription hint(HintContext ctx) {
3.70 - Element invoked = ctx.getInfo().getTrees().getElement(new TreePath(ctx.getPath(), ((ExpressionStatementTree) ctx.getPath().getLeaf()).getExpression()));
3.71 -
3.72 - if (invoked == null || invoked.getKind() != ElementKind.METHOD || ((ExecutableElement) invoked).getReturnType().getKind() == TypeKind.VOID) return null;
3.73 -
3.74 - boolean found = false;
3.75 -
3.76 - for (AnnotationMirror am : invoked.getAnnotationMirrors()) {
3.77 - String simpleName = am.getAnnotationType().asElement().getSimpleName().toString();
3.78 -
3.79 - if ("CheckReturnValue".equals(simpleName)) {
3.80 - found = true;
3.81 - break;
3.82 - }
3.83 - }
3.84 -
3.85 - if (!found && !checkReturnValueForJDKMethods((ExecutableElement) invoked)) return null;
3.86 -
3.87 - String displayName = NbBundle.getMessage(CheckReturnValueHint.class, "ERR_org.netbeans.modules.javahints.CheckReturnValueHint");
3.88 -
3.89 - return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName);
3.90 - }
3.91 -
3.92 - private static final Set<String> JDK_IMMUTABLE_CLASSES = new HashSet<String>(Arrays.asList("java.lang.String"));
3.93 -
3.94 - private static boolean checkReturnValueForJDKMethods(ExecutableElement method) {
3.95 - Element owner = method.getEnclosingElement();
3.96 -
3.97 - if (!owner.getKind().isClass() && !owner.getKind().isInterface()) return false;
3.98 -
3.99 - if (JDK_IMMUTABLE_CLASSES.contains(((TypeElement) owner).getQualifiedName().toString())) return true;
3.100 -
3.101 - return false;
3.102 - }
3.103 -}
4.1 --- a/javahints/src/org/netbeans/modules/javahints/ImageUtilitiesDeprecation.java Thu Nov 17 08:03:22 2011 +0100
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,155 +0,0 @@
4.4 -/*
4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 - *
4.7 - * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
4.8 - *
4.9 - * The contents of this file are subject to the terms of either the GNU
4.10 - * General Public License Version 2 only ("GPL") or the Common
4.11 - * Development and Distribution License("CDDL") (collectively, the
4.12 - * "License"). You may not use this file except in compliance with the
4.13 - * License. You can obtain a copy of the License at
4.14 - * http://www.netbeans.org/cddl-gplv2.html
4.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.16 - * specific language governing permissions and limitations under the
4.17 - * License. When distributing the software, include this License Header
4.18 - * Notice in each file and include the License file at
4.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
4.20 - * particular file as subject to the "Classpath" exception as provided
4.21 - * by Sun in the GPL Version 2 section of the License file that
4.22 - * accompanied this code. If applicable, add the following below the
4.23 - * License Header, with the fields enclosed by brackets [] replaced by
4.24 - * your own identifying information:
4.25 - * "Portions Copyrighted [year] [name of copyright owner]"
4.26 - *
4.27 - * If you wish your version of this file to be governed by only the CDDL
4.28 - * or only the GPL Version 2, indicate your decision by adding
4.29 - * "[Contributor] elects to include this software in this distribution
4.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
4.31 - * single choice of license, a recipient has the option to distribute
4.32 - * your version of this file under either the CDDL, the GPL Version 2 or
4.33 - * to extend the choice of license to its licensees as provided above.
4.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
4.35 - * Version 2 license, then the option applies only if the new code is
4.36 - * made subject to such option by the copyright holder.
4.37 - *
4.38 - * Contributor(s):
4.39 - *
4.40 - * Portions Copyrighted 2007-2008 Sun Microsystems, Inc.
4.41 - */
4.42 -
4.43 -package org.netbeans.modules.javahints;
4.44 -
4.45 -import com.sun.source.tree.MemberSelectTree;
4.46 -import com.sun.source.tree.MethodInvocationTree;
4.47 -import com.sun.source.tree.Tree.Kind;
4.48 -import com.sun.source.util.TreePath;
4.49 -import java.util.Collection;
4.50 -import java.util.Collections;
4.51 -import java.util.EnumSet;
4.52 -import java.util.List;
4.53 -import java.util.Set;
4.54 -import javax.lang.model.element.Element;
4.55 -import javax.lang.model.element.Name;
4.56 -import javax.lang.model.element.TypeElement;
4.57 -import javax.lang.model.type.TypeMirror;
4.58 -import org.netbeans.api.java.source.CompilationInfo;
4.59 -import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory;
4.60 -import org.netbeans.modules.java.hints.jackpot.spi.JavaFix;
4.61 -import org.netbeans.modules.java.hints.spi.AbstractHint;
4.62 -import org.netbeans.spi.editor.hints.ErrorDescription;
4.63 -import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
4.64 -import org.netbeans.spi.editor.hints.Fix;
4.65 -import org.openide.util.NbBundle;
4.66 -
4.67 -/**
4.68 - *
4.69 - * @author Jaroslav Tulach
4.70 - */
4.71 -public class ImageUtilitiesDeprecation extends AbstractHint {
4.72 -
4.73 - public ImageUtilitiesDeprecation() {
4.74 - super(false, false, HintSeverity.WARNING);
4.75 - }
4.76 -
4.77 - @Override
4.78 - public String getDescription() {
4.79 - return NbBundle.getMessage(ImageUtilitiesDeprecation.class, "DESC_ImageUtilities");
4.80 - }
4.81 -
4.82 - public Set<Kind> getTreeKinds() {
4.83 - return EnumSet.of(Kind.METHOD_INVOCATION);
4.84 - }
4.85 -
4.86 - public List<ErrorDescription> run(CompilationInfo compilationInfo, TreePath treePath) {
4.87 - return run(compilationInfo, treePath, CaretAwareJavaSourceTaskFactory.getLastPosition(compilationInfo.getFileObject()));
4.88 - }
4.89 -
4.90 - protected List<ErrorDescription> run(CompilationInfo info, TreePath treePath, int offset) {
4.91 - if (!Kind.METHOD_INVOCATION.equals(treePath.getLeaf().getKind())) {
4.92 - return null;
4.93 - }
4.94 - MethodInvocationTree mit = (MethodInvocationTree) treePath.getLeaf();
4.95 - TreePath ms = new TreePath(treePath, mit.getMethodSelect());
4.96 - Element e = info.getTrees().getElement(ms);
4.97 - if (e == null) {
4.98 - return null;
4.99 - }
4.100 - Name sn = e.getSimpleName();
4.101 - if (
4.102 - sn.contentEquals("loadImage") ||
4.103 - sn.contentEquals("mergeImages") ||
4.104 - sn.contentEquals("icon2Image")
4.105 - ) {
4.106 - TypeElement enclose = info.getElementUtilities().enclosingTypeElement(e);
4.107 - if (enclose == null) {
4.108 - return null;
4.109 - }
4.110 - Name qn = enclose.getQualifiedName();
4.111 - if (qn == null || !qn.contentEquals("org.openide.util.Utilities")) {
4.112 - return null;
4.113 - }
4.114 - int[] span;
4.115 -
4.116 - switch (mit.getMethodSelect().getKind()) {
4.117 - case MEMBER_SELECT: span = info.getTreeUtilities().findNameSpan((MemberSelectTree) mit.getMethodSelect()); break;
4.118 - case IDENTIFIER:
4.119 - span = new int[2];
4.120 - span[0] = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), mit.getMethodSelect());
4.121 - span[1] = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), mit.getMethodSelect());
4.122 - break;
4.123 - default:
4.124 - span = null;
4.125 - }
4.126 -
4.127 - if (span == null) {
4.128 - return null;
4.129 - }
4.130 -
4.131 - String fixDN = NbBundle.getMessage(ImageUtilitiesDeprecation.class, "FIX_ImageUtilities");
4.132 - Fix fix = JavaFix.rewriteFix(info,
4.133 - fixDN,
4.134 - ms,
4.135 - "org.openide.util.ImageUtilities." + e.getSimpleName().toString(),
4.136 - Collections.<String, TreePath>emptyMap(),
4.137 - Collections.<String, Collection<? extends TreePath>>emptyMap(),
4.138 - Collections.<String, String>emptyMap(),
4.139 - Collections.<String, TypeMirror>emptyMap());
4.140 - List<Fix> fixes = Collections.<Fix>singletonList(fix);
4.141 - ErrorDescription w = ErrorDescriptionFactory.createErrorDescription(getSeverity().toEditorSeverity(), "Use of Utilities." + e.getSimpleName().toString(), fixes, info.getFileObject(), span[0], span[1]);
4.142 - return Collections.singletonList(w);
4.143 - }
4.144 - return null;
4.145 - }
4.146 -
4.147 - public String getId() {
4.148 - return ImageUtilitiesDeprecation.class.getName();
4.149 - }
4.150 -
4.151 - public String getDisplayName() {
4.152 - return NbBundle.getMessage(ImageUtilitiesDeprecation.class, "DN_ImageUtilities");
4.153 - }
4.154 -
4.155 - public void cancel() {
4.156 - }
4.157 -
4.158 -}
5.1 --- a/javahints/src/org/netbeans/modules/javahints/OrganizeImports.java Thu Nov 17 08:03:22 2011 +0100
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,215 +0,0 @@
5.4 -/*
5.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5.6 - *
5.7 - * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5.8 - *
5.9 - * The contents of this file are subject to the terms of either the GNU
5.10 - * General Public License Version 2 only ("GPL") or the Common
5.11 - * Development and Distribution License("CDDL") (collectively, the
5.12 - * "License"). You may not use this file except in compliance with the
5.13 - * License. You can obtain a copy of the License at
5.14 - * http://www.netbeans.org/cddl-gplv2.html
5.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
5.16 - * specific language governing permissions and limitations under the
5.17 - * License. When distributing the software, include this License Header
5.18 - * Notice in each file and include the License file at
5.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
5.20 - * particular file as subject to the "Classpath" exception as provided
5.21 - * by Sun in the GPL Version 2 section of the License file that
5.22 - * accompanied this code. If applicable, add the following below the
5.23 - * License Header, with the fields enclosed by brackets [] replaced by
5.24 - * your own identifying information:
5.25 - * "Portions Copyrighted [year] [name of copyright owner]"
5.26 - *
5.27 - * If you wish your version of this file to be governed by only the CDDL
5.28 - * or only the GPL Version 2, indicate your decision by adding
5.29 - * "[Contributor] elects to include this software in this distribution
5.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
5.31 - * single choice of license, a recipient has the option to distribute
5.32 - * your version of this file under either the CDDL, the GPL Version 2 or
5.33 - * to extend the choice of license to its licensees as provided above.
5.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
5.35 - * Version 2 license, then the option applies only if the new code is
5.36 - * made subject to such option by the copyright holder.
5.37 - *
5.38 - * Contributor(s):
5.39 - *
5.40 - * Portions Copyrighted 2008 Sun Microsystems, Inc.
5.41 - */
5.42 -
5.43 -package org.netbeans.modules.javahints;
5.44 -
5.45 -import com.sun.source.tree.ClassTree;
5.46 -import com.sun.source.tree.CompilationUnitTree;
5.47 -import com.sun.source.tree.IdentifierTree;
5.48 -import com.sun.source.tree.ImportTree;
5.49 -import com.sun.source.tree.MemberSelectTree;
5.50 -import com.sun.source.tree.Tree.Kind;
5.51 -import com.sun.source.util.TreePath;
5.52 -import com.sun.source.util.TreePathScanner;
5.53 -import java.io.IOException;
5.54 -import java.util.Arrays;
5.55 -import java.util.Collections;
5.56 -import java.util.EnumSet;
5.57 -import java.util.HashSet;
5.58 -import java.util.List;
5.59 -import java.util.Set;
5.60 -import javax.lang.model.element.Element;
5.61 -import javax.lang.model.element.ElementKind;
5.62 -import javax.swing.text.StyledDocument;
5.63 -import org.netbeans.api.editor.guards.GuardedSectionManager;
5.64 -import org.netbeans.api.java.source.CompilationInfo;
5.65 -import org.netbeans.api.java.source.WorkingCopy;
5.66 -import org.netbeans.modules.java.hints.jackpot.spi.JavaFix;
5.67 -import org.netbeans.modules.java.hints.spi.AbstractHint;
5.68 -import org.netbeans.spi.editor.hints.ErrorDescription;
5.69 -import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
5.70 -import org.netbeans.spi.editor.hints.Fix;
5.71 -import org.netbeans.spi.editor.hints.Severity;
5.72 -import org.openide.util.Exceptions;
5.73 -
5.74 -/**
5.75 - *
5.76 - * @author Jan Lahoda
5.77 - */
5.78 -public class OrganizeImports extends AbstractHint {
5.79 -
5.80 - public OrganizeImports() {
5.81 - super(false, false, HintSeverity.WARNING);
5.82 - }
5.83 -
5.84 - @Override
5.85 - public String getDescription() {
5.86 - return "Organize Imports";
5.87 - }
5.88 -
5.89 - public Set<Kind> getTreeKinds() {
5.90 - return EnumSet.of(Kind.COMPILATION_UNIT);
5.91 - }
5.92 -
5.93 - public List<ErrorDescription> run(CompilationInfo info, TreePath treePath) {
5.94 - try {
5.95 - StyledDocument doc = (StyledDocument) info.getDocument();
5.96 - if (doc == null || GuardedSectionManager.getInstance(doc) != null) {
5.97 - return null;
5.98 - }
5.99 - } catch (IOException ex) {
5.100 - Exceptions.printStackTrace(ex);
5.101 - }
5.102 -
5.103 - Fix f = JavaFix.toEditorFix(new FixImpl(info));
5.104 - List<Fix> l = Collections.singletonList(f);
5.105 - ErrorDescription ed = ErrorDescriptionFactory.createErrorDescription(Severity.WARNING, "Organize Imports", l, info.getFileObject(), 0, 1);
5.106 -
5.107 - return Collections.singletonList(ed);
5.108 - }
5.109 -
5.110 - public String getId() {
5.111 - return OrganizeImports.class.getName();
5.112 - }
5.113 -
5.114 - public String getDisplayName() {
5.115 - return "Organize Imports";
5.116 - }
5.117 -
5.118 - public void cancel() {
5.119 - }
5.120 -
5.121 - private static final class FixImpl extends JavaFix {
5.122 -
5.123 - public FixImpl(CompilationInfo info) {
5.124 - super(info, new TreePath(info.getCompilationUnit()));
5.125 - }
5.126 -
5.127 - public String getText() {
5.128 - return "Organize Imports";
5.129 - }
5.130 -
5.131 - @Override
5.132 - protected void performRewrite(WorkingCopy wc, TreePath tp, boolean canShowUI) {
5.133 - organizeImports(wc);
5.134 - }
5.135 - }
5.136 -
5.137 - private static void organizeImports(WorkingCopy copy) {
5.138 - CompilationUnitTree old = copy.getCompilationUnit();
5.139 -
5.140 - new ReplaceQualifiedNames(copy).scan(old, null);
5.141 -
5.142 - CompilationUnitTree nue = copy.getTreeMaker().CompilationUnit(old.getPackageName(), Collections.<ImportTree>emptyList(), old.getTypeDecls(), old.getSourceFile());
5.143 -
5.144 - copy.rewrite(old, nue);
5.145 - }
5.146 -
5.147 - private static final class ReplaceQualifiedNames extends TreePathScanner<Void, Void> {
5.148 -
5.149 - private final WorkingCopy copy;
5.150 -
5.151 - public ReplaceQualifiedNames(WorkingCopy copy) {
5.152 - this.copy = copy;
5.153 - }
5.154 -
5.155 - private static final Set<String> PROHIBITED_NAMES = new HashSet<String>(Arrays.asList("super", "this", "<init>"));
5.156 -
5.157 - private static final Set<ElementKind> SITES_GOOD_FOR_IMPORTS = EnumSet.of(ElementKind.ANNOTATION_TYPE, ElementKind.CLASS, ElementKind.ENUM, ElementKind.INTERFACE, ElementKind.PACKAGE);
5.158 -
5.159 - @Override
5.160 - public Void visitMemberSelect(MemberSelectTree node, Void p) {
5.161 - if (PROHIBITED_NAMES.contains(node.getIdentifier().toString())) {
5.162 - return super.visitMemberSelect(node, p);
5.163 - }
5.164 -
5.165 - Element e = copy.getTrees().getElement(getCurrentPath());
5.166 - Element site = copy.getTrees().getElement(new TreePath(getCurrentPath(), node.getExpression()));
5.167 -
5.168 - if (e != null && site != null && SITES_GOOD_FOR_IMPORTS.contains(site.getKind())) {
5.169 - copy.rewrite(node, copy.getTreeMaker().QualIdent(e));
5.170 - return null;
5.171 - }
5.172 -
5.173 - return super.visitMemberSelect(node, p);
5.174 - }
5.175 -
5.176 - private static final Set<ElementKind> LOCAL_VARIABLES = EnumSet.of(ElementKind.EXCEPTION_PARAMETER, ElementKind.LOCAL_VARIABLE, ElementKind.PARAMETER);
5.177 -
5.178 - @Override
5.179 - public Void visitIdentifier(IdentifierTree node, Void p) {
5.180 - if (PROHIBITED_NAMES.contains(node.getName().toString())) {
5.181 - return super.visitIdentifier(node, p);
5.182 - }
5.183 -
5.184 - Element e = copy.getTrees().getElement(getCurrentPath());
5.185 -
5.186 - if (e != null && !LOCAL_VARIABLES.contains(e.getKind())) {
5.187 - if (e.getKind().isClass() || e.getKind().isInterface()) {
5.188 - copy.rewrite(node, copy.getTreeMaker().QualIdent(e));
5.189 - return null;
5.190 - }
5.191 -
5.192 - if (!classes.contains(e.getEnclosingElement())) {
5.193 - copy.rewrite(node, copy.getTreeMaker().QualIdent(e));
5.194 - return null;
5.195 - }
5.196 - }
5.197 -
5.198 - return super.visitIdentifier(node, p);
5.199 - }
5.200 -
5.201 - @Override
5.202 - public Void visitCompilationUnit(CompilationUnitTree node, Void p) {
5.203 - scan(node.getPackageAnnotations(), p);
5.204 - scan(node.getImports(), p);
5.205 - scan(node.getTypeDecls(), p);
5.206 - return null;
5.207 - }
5.208 -
5.209 - private final Set<Element> classes = new HashSet<Element>();
5.210 -
5.211 - @Override
5.212 - public Void visitClass(ClassTree node, Void p) {
5.213 - classes.add(copy.getTrees().getElement(getCurrentPath()));
5.214 - return super.visitClass(node, p);
5.215 - }
5.216 -
5.217 - }
5.218 -}
6.1 --- a/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscores.java Thu Nov 17 08:03:22 2011 +0100
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,222 +0,0 @@
6.4 -/*
6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6.6 - *
6.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
6.8 - *
6.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6.10 - * Other names may be trademarks of their respective owners.
6.11 - *
6.12 - * The contents of this file are subject to the terms of either the GNU
6.13 - * General Public License Version 2 only ("GPL") or the Common
6.14 - * Development and Distribution License("CDDL") (collectively, the
6.15 - * "License"). You may not use this file except in compliance with the
6.16 - * License. You can obtain a copy of the License at
6.17 - * http://www.netbeans.org/cddl-gplv2.html
6.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
6.19 - * specific language governing permissions and limitations under the
6.20 - * License. When distributing the software, include this License Header
6.21 - * Notice in each file and include the License file at
6.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
6.23 - * particular file as subject to the "Classpath" exception as provided
6.24 - * by Oracle in the GPL Version 2 section of the License file that
6.25 - * accompanied this code. If applicable, add the following below the
6.26 - * License Header, with the fields enclosed by brackets [] replaced by
6.27 - * your own identifying information:
6.28 - * "Portions Copyrighted [year] [name of copyright owner]"
6.29 - *
6.30 - * If you wish your version of this file to be governed by only the CDDL
6.31 - * or only the GPL Version 2, indicate your decision by adding
6.32 - * "[Contributor] elects to include this software in this distribution
6.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
6.34 - * single choice of license, a recipient has the option to distribute
6.35 - * your version of this file under either the CDDL, the GPL Version 2 or
6.36 - * to extend the choice of license to its licensees as provided above.
6.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
6.38 - * Version 2 license, then the option applies only if the new code is
6.39 - * made subject to such option by the copyright holder.
6.40 - *
6.41 - * Contributor(s):
6.42 - *
6.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
6.44 - */
6.45 -package org.netbeans.modules.javahints.jdk;
6.46 -
6.47 -import com.sun.source.tree.Tree.Kind;
6.48 -import com.sun.source.util.TreePath;
6.49 -import java.util.prefs.Preferences;
6.50 -import java.util.regex.Pattern;
6.51 -import javax.lang.model.SourceVersion;
6.52 -import javax.swing.JComponent;
6.53 -import org.netbeans.api.java.source.CompilationInfo;
6.54 -import org.netbeans.api.java.source.WorkingCopy;
6.55 -import org.netbeans.modules.java.hints.jackpot.code.spi.Hint;
6.56 -import org.netbeans.modules.java.hints.jackpot.code.spi.TriggerTreeKind;
6.57 -import org.netbeans.modules.java.hints.jackpot.spi.CustomizerProvider;
6.58 -import org.netbeans.modules.java.hints.jackpot.spi.HintContext;
6.59 -import org.netbeans.modules.java.hints.jackpot.spi.JavaFix;
6.60 -import org.netbeans.modules.java.hints.jackpot.spi.support.ErrorDescriptionFactory;
6.61 -import org.netbeans.modules.javahints.jdk.AddUnderscores.CustomizerProviderImpl;
6.62 -import org.netbeans.modules.java.hints.spi.AbstractHint.HintSeverity;
6.63 -import org.netbeans.spi.editor.hints.ErrorDescription;
6.64 -import org.netbeans.spi.editor.hints.Fix;
6.65 -import org.openide.util.NbBundle;
6.66 -
6.67 -/**
6.68 - *
6.69 - * @author lahvac
6.70 - */
6.71 -@Hint(id=AddUnderscores.ID, category="rules15", enabled=false, severity=HintSeverity.CURRENT_LINE_WARNING, customizerProvider=CustomizerProviderImpl.class)
6.72 -public class AddUnderscores {
6.73 - public static final String ID = "org.netbeans.modules.javahints.jdk.AddUnderscores";
6.74 -
6.75 - @TriggerTreeKind({Kind.INT_LITERAL, Kind.LONG_LITERAL})
6.76 - public static ErrorDescription hint(HintContext ctx) {
6.77 - if (ctx.getInfo().getSourceVersion().compareTo(SourceVersion.RELEASE_7) < 0) return null;
6.78 -
6.79 - TreePath tp = ctx.getPath();
6.80 - int start = (int) ctx.getInfo().getTrees().getSourcePositions().getStartPosition(tp.getCompilationUnit(), tp.getLeaf());
6.81 - int end = (int) ctx.getInfo().getTrees().getSourcePositions().getEndPosition(tp.getCompilationUnit(), tp.getLeaf());
6.82 - String literal = ctx.getInfo().getText().substring(start, end);
6.83 - if (!isReplaceLiteralsWithUnderscores(ctx.getPreferences()) && literal.contains("_")) return null;
6.84 - RadixInfo info = radixInfo(literal);
6.85 - if (info.radix == 8) return null;//octals ignored for now
6.86 - String normalized = info.constant.replaceAll(Pattern.quote("_"), "");
6.87 - int separateCount = getSizeForRadix(ctx.getPreferences(), info.radix);
6.88 - StringBuilder split = new StringBuilder();
6.89 - int count = separateCount + 1;
6.90 -
6.91 - for (int i = normalized.length(); i > 0; i--) {
6.92 - if (--count == 0) {
6.93 - split.append("_");
6.94 - count = separateCount;
6.95 - }
6.96 - split.append(normalized.charAt(i - 1));
6.97 - }
6.98 -
6.99 - split.reverse();
6.100 -
6.101 - String result = info.prefix + split.toString() + info.suffix;
6.102 -
6.103 - if (result.equals(literal)) return null;
6.104 -
6.105 - String displayName = NbBundle.getMessage(AddUnderscores.class, "ERR_" + ID);
6.106 - Fix f = JavaFix.toEditorFix(new FixImpl(ctx.getInfo(), tp, result));
6.107 -
6.108 - return ErrorDescriptionFactory.forTree(ctx, tp, displayName, f);
6.109 - }
6.110 -
6.111 - private static final String KEY_SIZE_BINARY = "size-binary";
6.112 - private static final String KEY_SIZE_DECIMAL = "size-decimal";
6.113 - private static final String KEY_SIZE_HEXADECIMAL = "size-hexadecimal";
6.114 - private static final String KEY_ALSO_WITH_UNDERSCORES = "also-with-underscores";
6.115 -
6.116 - static int getSizeForRadix(Preferences prefs, int radix) {
6.117 - String key;
6.118 - int def;
6.119 -
6.120 - switch (radix) {
6.121 - case 2: key = KEY_SIZE_BINARY; def = 4; break;
6.122 - case 10: key = KEY_SIZE_DECIMAL; def = 3; break;
6.123 - case 16: key = KEY_SIZE_HEXADECIMAL; def = 4; break;
6.124 - default: throw new IllegalStateException("radix=" + radix);
6.125 - }
6.126 -
6.127 - return prefs.getInt(key, def);
6.128 - }
6.129 -
6.130 - static boolean isReplaceLiteralsWithUnderscores(Preferences prefs) {
6.131 - return prefs.getBoolean(KEY_ALSO_WITH_UNDERSCORES, false);
6.132 - }
6.133 -
6.134 - static void setSizeForRadix(Preferences prefs, int radix, int size) {
6.135 - String key;
6.136 -
6.137 - switch (radix) {
6.138 - case 2: key = KEY_SIZE_BINARY; break;
6.139 - case 10: key = KEY_SIZE_DECIMAL; break;
6.140 - case 16: key = KEY_SIZE_HEXADECIMAL; break;
6.141 - default: throw new IllegalStateException("radix=" + radix);
6.142 - }
6.143 -
6.144 - prefs.putInt(key, size);
6.145 - }
6.146 -
6.147 - static void setReplaceLiteralsWithUnderscores(Preferences prefs, boolean value) {
6.148 - prefs.putBoolean(KEY_ALSO_WITH_UNDERSCORES, value);
6.149 - }
6.150 -
6.151 -
6.152 - public static RadixInfo radixInfo(String literal) {
6.153 - String suffix = "";
6.154 -
6.155 - if (literal.endsWith("l") || literal.endsWith("L")) {
6.156 - suffix = literal.substring(literal.length() - 1);
6.157 - literal = literal.substring(0, literal.length() - 1);
6.158 - }
6.159 -
6.160 - int currentRadix = 10;
6.161 - String prefix = "";
6.162 -
6.163 - if (literal.startsWith("0x") || literal.startsWith("0X")) {
6.164 - currentRadix = 16;
6.165 - prefix = literal.substring(0, 2);
6.166 - literal = literal.substring(2);
6.167 - } else if (literal.startsWith("0b") || literal.startsWith("0B")) {
6.168 - currentRadix = 2;
6.169 - prefix = literal.substring(0, 2);
6.170 - literal = literal.substring(2);
6.171 - } else if (literal.startsWith("0") && literal.length() > 1) {
6.172 - currentRadix = 8;
6.173 - prefix = literal.substring(0, 1);
6.174 - literal = literal.substring(1);
6.175 - }
6.176 -
6.177 - return new RadixInfo(prefix, literal, suffix, currentRadix);
6.178 - }
6.179 -
6.180 - public static final class RadixInfo {
6.181 - public final String prefix;
6.182 - public final String constant;
6.183 - public final String suffix;
6.184 - public final int radix;
6.185 -
6.186 - public RadixInfo(String prefix, String constant, String suffix, int radix) {
6.187 - this.prefix = prefix;
6.188 - this.constant = constant;
6.189 - this.suffix = suffix;
6.190 - this.radix = radix;
6.191 - }
6.192 -
6.193 - }
6.194 -
6.195 - private static final class FixImpl extends JavaFix {
6.196 -
6.197 - private final String target;
6.198 -
6.199 - public FixImpl(CompilationInfo info, TreePath tp, String target) {
6.200 - super(info, tp);
6.201 - this.target = target;
6.202 - }
6.203 -
6.204 -
6.205 - @Override
6.206 - protected String getText() {
6.207 - return NbBundle.getMessage(AddUnderscores.class, "FIX_" + ID, target);
6.208 - }
6.209 -
6.210 - @Override
6.211 - protected void performRewrite(WorkingCopy wc, TreePath tp, boolean canShowUI) {
6.212 - wc.rewrite(tp.getLeaf(), wc.getTreeMaker().Identifier(target));
6.213 - }
6.214 -
6.215 - }
6.216 -
6.217 - public static final class CustomizerProviderImpl implements CustomizerProvider {
6.218 -
6.219 - @Override
6.220 - public JComponent getCustomizer(Preferences prefs) {
6.221 - return new AddUnderscoresPanel(prefs);
6.222 - }
6.223 -
6.224 - }
6.225 -}
7.1 --- a/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscoresPanel.form Thu Nov 17 08:03:22 2011 +0100
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,114 +0,0 @@
7.4 -<?xml version="1.0" encoding="UTF-8" ?>
7.5 -
7.6 -<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
7.7 - <AuxValues>
7.8 - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
7.9 - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7.10 - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
7.11 - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
7.12 - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
7.13 - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
7.14 - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
7.15 - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
7.16 - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
7.17 - </AuxValues>
7.18 -
7.19 - <Layout>
7.20 - <DimensionLayout dim="0">
7.21 - <Group type="103" groupAlignment="0" attributes="0">
7.22 - <Group type="102" attributes="0">
7.23 - <EmptySpace max="-2" attributes="0"/>
7.24 - <Group type="103" groupAlignment="0" attributes="0">
7.25 - <Component id="replaceExisting" alignment="0" min="-2" max="-2" attributes="0"/>
7.26 - <Group type="102" alignment="0" attributes="0">
7.27 - <Group type="103" groupAlignment="0" attributes="0">
7.28 - <Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/>
7.29 - <Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
7.30 - <Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
7.31 - </Group>
7.32 - <EmptySpace max="-2" attributes="0"/>
7.33 - <Group type="103" groupAlignment="0" attributes="0">
7.34 - <Component id="binary" min="-2" max="-2" attributes="0"/>
7.35 - <Component id="decimal" min="-2" max="-2" attributes="0"/>
7.36 - <Component id="hexa" min="-2" max="-2" attributes="0"/>
7.37 - </Group>
7.38 - </Group>
7.39 - </Group>
7.40 - <EmptySpace max="32767" attributes="0"/>
7.41 - </Group>
7.42 - </Group>
7.43 - </DimensionLayout>
7.44 - <DimensionLayout dim="1">
7.45 - <Group type="103" groupAlignment="0" attributes="0">
7.46 - <Group type="102" alignment="0" attributes="0">
7.47 - <EmptySpace max="-2" attributes="0"/>
7.48 - <Group type="103" groupAlignment="3" attributes="0">
7.49 - <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
7.50 - <Component id="binary" alignment="3" min="-2" max="-2" attributes="0"/>
7.51 - </Group>
7.52 - <EmptySpace type="separate" max="-2" attributes="0"/>
7.53 - <Group type="103" groupAlignment="3" attributes="0">
7.54 - <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
7.55 - <Component id="decimal" alignment="3" min="-2" max="-2" attributes="0"/>
7.56 - </Group>
7.57 - <EmptySpace type="separate" max="-2" attributes="0"/>
7.58 - <Group type="103" groupAlignment="3" attributes="0">
7.59 - <Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
7.60 - <Component id="hexa" alignment="3" min="-2" max="-2" attributes="0"/>
7.61 - </Group>
7.62 - <EmptySpace type="separate" max="-2" attributes="0"/>
7.63 - <Component id="replaceExisting" min="-2" max="-2" attributes="0"/>
7.64 - <EmptySpace max="32767" attributes="0"/>
7.65 - </Group>
7.66 - </Group>
7.67 - </DimensionLayout>
7.68 - </Layout>
7.69 - <SubComponents>
7.70 - <Component class="javax.swing.JLabel" name="jLabel1">
7.71 - <Properties>
7.72 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
7.73 - <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
7.74 - </Property>
7.75 - </Properties>
7.76 - </Component>
7.77 - <Component class="javax.swing.JLabel" name="jLabel2">
7.78 - <Properties>
7.79 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
7.80 - <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
7.81 - </Property>
7.82 - </Properties>
7.83 - </Component>
7.84 - <Component class="javax.swing.JLabel" name="jLabel3">
7.85 - <Properties>
7.86 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
7.87 - <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.jLabel3.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
7.88 - </Property>
7.89 - </Properties>
7.90 - </Component>
7.91 - <Component class="javax.swing.JSpinner" name="binary">
7.92 - <Events>
7.93 - <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="binaryStateChanged"/>
7.94 - </Events>
7.95 - </Component>
7.96 - <Component class="javax.swing.JSpinner" name="decimal">
7.97 - <Events>
7.98 - <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="decimalStateChanged"/>
7.99 - </Events>
7.100 - </Component>
7.101 - <Component class="javax.swing.JSpinner" name="hexa">
7.102 - <Events>
7.103 - <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="hexaStateChanged"/>
7.104 - </Events>
7.105 - </Component>
7.106 - <Component class="javax.swing.JCheckBox" name="replaceExisting">
7.107 - <Properties>
7.108 - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
7.109 - <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.replaceExisting.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
7.110 - </Property>
7.111 - </Properties>
7.112 - <Events>
7.113 - <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="replaceExistingStateChanged"/>
7.114 - </Events>
7.115 - </Component>
7.116 - </SubComponents>
7.117 -</Form>
8.1 --- a/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscoresPanel.java Thu Nov 17 08:03:22 2011 +0100
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,181 +0,0 @@
8.4 -/*
8.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8.6 - *
8.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
8.8 - *
8.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8.10 - * Other names may be trademarks of their respective owners.
8.11 - *
8.12 - * The contents of this file are subject to the terms of either the GNU
8.13 - * General Public License Version 2 only ("GPL") or the Common
8.14 - * Development and Distribution License("CDDL") (collectively, the
8.15 - * "License"). You may not use this file except in compliance with the
8.16 - * License. You can obtain a copy of the License at
8.17 - * http://www.netbeans.org/cddl-gplv2.html
8.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
8.19 - * specific language governing permissions and limitations under the
8.20 - * License. When distributing the software, include this License Header
8.21 - * Notice in each file and include the License file at
8.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
8.23 - * particular file as subject to the "Classpath" exception as provided
8.24 - * by Oracle in the GPL Version 2 section of the License file that
8.25 - * accompanied this code. If applicable, add the following below the
8.26 - * License Header, with the fields enclosed by brackets [] replaced by
8.27 - * your own identifying information:
8.28 - * "Portions Copyrighted [year] [name of copyright owner]"
8.29 - *
8.30 - * If you wish your version of this file to be governed by only the CDDL
8.31 - * or only the GPL Version 2, indicate your decision by adding
8.32 - * "[Contributor] elects to include this software in this distribution
8.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
8.34 - * single choice of license, a recipient has the option to distribute
8.35 - * your version of this file under either the CDDL, the GPL Version 2 or
8.36 - * to extend the choice of license to its licensees as provided above.
8.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
8.38 - * Version 2 license, then the option applies only if the new code is
8.39 - * made subject to such option by the copyright holder.
8.40 - *
8.41 - * Contributor(s):
8.42 - *
8.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
8.44 - */
8.45 -package org.netbeans.modules.javahints.jdk;
8.46 -
8.47 -import java.util.prefs.Preferences;
8.48 -
8.49 -/**
8.50 - *
8.51 - * @author lahvac
8.52 - */
8.53 -public class AddUnderscoresPanel extends javax.swing.JPanel {
8.54 -
8.55 - private final Preferences prefs;
8.56 -
8.57 - /**
8.58 - * Creates new form AddUnderscoresPanel
8.59 - */
8.60 - public AddUnderscoresPanel(Preferences prefs) {
8.61 - initComponents();
8.62 - this.prefs = prefs;
8.63 -
8.64 - binary.setValue(AddUnderscores.getSizeForRadix(prefs, 2));
8.65 - decimal.setValue(AddUnderscores.getSizeForRadix(prefs, 10));
8.66 - hexa.setValue(AddUnderscores.getSizeForRadix(prefs, 16));
8.67 - replaceExisting.setSelected(AddUnderscores.isReplaceLiteralsWithUnderscores(prefs));
8.68 - }
8.69 -
8.70 - /**
8.71 - * This method is called from within the constructor to initialize the form.
8.72 - * WARNING: Do NOT modify this code. The content of this method is always
8.73 - * regenerated by the Form Editor.
8.74 - */
8.75 - @SuppressWarnings("unchecked")
8.76 - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
8.77 - private void initComponents() {
8.78 -
8.79 - jLabel1 = new javax.swing.JLabel();
8.80 - jLabel2 = new javax.swing.JLabel();
8.81 - jLabel3 = new javax.swing.JLabel();
8.82 - binary = new javax.swing.JSpinner();
8.83 - decimal = new javax.swing.JSpinner();
8.84 - hexa = new javax.swing.JSpinner();
8.85 - replaceExisting = new javax.swing.JCheckBox();
8.86 -
8.87 - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.jLabel1.text")); // NOI18N
8.88 -
8.89 - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.jLabel2.text")); // NOI18N
8.90 -
8.91 - org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.jLabel3.text")); // NOI18N
8.92 -
8.93 - binary.addChangeListener(new javax.swing.event.ChangeListener() {
8.94 - public void stateChanged(javax.swing.event.ChangeEvent evt) {
8.95 - binaryStateChanged(evt);
8.96 - }
8.97 - });
8.98 -
8.99 - decimal.addChangeListener(new javax.swing.event.ChangeListener() {
8.100 - public void stateChanged(javax.swing.event.ChangeEvent evt) {
8.101 - decimalStateChanged(evt);
8.102 - }
8.103 - });
8.104 -
8.105 - hexa.addChangeListener(new javax.swing.event.ChangeListener() {
8.106 - public void stateChanged(javax.swing.event.ChangeEvent evt) {
8.107 - hexaStateChanged(evt);
8.108 - }
8.109 - });
8.110 -
8.111 - org.openide.awt.Mnemonics.setLocalizedText(replaceExisting, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.replaceExisting.text")); // NOI18N
8.112 - replaceExisting.addChangeListener(new javax.swing.event.ChangeListener() {
8.113 - public void stateChanged(javax.swing.event.ChangeEvent evt) {
8.114 - replaceExistingStateChanged(evt);
8.115 - }
8.116 - });
8.117 -
8.118 - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
8.119 - this.setLayout(layout);
8.120 - layout.setHorizontalGroup(
8.121 - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
8.122 - .addGroup(layout.createSequentialGroup()
8.123 - .addContainerGap()
8.124 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
8.125 - .addComponent(replaceExisting)
8.126 - .addGroup(layout.createSequentialGroup()
8.127 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
8.128 - .addComponent(jLabel3)
8.129 - .addComponent(jLabel2)
8.130 - .addComponent(jLabel1))
8.131 - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
8.132 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
8.133 - .addComponent(binary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
8.134 - .addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
8.135 - .addComponent(hexa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
8.136 - .addContainerGap())
8.137 - );
8.138 - layout.setVerticalGroup(
8.139 - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
8.140 - .addGroup(layout.createSequentialGroup()
8.141 - .addContainerGap()
8.142 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
8.143 - .addComponent(jLabel1)
8.144 - .addComponent(binary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
8.145 - .addGap(18, 18, 18)
8.146 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
8.147 - .addComponent(jLabel2)
8.148 - .addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
8.149 - .addGap(18, 18, 18)
8.150 - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
8.151 - .addComponent(jLabel3)
8.152 - .addComponent(hexa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
8.153 - .addGap(18, 18, 18)
8.154 - .addComponent(replaceExisting)
8.155 - .addContainerGap())
8.156 - );
8.157 - }// </editor-fold>//GEN-END:initComponents
8.158 -
8.159 - private void binaryStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_binaryStateChanged
8.160 - AddUnderscores.setSizeForRadix(prefs, 2, (Integer) binary.getValue());
8.161 - }//GEN-LAST:event_binaryStateChanged
8.162 -
8.163 - private void decimalStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_decimalStateChanged
8.164 - AddUnderscores.setSizeForRadix(prefs, 10, (Integer) decimal.getValue());
8.165 - }//GEN-LAST:event_decimalStateChanged
8.166 -
8.167 - private void hexaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_hexaStateChanged
8.168 - AddUnderscores.setSizeForRadix(prefs, 16, (Integer) hexa.getValue());
8.169 - }//GEN-LAST:event_hexaStateChanged
8.170 -
8.171 - private void replaceExistingStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_replaceExistingStateChanged
8.172 - AddUnderscores.setReplaceLiteralsWithUnderscores(prefs, replaceExisting.isSelected());
8.173 - }//GEN-LAST:event_replaceExistingStateChanged
8.174 -
8.175 - // Variables declaration - do not modify//GEN-BEGIN:variables
8.176 - private javax.swing.JSpinner binary;
8.177 - private javax.swing.JSpinner decimal;
8.178 - private javax.swing.JSpinner hexa;
8.179 - private javax.swing.JLabel jLabel1;
8.180 - private javax.swing.JLabel jLabel2;
8.181 - private javax.swing.JLabel jLabel3;
8.182 - private javax.swing.JCheckBox replaceExisting;
8.183 - // End of variables declaration//GEN-END:variables
8.184 -}
9.1 --- a/javahints/src/org/netbeans/modules/javahints/jdk/Bundle.properties Thu Nov 17 08:03:22 2011 +0100
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,48 +0,0 @@
9.4 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9.5 -#
9.6 -# Copyright 2011 Oracle and/or its affiliates. All rights reserved.
9.7 -#
9.8 -# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9.9 -# Other names may be trademarks of their respective owners.
9.10 -#
9.11 -# The contents of this file are subject to the terms of either the GNU
9.12 -# General Public License Version 2 only ("GPL") or the Common
9.13 -# Development and Distribution License("CDDL") (collectively, the
9.14 -# "License"). You may not use this file except in compliance with the
9.15 -# License. You can obtain a copy of the License at
9.16 -# http://www.netbeans.org/cddl-gplv2.html
9.17 -# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
9.18 -# specific language governing permissions and limitations under the
9.19 -# License. When distributing the software, include this License Header
9.20 -# Notice in each file and include the License file at
9.21 -# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
9.22 -# particular file as subject to the "Classpath" exception as provided
9.23 -# by Oracle in the GPL Version 2 section of the License file that
9.24 -# accompanied this code. If applicable, add the following below the
9.25 -# License Header, with the fields enclosed by brackets [] replaced by
9.26 -# your own identifying information:
9.27 -# "Portions Copyrighted [year] [name of copyright owner]"
9.28 -#
9.29 -# If you wish your version of this file to be governed by only the CDDL
9.30 -# or only the GPL Version 2, indicate your decision by adding
9.31 -# "[Contributor] elects to include this software in this distribution
9.32 -# under the [CDDL or GPL Version 2] license." If you do not indicate a
9.33 -# single choice of license, a recipient has the option to distribute
9.34 -# your version of this file under either the CDDL, the GPL Version 2 or
9.35 -# to extend the choice of license to its licensees as provided above.
9.36 -# However, if you add GPL Version 2 code and therefore, elected the GPL
9.37 -# Version 2 license, then the option applies only if the new code is
9.38 -# made subject to such option by the copyright holder.
9.39 -#
9.40 -# Contributor(s):
9.41 -#
9.42 -# Portions Copyrighted 2011 Sun Microsystems, Inc.
9.43 -
9.44 -DN_org.netbeans.modules.javahints.jdk.AddUnderscores=Add Underscores
9.45 -DESC_org.netbeans.modules.javahints.jdk.AddUnderscores=Proposed to add underscores to integer literals to improve their readability
9.46 -ERR_org.netbeans.modules.javahints.jdk.AddUnderscores=Underscores could be used to improve readability
9.47 -FIX_org.netbeans.modules.javahints.jdk.AddUnderscores=Change the literal to: {0}
9.48 -AddUnderscoresPanel.jLabel1.text=&Binary:
9.49 -AddUnderscoresPanel.jLabel3.text=&Hexadecimal:
9.50 -AddUnderscoresPanel.jLabel2.text=&Decimal:
9.51 -AddUnderscoresPanel.replaceExisting.text=&Also transform literals with underscores
10.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/Bundle_test.properties Thu Nov 17 08:03:22 2011 +0100
10.2 +++ b/javahints/test/unit/src/org/netbeans/modules/javahints/Bundle_test.properties Thu Nov 17 12:37:33 2011 +0100
10.3 @@ -21,5 +21,4 @@
10.4 ERR_NULL_TO_NON_NULL_ARG=ERR_NULL_TO_NON_NULL_ARG
10.5 ERR_POSSIBLENULL_TO_NON_NULL_ARG=ERR_POSSIBLENULL_TO_NON_NULL_ARG
10.6 DN_NegateCondition=Negate condition
10.7 -ERR_org.netbeans.modules.javahints.CheckReturnValueHint=ERR_org.netbeans.modules.javahints.CheckReturnValueHint
10.8 FIX_AddReturn=FIX_AddReturn
11.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/CheckReturnValueHintTest.java Thu Nov 17 08:03:22 2011 +0100
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,79 +0,0 @@
11.4 -/*
11.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
11.6 - *
11.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
11.8 - *
11.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
11.10 - * Other names may be trademarks of their respective owners.
11.11 - *
11.12 - * The contents of this file are subject to the terms of either the GNU
11.13 - * General Public License Version 2 only ("GPL") or the Common
11.14 - * Development and Distribution License("CDDL") (collectively, the
11.15 - * "License"). You may not use this file except in compliance with the
11.16 - * License. You can obtain a copy of the License at
11.17 - * http://www.netbeans.org/cddl-gplv2.html
11.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11.19 - * specific language governing permissions and limitations under the
11.20 - * License. When distributing the software, include this License Header
11.21 - * Notice in each file and include the License file at
11.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
11.23 - * particular file as subject to the "Classpath" exception as provided
11.24 - * by Oracle in the GPL Version 2 section of the License file that
11.25 - * accompanied this code. If applicable, add the following below the
11.26 - * License Header, with the fields enclosed by brackets [] replaced by
11.27 - * your own identifying information:
11.28 - * "Portions Copyrighted [year] [name of copyright owner]"
11.29 - *
11.30 - * If you wish your version of this file to be governed by only the CDDL
11.31 - * or only the GPL Version 2, indicate your decision by adding
11.32 - * "[Contributor] elects to include this software in this distribution
11.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
11.34 - * single choice of license, a recipient has the option to distribute
11.35 - * your version of this file under either the CDDL, the GPL Version 2 or
11.36 - * to extend the choice of license to its licensees as provided above.
11.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
11.38 - * Version 2 license, then the option applies only if the new code is
11.39 - * made subject to such option by the copyright holder.
11.40 - *
11.41 - * Contributor(s):
11.42 - *
11.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
11.44 - */
11.45 -package org.netbeans.modules.javahints;
11.46 -
11.47 -import org.netbeans.modules.java.hints.jackpot.code.spi.TestBase;
11.48 -
11.49 -/**
11.50 - *
11.51 - * @author lahvac
11.52 - */
11.53 -public class CheckReturnValueHintTest extends TestBase {
11.54 -
11.55 - public CheckReturnValueHintTest(String name) {
11.56 - super(name, CheckReturnValueHint.class);
11.57 - }
11.58 -
11.59 - public void testSimpleReport() throws Exception {
11.60 - performAnalysisTest("test/Test.java",
11.61 - "package test;\n" +
11.62 - "public class Test {\n" +
11.63 - " public @CheckReturnValue String foo() { return null; }\n" +
11.64 - " public void test() {\n" +
11.65 - " foo();\n" +
11.66 - " }\n" +
11.67 - "}\n" +
11.68 - "public @interface CheckReturnValue {}\n",
11.69 - "4:8-4:14:verifier:ERR_org.netbeans.modules.javahints.CheckReturnValueHint");
11.70 - }
11.71 -
11.72 - public void testStringSubString() throws Exception {
11.73 - performAnalysisTest("test/Test.java",
11.74 - "package test;\n" +
11.75 - "public class Test {\n" +
11.76 - " public void test(String arg) {\n" +
11.77 - " arg.substring(0);\n" +
11.78 - " }\n" +
11.79 - "}\n",
11.80 - "3:8-3:25:verifier:ERR_org.netbeans.modules.javahints.CheckReturnValueHint");
11.81 - }
11.82 -}
12.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/ImageUtilitiesDeprecationTest.java Thu Nov 17 08:03:22 2011 +0100
12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
12.3 @@ -1,158 +0,0 @@
12.4 -/*
12.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
12.6 - *
12.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
12.8 - *
12.9 - * The contents of this file are subject to the terms of either the GNU
12.10 - * General Public License Version 2 only ("GPL") or the Common
12.11 - * Development and Distribution License("CDDL") (collectively, the
12.12 - * "License"). You may not use this file except in compliance with the
12.13 - * License. You can obtain a copy of the License at
12.14 - * http://www.netbeans.org/cddl-gplv2.html
12.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12.16 - * specific language governing permissions and limitations under the
12.17 - * License. When distributing the software, include this License Header
12.18 - * Notice in each file and include the License file at
12.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
12.20 - * particular file as subject to the "Classpath" exception as provided
12.21 - * by Sun in the GPL Version 2 section of the License file that
12.22 - * accompanied this code. If applicable, add the following below the
12.23 - * License Header, with the fields enclosed by brackets [] replaced by
12.24 - * your own identifying information:
12.25 - * "Portions Copyrighted [year] [name of copyright owner]"
12.26 - *
12.27 - * If you wish your version of this file to be governed by only the CDDL
12.28 - * or only the GPL Version 2, indicate your decision by adding
12.29 - * "[Contributor] elects to include this software in this distribution
12.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
12.31 - * single choice of license, a recipient has the option to distribute
12.32 - * your version of this file under either the CDDL, the GPL Version 2 or
12.33 - * to extend the choice of license to its licensees as provided above.
12.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
12.35 - * Version 2 license, then the option applies only if the new code is
12.36 - * made subject to such option by the copyright holder.
12.37 - *
12.38 - * Contributor(s):
12.39 - *
12.40 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
12.41 - */
12.42 -
12.43 -package org.netbeans.modules.javahints;
12.44 -
12.45 -import com.sun.source.tree.Tree.Kind;
12.46 -import com.sun.source.util.TreePath;
12.47 -import java.util.List;
12.48 -import junit.framework.Test;
12.49 -import org.netbeans.api.java.source.CompilationInfo;
12.50 -import org.netbeans.modules.java.hints.infrastructure.TreeRuleTestBase;
12.51 -import org.netbeans.spi.editor.hints.ErrorDescription;
12.52 -import org.netbeans.spi.editor.hints.Fix;
12.53 -import org.openide.filesystems.FileObject;
12.54 -import org.openide.filesystems.FileUtil;
12.55 -import org.openide.filesystems.URLMapper;
12.56 -import org.openide.util.NbBundle;
12.57 -import org.openide.util.Utilities;
12.58 -
12.59 -/**
12.60 - *
12.61 - * @author Jaroslav Tulach
12.62 - */
12.63 -public class ImageUtilitiesDeprecationTest extends TreeRuleTestBase {
12.64 -
12.65 - public ImageUtilitiesDeprecationTest(String testName) {
12.66 - super(testName);
12.67 - }
12.68 -
12.69 - public void testLoadImage() throws Exception {
12.70 - performFixTest("test/Test.java",
12.71 - "package test;\n" +
12.72 - "import org.openide.util.Utilities;\n" +
12.73 - "public class Test {\n" +
12.74 - " private void test(Object o) {\n" +
12.75 - " Utilities.lo|adImage(\"Ahoj\");\n" +
12.76 - " }\n" +
12.77 - "}\n",
12.78 - "4:18-4:27:verifier:Use of Utilities.loadImage",
12.79 - "FixImpl",
12.80 - "package test; import org.openide.util.ImageUtilities; import org.openide.util.Utilities; public class Test { private void test(Object o) { ImageUtilities.loadImage(\"Ahoj\"); } } ");
12.81 - }
12.82 -
12.83 - public void testLoadImageLocalized() throws Exception {
12.84 - performFixTest("test/Test.java",
12.85 - "package test;\n" +
12.86 - "import org.openide.util.Utilities;\n" +
12.87 - "public class Test {\n" +
12.88 - " private void test(Object o) {\n" +
12.89 - " Utilities.lo|adImage(\"Ahoj\", true);\n" +
12.90 - " }\n" +
12.91 - "}\n",
12.92 - "4:18-4:27:verifier:Use of Utilities.loadImage",
12.93 - "FixImpl",
12.94 - "package test; import org.openide.util.ImageUtilities; import org.openide.util.Utilities; public class Test { private void test(Object o) { ImageUtilities.loadImage(\"Ahoj\", true); } } ");
12.95 - }
12.96 -
12.97 - public void testIcon2Image() throws Exception {
12.98 - performFixTest("test/Test.java",
12.99 - "package test;\n" +
12.100 - "import org.openide.util.Utilities;\n" +
12.101 - "public class Test {\n" +
12.102 - " private void test(Object o) {\n" +
12.103 - " Utilities.icon2|Image(null);\n" +
12.104 - " }\n" +
12.105 - "}\n",
12.106 - "4:18-4:28:verifier:Use of Utilities.icon2Image",
12.107 - "FixImpl",
12.108 - "package test; import org.openide.util.ImageUtilities; import org.openide.util.Utilities; public class Test { private void test(Object o) { ImageUtilities.icon2Image(null); } } ");
12.109 - }
12.110 -
12.111 - public void testMergeImages() throws Exception {
12.112 - performFixTest("test/Test.java",
12.113 - "package test;\n" +
12.114 - "import org.openide.util.Utilities;\n" +
12.115 - "public class Test {\n" +
12.116 - " private void test(Object o) {\n" +
12.117 - " Utilities.merge|Images(null, null);\n" +
12.118 - " }\n" +
12.119 - "}\n",
12.120 - "4:18-4:29:verifier:Use of Utilities.mergeImages",
12.121 - "FixImpl",
12.122 - "package test; import org.openide.util.ImageUtilities; import org.openide.util.Utilities; public class Test { private void test(Object o) { ImageUtilities.mergeImages(null, null); } } ");
12.123 - }
12.124 -
12.125 - @Override
12.126 - protected List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path) {
12.127 - throw new UnsupportedOperationException();
12.128 - }
12.129 -
12.130 - @Override
12.131 - protected String toDebugString(CompilationInfo info, Fix f) {
12.132 - return "FixImpl";
12.133 - }
12.134 -
12.135 - @Override
12.136 - protected List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path, int offset) {
12.137 - ImageUtilitiesDeprecation c = new ImageUtilitiesDeprecation();
12.138 - while (path != null && path.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
12.139 - path = path.getParentPath();
12.140 - }
12.141 -
12.142 - if (path == null) {
12.143 - return null;
12.144 - }
12.145 - return c.run(info, path, offset);
12.146 - }
12.147 -
12.148 - @Override
12.149 - protected FileObject[] extraClassPath() {
12.150 - FileObject api = URLMapper.findFileObject(Utilities.class.getProtectionDomain().getCodeSource().getLocation());
12.151 -
12.152 - assertNotNull(api);
12.153 -
12.154 - return new FileObject[] {FileUtil.getArchiveRoot(api)};
12.155 - }
12.156 -
12.157 - static {
12.158 - NbBundle.setBranding("test");
12.159 - }
12.160 -
12.161 -}
13.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/NoDOGetCookieTest.java Thu Nov 17 08:03:22 2011 +0100
13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3 @@ -1,126 +0,0 @@
13.4 -/*
13.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
13.6 - *
13.7 - * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
13.8 - *
13.9 - * The contents of this file are subject to the terms of either the GNU
13.10 - * General Public License Version 2 only ("GPL") or the Common
13.11 - * Development and Distribution License("CDDL") (collectively, the
13.12 - * "License"). You may not use this file except in compliance with the
13.13 - * License. You can obtain a copy of the License at
13.14 - * http://www.netbeans.org/cddl-gplv2.html
13.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13.16 - * specific language governing permissions and limitations under the
13.17 - * License. When distributing the software, include this License Header
13.18 - * Notice in each file and include the License file at
13.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
13.20 - * particular file as subject to the "Classpath" exception as provided
13.21 - * by Sun in the GPL Version 2 section of the License file that
13.22 - * accompanied this code. If applicable, add the following below the
13.23 - * License Header, with the fields enclosed by brackets [] replaced by
13.24 - * your own identifying information:
13.25 - * "Portions Copyrighted [year] [name of copyright owner]"
13.26 - *
13.27 - * If you wish your version of this file to be governed by only the CDDL
13.28 - * or only the GPL Version 2, indicate your decision by adding
13.29 - * "[Contributor] elects to include this software in this distribution
13.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
13.31 - * single choice of license, a recipient has the option to distribute
13.32 - * your version of this file under either the CDDL, the GPL Version 2 or
13.33 - * to extend the choice of license to its licensees as provided above.
13.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
13.35 - * Version 2 license, then the option applies only if the new code is
13.36 - * made subject to such option by the copyright holder.
13.37 - *
13.38 - * Contributor(s):
13.39 - *
13.40 - * Portions Copyrighted 2008 Sun Microsystems, Inc.
13.41 - */
13.42 -
13.43 -package org.netbeans.modules.javahints;
13.44 -
13.45 -import com.sun.source.tree.Tree.Kind;
13.46 -import com.sun.source.util.TreePath;
13.47 -import java.util.LinkedList;
13.48 -import java.util.List;
13.49 -import org.netbeans.api.java.source.CompilationInfo;
13.50 -import org.netbeans.modules.java.hints.infrastructure.TreeRuleTestBase;
13.51 -import org.netbeans.spi.editor.hints.ErrorDescription;
13.52 -import org.netbeans.spi.editor.hints.Fix;
13.53 -import org.openide.cookies.EditorCookie;
13.54 -import org.openide.filesystems.FileObject;
13.55 -import org.openide.filesystems.FileUtil;
13.56 -import org.openide.filesystems.URLMapper;
13.57 -import org.openide.loaders.DataObject;
13.58 -import org.openide.nodes.Node;
13.59 -import org.openide.util.NbBundle;
13.60 -import org.openide.util.Utilities;
13.61 -
13.62 -/**
13.63 - *
13.64 - * @author Jan Lahoda
13.65 - */
13.66 -public class NoDOGetCookieTest extends TreeRuleTestBase {
13.67 -
13.68 - public NoDOGetCookieTest(String testName) {
13.69 - super(testName);
13.70 - }
13.71 -
13.72 - public void testGetCookie() throws Exception {
13.73 - performFixTest("test/Test.java",
13.74 - "package test;\n" +
13.75 - "import org.openide.loaders.DataObject;\n" +
13.76 - "import org.openide.cookies.EditorCookie;\n" +
13.77 - "public class Test {\n" +
13.78 - " private void test(DataObject o) {\n" +
13.79 - " o.get|Cookie(EditorCookie.class);\n" +
13.80 - " }\n" +
13.81 - "}\n",
13.82 - "5:8-5:39:verifier:Use of DO.getCookie",
13.83 - "FixImpl",
13.84 - "package test; import org.openide.loaders.DataObject; import org.openide.cookies.EditorCookie; public class Test { private void test(DataObject o) { o.getLookup().lookup(EditorCookie.class); } } ");
13.85 - }
13.86 -
13.87 - @Override
13.88 - protected List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path) {
13.89 - throw new UnsupportedOperationException();
13.90 - }
13.91 -
13.92 - @Override
13.93 - protected String toDebugString(CompilationInfo info, Fix f) {
13.94 - return "FixImpl";
13.95 - }
13.96 -
13.97 - @Override
13.98 - protected List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path, int offset) {
13.99 - NoDOGetCookie c = new NoDOGetCookie();
13.100 - while (path != null && path.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
13.101 - path = path.getParentPath();
13.102 - }
13.103 -
13.104 - if (path == null) {
13.105 - return null;
13.106 - }
13.107 - return c.run(info, path);
13.108 - }
13.109 -
13.110 - @Override
13.111 - protected FileObject[] extraClassPath() {
13.112 - List<FileObject> result = new LinkedList<FileObject>();
13.113 -
13.114 - for (Class c : new Class[] { Utilities.class, FileObject.class, Node.class, DataObject.class, EditorCookie.class}) {
13.115 - FileObject api = URLMapper.findFileObject(c.getProtectionDomain().getCodeSource().getLocation());
13.116 -
13.117 - assertNotNull(api);
13.118 -
13.119 - result.add(FileUtil.getArchiveRoot(api));
13.120 - }
13.121 -
13.122 - return result.toArray(new FileObject[0]);
13.123 - }
13.124 -
13.125 - static {
13.126 - NbBundle.setBranding("test");
13.127 - }
13.128 -
13.129 -}
14.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/jdk/AddUnderscoresTest.java Thu Nov 17 08:03:22 2011 +0100
14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
14.3 @@ -1,161 +0,0 @@
14.4 -/*
14.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
14.6 - *
14.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
14.8 - *
14.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
14.10 - * Other names may be trademarks of their respective owners.
14.11 - *
14.12 - * The contents of this file are subject to the terms of either the GNU
14.13 - * General Public License Version 2 only ("GPL") or the Common
14.14 - * Development and Distribution License("CDDL") (collectively, the
14.15 - * "License"). You may not use this file except in compliance with the
14.16 - * License. You can obtain a copy of the License at
14.17 - * http://www.netbeans.org/cddl-gplv2.html
14.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
14.19 - * specific language governing permissions and limitations under the
14.20 - * License. When distributing the software, include this License Header
14.21 - * Notice in each file and include the License file at
14.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
14.23 - * particular file as subject to the "Classpath" exception as provided
14.24 - * by Oracle in the GPL Version 2 section of the License file that
14.25 - * accompanied this code. If applicable, add the following below the
14.26 - * License Header, with the fields enclosed by brackets [] replaced by
14.27 - * your own identifying information:
14.28 - * "Portions Copyrighted [year] [name of copyright owner]"
14.29 - *
14.30 - * If you wish your version of this file to be governed by only the CDDL
14.31 - * or only the GPL Version 2, indicate your decision by adding
14.32 - * "[Contributor] elects to include this software in this distribution
14.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
14.34 - * single choice of license, a recipient has the option to distribute
14.35 - * your version of this file under either the CDDL, the GPL Version 2 or
14.36 - * to extend the choice of license to its licensees as provided above.
14.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
14.38 - * Version 2 license, then the option applies only if the new code is
14.39 - * made subject to such option by the copyright holder.
14.40 - *
14.41 - * Contributor(s):
14.42 - *
14.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
14.44 - */
14.45 -package org.netbeans.modules.javahints.jdk;
14.46 -
14.47 -import org.netbeans.modules.javahints.jdk.AddUnderscores;
14.48 -import java.util.Collections;
14.49 -import java.util.prefs.Preferences;
14.50 -import org.netbeans.junit.internal.MemoryPreferencesFactory;
14.51 -import org.netbeans.modules.java.hints.analyzer.OverridePreferences;
14.52 -import org.netbeans.modules.java.hints.jackpot.code.spi.TestBase;
14.53 -import org.netbeans.modules.java.hints.jackpot.impl.RulesManager;
14.54 -import org.netbeans.modules.java.hints.options.HintsSettings;
14.55 -
14.56 -/**
14.57 - *
14.58 - * @author lahvac
14.59 - */
14.60 -public class AddUnderscoresTest extends TestBase {
14.61 - public AddUnderscoresTest(String name) {
14.62 - super(name, AddUnderscores.class);
14.63 - }
14.64 -
14.65 - public void testSimpleAdd() throws Exception {
14.66 - performFixTest("test/Test.java",
14.67 - "package test;\n" +
14.68 - "public class Test {\n" +
14.69 - " private static final int CONST = 12345678;\n" +
14.70 - "}\n",
14.71 - "2:37-2:45:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
14.72 - "FixImpl",
14.73 - ("package test;\n" +
14.74 - "public class Test {\n" +
14.75 - " private static final int CONST = 12_345_678;\n" +
14.76 - "}\n").replaceAll("[ \t\n]+", " "));
14.77 - }
14.78 -
14.79 - public void testSettings() throws Exception {
14.80 - AddUnderscores.setSizeForRadix(prefs, 2, 5);
14.81 - performFixTest("test/Test.java",
14.82 - "package test;\n" +
14.83 - "public class Test {\n" +
14.84 - " private static final int CONST = 0B1010101010101010;\n" +
14.85 - "}\n",
14.86 - "2:37-2:55:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
14.87 - "FixImpl",
14.88 - ("package test;\n" +
14.89 - "public class Test {\n" +
14.90 - " private static final int CONST = 0B1_01010_10101_01010;\n" +
14.91 - "}\n").replaceAll("[ \t\n]+", " "));
14.92 - }
14.93 -
14.94 - public void testHexLong() throws Exception {
14.95 - AddUnderscores.setSizeForRadix(prefs, 16, 3);
14.96 - performFixTest("test/Test.java",
14.97 - "package test;\n" +
14.98 - "public class Test {\n" +
14.99 - " private static final int CONST = 0xA5A5A5A5A5A5A5A5L;\n" +
14.100 - "}\n",
14.101 - "2:37-2:56:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
14.102 - "FixImpl",
14.103 - ("package test;\n" +
14.104 - "public class Test {\n" +
14.105 - " private static final int CONST = 0xA_5A5_A5A_5A5_A5A_5A5L;\n" +
14.106 - "}\n").replaceAll("[ \t\n]+", " "));
14.107 - }
14.108 -
14.109 - public void testAlreadyHasUnderscores1() throws Exception {
14.110 - performAnalysisTest("test/Test.java",
14.111 - "package test;\n" +
14.112 - "public class Test {\n" +
14.113 - " private static final int CONST = 0xA5A5A5A5_A5A5A5A5L;\n" +
14.114 - "}\n");
14.115 - }
14.116 -
14.117 - public void testAlreadyHasUnderscores2() throws Exception {
14.118 - AddUnderscores.setReplaceLiteralsWithUnderscores(prefs, true);
14.119 - performFixTest("test/Test.java",
14.120 - "package test;\n" +
14.121 - "public class Test {\n" +
14.122 - " private static final int CONST = 0xA5A5A5A5A5A5A5A_5L;\n" +
14.123 - "}\n",
14.124 - "2:37-2:57:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
14.125 - "FixImpl",
14.126 - ("package test;\n" +
14.127 - "public class Test {\n" +
14.128 - " private static final int CONST = 0xA5A5_A5A5_A5A5_A5A5L;\n" +
14.129 - "}\n").replaceAll("[ \t\n]+", " "));
14.130 - }
14.131 -
14.132 - public void testZeroIsNotOctal() throws Exception {
14.133 - assertEquals(10, AddUnderscores.radixInfo("0").radix);
14.134 - assertEquals(10, AddUnderscores.radixInfo("0L").radix);
14.135 - }
14.136 -
14.137 - public void testIgnoreOctalConstantsForNow() throws Exception {
14.138 - performAnalysisTest("test/Test.java",
14.139 - "package test;\n" +
14.140 - "public class Test {\n" +
14.141 - " private static final int CONST = 0123;\n" +
14.142 - "}\n");
14.143 - }
14.144 -
14.145 - private Preferences prefs;
14.146 -
14.147 - @Override
14.148 - protected void setUp() throws Exception {
14.149 - super.setUp();
14.150 -
14.151 - prefs = new OverridePreferences(RulesManager.getPreferences(AddUnderscores.ID, HintsSettings.getCurrentProfileId()));
14.152 - HintsSettings.setPreferencesOverride(Collections.singletonMap(AddUnderscores.ID, prefs));
14.153 -
14.154 - setSourceLevel("1.7");
14.155 - }
14.156 -
14.157 - @Override
14.158 - protected void tearDown() throws Exception {
14.159 - HintsSettings.setPreferencesOverride(Collections.<String, Preferences>emptyMap());
14.160 - prefs = null;
14.161 - super.tearDown();
14.162 - }
14.163 -
14.164 -}
15.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/jdk/Bundle_test.properties Thu Nov 17 08:03:22 2011 +0100
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,44 +0,0 @@
15.4 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
15.5 -#
15.6 -# Copyright 2011 Oracle and/or its affiliates. All rights reserved.
15.7 -#
15.8 -# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
15.9 -# Other names may be trademarks of their respective owners.
15.10 -#
15.11 -# The contents of this file are subject to the terms of either the GNU
15.12 -# General Public License Version 2 only ("GPL") or the Common
15.13 -# Development and Distribution License("CDDL") (collectively, the
15.14 -# "License"). You may not use this file except in compliance with the
15.15 -# License. You can obtain a copy of the License at
15.16 -# http://www.netbeans.org/cddl-gplv2.html
15.17 -# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15.18 -# specific language governing permissions and limitations under the
15.19 -# License. When distributing the software, include this License Header
15.20 -# Notice in each file and include the License file at
15.21 -# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
15.22 -# particular file as subject to the "Classpath" exception as provided
15.23 -# by Oracle in the GPL Version 2 section of the License file that
15.24 -# accompanied this code. If applicable, add the following below the
15.25 -# License Header, with the fields enclosed by brackets [] replaced by
15.26 -# your own identifying information:
15.27 -# "Portions Copyrighted [year] [name of copyright owner]"
15.28 -#
15.29 -# If you wish your version of this file to be governed by only the CDDL
15.30 -# or only the GPL Version 2, indicate your decision by adding
15.31 -# "[Contributor] elects to include this software in this distribution
15.32 -# under the [CDDL or GPL Version 2] license." If you do not indicate a
15.33 -# single choice of license, a recipient has the option to distribute
15.34 -# your version of this file under either the CDDL, the GPL Version 2 or
15.35 -# to extend the choice of license to its licensees as provided above.
15.36 -# However, if you add GPL Version 2 code and therefore, elected the GPL
15.37 -# Version 2 license, then the option applies only if the new code is
15.38 -# made subject to such option by the copyright holder.
15.39 -#
15.40 -# Contributor(s):
15.41 -#
15.42 -# Portions Copyrighted 2011 Sun Microsystems, Inc.
15.43 -
15.44 -DN_org.netbeans.modules.javahints.jdk.AddUnderscores=DN_org.netbeans.modules.javahints.jdk.AddUnderscores
15.45 -DESC_org.netbeans.modules.javahints.jdk.AddUnderscores=DESC_org.netbeans.modules.javahints.jdk.AddUnderscores
15.46 -ERR_org.netbeans.modules.javahints.jdk.AddUnderscores=ERR_org.netbeans.modules.javahints.jdk.AddUnderscores
15.47 -FIX_org.netbeans.modules.javahints.jdk.AddUnderscores=FIX_org.netbeans.modules.javahints.jdk.AddUnderscores{0}