Skip to content

Commit

Permalink
Merge branch 'modifiers_hints' of https://github.com/rasa-silva/nb-ad…
Browse files Browse the repository at this point in the history
…ditional-hints into rasa-silva-modifiers_hints
  • Loading branch information
markiewb committed Nov 25, 2013
2 parents 8f3715e + 539baf0 commit 6b58401
Show file tree
Hide file tree
Showing 10 changed files with 980 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<netbeans.version>RELEASE721</netbeans.version>
<netbeans.run.params.ide />
<netbeans.run.params>${netbeans.run.params.ide}</netbeans.run.params>
</properties>
<organization>
<name>Benno Markiewicz ([email protected])</name>
</organization>
<url>https://github.com/markiewb/nb-additional-hints</url>

<repositories>
<!--
Repository hosting NetBeans modules, especially APIs.
Expand Down Expand Up @@ -120,7 +118,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<version>3.11</version>
<version>3.11.1</version>
<extensions>true</extensions>
<configuration>
<!-- keep this id, else the update from existing versions will fail
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Contributor(s):
*
* The Original Software is NetBeans. The Initial Developer of the Original
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
* Microsystems, Inc. All Rights Reserved.
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* "Portions Copyrighted 2013 Benno Markiewicz"
*/
package de.markiewb.netbeans.plugins.hints.modifiers;

import com.sun.source.tree.ModifiersTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import java.util.EnumSet;
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.Fix;
import org.netbeans.spi.editor.hints.Severity;
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
import org.netbeans.spi.java.hints.Hint;
import org.netbeans.spi.java.hints.HintContext;
import org.netbeans.spi.java.hints.TriggerTreeKind;
import org.netbeans.spi.java.hints.support.FixFactory;
import org.openide.util.NbBundle;

/**
* Turns a class, method of field public.
*/
@NbBundle.Messages({
"ERR_MakePackageProtected=Make Package Protected",
"DN_MakePackageProtected=Make Package Protected",
"DESC_MakePackageProtected=Makes a class, method or field package protected."})
public class MakePackageProtected {

private static final EnumSet<Modifier> opositeModifiers = EnumSet.of(Modifier.PRIVATE, Modifier.PUBLIC, Modifier.PROTECTED);

@Hint(displayName = "#DN_MakePackageProtected", description = "#DESC_MakePackageProtected", category = "suggestions",
hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@TriggerTreeKind({Tree.Kind.CLASS, Tree.Kind.METHOD, Tree.Kind.VARIABLE})
public static ErrorDescription convert(HintContext ctx) {

TreePath path = ctx.getPath();
Element element = ctx.getInfo().getTrees().getElement(path);

if (element == null) {
return null;
}

ModifiersTree modifiers = ModifierUtils.getModifiersTree(path, element);

if (modifiers == null || (!modifiers.getFlags().contains(Modifier.PROTECTED)
&& !modifiers.getFlags().contains(Modifier.PRIVATE)
&& !modifiers.getFlags().contains(Modifier.PUBLIC))) {
return null;
}

Fix fix = FixFactory.changeModifiersFix(ctx.getInfo(), new TreePath(path, modifiers), EnumSet.of(Modifier.PROTECTED), opositeModifiers, Bundle.ERR_MakePackageProtected());
return ErrorDescriptionFactory.forName(ctx, path, Bundle.ERR_MakePackageProtected(), fix);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Contributor(s):
*
* The Original Software is NetBeans. The Initial Developer of the Original
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
* Microsystems, Inc. All Rights Reserved.
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* "Portions Copyrighted 2013 Benno Markiewicz"
*/
package de.markiewb.netbeans.plugins.hints.modifiers;

import com.sun.source.tree.ModifiersTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import java.util.EnumSet;
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.Fix;
import org.netbeans.spi.editor.hints.Severity;
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
import org.netbeans.spi.java.hints.Hint;
import org.netbeans.spi.java.hints.HintContext;
import org.netbeans.spi.java.hints.TriggerTreeKind;
import org.netbeans.spi.java.hints.support.FixFactory;
import org.openide.util.NbBundle;

@NbBundle.Messages({
"ERR_MakePrivate=Make Private",
"DN_MakePrivate=Make Private",
"DESC_MakePrivate=Makes a class, method or field private."})
public class MakePrivate {

private static final EnumSet<Modifier> opositeModifiers = EnumSet.of(Modifier.PUBLIC, Modifier.PROTECTED);

@Hint(displayName = "#DN_MakePrivate", description = "#DESC_MakePrivate", category = "suggestions",
hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@TriggerTreeKind({Tree.Kind.CLASS, Tree.Kind.METHOD, Tree.Kind.VARIABLE})
public static ErrorDescription convert(HintContext ctx) {

TreePath path = ctx.getPath();
Element element = ctx.getInfo().getTrees().getElement(path);

if (element == null) {
return null;
}

if (ModifierUtils.isTopLevelClass(element)) {
return null;
}

ModifiersTree modifiers = ModifierUtils.getModifiersTree(path, element);

if (modifiers == null || modifiers.getFlags().contains(Modifier.PRIVATE)) {
return null;
}

Fix fix = FixFactory.changeModifiersFix(ctx.getInfo(), new TreePath(path, modifiers), EnumSet.of(Modifier.PRIVATE), opositeModifiers, Bundle.ERR_MakePrivate());
return ErrorDescriptionFactory.forName(ctx, path, Bundle.ERR_MakePrivate(), fix);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Contributor(s):
*
* The Original Software is NetBeans. The Initial Developer of the Original
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
* Microsystems, Inc. All Rights Reserved.
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* "Portions Copyrighted 2013 Benno Markiewicz"
*/
package de.markiewb.netbeans.plugins.hints.modifiers;

import com.sun.source.tree.ModifiersTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import java.util.EnumSet;
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.Fix;
import org.netbeans.spi.editor.hints.Severity;
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
import org.netbeans.spi.java.hints.Hint;
import org.netbeans.spi.java.hints.HintContext;
import org.netbeans.spi.java.hints.TriggerTreeKind;
import org.netbeans.spi.java.hints.support.FixFactory;
import org.openide.util.NbBundle;

/**
* Turns a class, method of field public.
*/
@NbBundle.Messages({
"ERR_MakeProtected=Make Protected",
"DN_MakeProtected=Make Protected",
"DESC_MakeProtected=Makes a class, method or field protected."})
public class MakeProtected {

private static final EnumSet<Modifier> opositeModifiers = EnumSet.of(Modifier.PRIVATE, Modifier.PUBLIC);

@Hint(displayName = "#DN_MakeProtected", description = "#DESC_MakeProtected", category = "suggestions",
hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@TriggerTreeKind({Tree.Kind.CLASS, Tree.Kind.METHOD, Tree.Kind.VARIABLE})
public static ErrorDescription convert(HintContext ctx) {

TreePath path = ctx.getPath();
Element element = ctx.getInfo().getTrees().getElement(path);

if (element == null) {
return null;
}

if (ModifierUtils.isTopLevelClass(element)) {
return null;
}

ModifiersTree modifiers = ModifierUtils.getModifiersTree(path, element);

if (modifiers == null || modifiers.getFlags().contains(Modifier.PROTECTED)) {
return null;
}

Fix fix = FixFactory.changeModifiersFix(ctx.getInfo(), new TreePath(path, modifiers), EnumSet.of(Modifier.PROTECTED), opositeModifiers, Bundle.ERR_MakeProtected());
return ErrorDescriptionFactory.forName(ctx, path, Bundle.ERR_MakeProtected(), fix);
}
}
Loading

0 comments on commit 6b58401

Please sign in to comment.