Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced all [equals() -> "==", HashSet -> EnumSet, HashMap -> EnumMap] calls for enum types #5309

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public List<Fix> run(final CompilationInfo info, String diagnosticKey,
NewArrayTree arrayTree = (NewArrayTree) initializer;
Tree type = arrayTree.getType();
if (type != null) {
if (type.getKind().equals(Kind.IDENTIFIER)) {
if (type.getKind() == Kind.IDENTIFIER) {
itName = ((IdentifierTree) type).getName();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private Image computeIcon(boolean opened, int type) {
if (icon == null) {
Image image = opened ? super.getOpenedIcon(type) : super.getIcon(type);

if (Type.LIBRARY.equals(visualType)) {
if (Type.LIBRARY == visualType) {
return ImageUtilities.mergeImages(image, LIBRARIES_BADGE, 7, 7);
} else {
return image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public ClassTree ensureNoArgConstructor(ClassTree classTree) throws IOException
ModifiersTree oldModifiersTree = constructorTree.getModifiers();
Set<Modifier> newModifiers = EnumSet.of(Modifier.PUBLIC);
for (Modifier modifier : oldModifiersTree.getFlags()) {
if (!Modifier.PROTECTED.equals(modifier) && !Modifier.PRIVATE.equals(modifier)) {
if (Modifier.PROTECTED != modifier && Modifier.PRIVATE != modifier) {
newModifiers.add(modifier);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ public static ResultProcess startServer(GlassFishServer server,
// Add debug parameters read from domain.xml.
// It's important to add them before java options specified by user
// in case user specified it by himslef.
if (mode.equals(StartMode.DEBUG)) {
if (mode == StartMode.DEBUG) {
String debugOpts = propMap.get("debug-options");
String[] debugOptsSplited = debugOpts.split("\\s+(?=-)");
optList.addAll(Arrays.asList(debugOptsSplited));
}
// add profile parameters
if (mode.equals(StartMode.PROFILE)) {
if (mode == StartMode.PROFILE) {
}
// appending IDE specified options after the ones got from domain.xml
// IDE specified are takind precedence this way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.EnumSet;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
Expand All @@ -53,10 +54,10 @@
public final class CmFieldGenerator extends AbstractMethodGenerator {

// available for tests
static final Set<Modifier> PUBLIC_ABSTRACT = new HashSet<Modifier>(Arrays.asList(new Modifier[] {
static final Set<Modifier> PUBLIC_ABSTRACT = EnumSet.of(
Modifier.PUBLIC,
Modifier.ABSTRACT
}));
);

private CmFieldGenerator(String ejbClass, FileObject ejbClassFileObject) {
super(ejbClass, ejbClassFileObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.EnumSet;
import javax.lang.model.element.Modifier;
import org.netbeans.modules.j2ee.core.api.support.java.method.MethodModel;
import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
Expand Down Expand Up @@ -64,9 +65,7 @@ public void generate(MethodModel methodModel, boolean generateLocal, boolean gen
if (!methodModel.getExceptions().contains("javax.ejb.FinderException")) {
exceptions.add("javax.ejb.FinderException");
}
Set<Modifier> modifiers = new HashSet<Modifier>(2);
modifiers.add(Modifier.PUBLIC);
modifiers.add(Modifier.ABSTRACT);
Set<Modifier> modifiers = EnumSet.of(Modifier.PUBLIC, Modifier.ABSTRACT);
MethodModel methodModelCopy = MethodModel.create(
methodModel.getName(),
methodModel.getReturnType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.EnumSet;
import javax.lang.model.element.Modifier;
import org.netbeans.modules.j2ee.dd.api.ejb.CmpField;
import org.netbeans.modules.j2ee.dd.api.ejb.CmrField;
Expand Down Expand Up @@ -59,7 +60,7 @@ public final class EntityMethodController extends AbstractMethodController {

private final MetadataModel<EjbJarMetadata> metadataModel;
private final String ejbClass;
private final Set<Modifier> modifiersPublicAbstract = new HashSet<Modifier>(2);
private final Set<Modifier> modifiersPublicAbstract = EnumSet.noneOf(Modifier.class);

private final String abstractSchemaName;
private final String persistenceType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.netbeans.modules.j2ee.ejbcore.util._RetoucheUtil;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -65,9 +66,7 @@ public AddSelectMethodStrategy(String name) {

@Override
public MethodModel getPrototypeMethod() {
Set<Modifier> modifiers = new HashSet<Modifier>();
modifiers.add(Modifier.PUBLIC);
modifiers.add(Modifier.ABSTRACT);
Set<Modifier> modifiers = EnumSet.of(Modifier.PUBLIC, Modifier.ABSTRACT);
return MethodModel.create(
"ejbSelectBy",
"int",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ protected void removeNotify() {

@Override
protected Node[] createNodes(Key key) {
if (Key.LOCAL.equals(key)) {
if (Key.LOCAL == key) {
MethodChildren children = new MethodChildren(this, cpInfo, ejbModule, controller, MethodsNode.ViewType.LOCAL);
MethodsNode n = new MethodsNode(ejbClass, ejbModule, children, MethodsNode.ViewType.LOCAL);
n.setIconBaseWithExtension("org/netbeans/modules/j2ee/ejbcore/resources/LocalMethodContainerIcon.gif");
n.setDisplayName(NbBundle.getMessage(EjbViewController.class, "LBL_LocalMethods"));
return new Node[] { n };
}
if (Key.REMOTE.equals(key)) {
if (Key.REMOTE == key) {
MethodChildren children = new MethodChildren(this, cpInfo, ejbModule, controller, MethodsNode.ViewType.REMOTE);
MethodsNode n = new MethodsNode(ejbClass, ejbModule, children, MethodsNode.ViewType.REMOTE);
n.setIconBaseWithExtension("org/netbeans/modules/j2ee/ejbcore/resources/RemoteMethodContainerIcon.gif");
n.setDisplayName(NbBundle.getMessage(EjbViewController.class, "LBL_RemoteMethods"));
return new Node[] { n };
}
if (Key.BEAN.equals(key)) {
if (Key.BEAN == key) {
MethodChildren children = new MethodChildren(this, cpInfo, ejbModule, controller, MethodsNode.ViewType.NO_INTERFACE);
MethodsNode n = new MethodsNode(ejbClass, ejbModule, children, MethodsNode.ViewType.NO_INTERFACE);
n.setIconBaseWithExtension("org/netbeans/modules/j2ee/ejbcore/resources/MethodContainerIcon.gif");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ public void run(WorkingCopy workingCopy) throws IOException {
}

// modifiers
Set<Modifier> modifiers = new HashSet<>();
modifiers.add(Modifier.PRIVATE);
Set<Modifier> modifiers = EnumSet.of(Modifier.PRIVATE);

if (isStatic) {
modifiers.add(Modifier.STATIC);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.ModifiersTree;
import java.io.IOException;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
Expand Down Expand Up @@ -71,8 +72,8 @@ public void run(WorkingCopy workingCopy) throws Exception {
ClassTree clazzTree = workingCopy.getTrees().getTree(clazz);
TreeMaker make = workingCopy.getTreeMaker();

Set<Modifier> flags = new HashSet<>(clazzTree.getModifiers().getFlags());
flags.add(Modifier.PUBLIC);
Set<Modifier> flags = EnumSet.of(Modifier.PUBLIC);
flags.addAll(clazzTree.getModifiers().getFlags());
ModifiersTree newModifiers = make.Modifiers(flags, clazzTree.getModifiers().getAnnotations());
workingCopy.rewrite(clazzTree.getModifiers(), newModifiers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.ModifiersTree;
import java.io.IOException;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
Expand Down Expand Up @@ -70,7 +71,8 @@ public void run(WorkingCopy workingCopy) throws Exception {
ClassTree clazzTree = workingCopy.getTrees().getTree(clazz);
TreeMaker make = workingCopy.getTreeMaker();

Set<Modifier> flags = new HashSet<>(clazzTree.getModifiers().getFlags());
Set<Modifier> flags = EnumSet.noneOf(Modifier.class);
flags.addAll(clazzTree.getModifiers().getFlags());
flags.remove(modifier);
ModifiersTree newModifiers = make.Modifiers(flags, clazzTree.getModifiers().getAnnotations());
workingCopy.rewrite(clazzTree.getModifiers(), newModifiers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ protected static Configuration addServerTests(Server server, Configuration conf,
LOG.info("adding server tests");
return addTest(conf, clazz, testNames);
} else {
if (server.equals(GLASSFISH) || server.equals(ANY)) {
if (server == GLASSFISH || server == ANY) {
registerGlassFish();
if (isRegistered(GLASSFISH)) {
return addTest(conf, clazz, testNames);
}
}
if (server.equals(TOMCAT) || server.equals(ANY)) {
if (server == TOMCAT || server == ANY) {
registerTomcat();
if (isRegistered(TOMCAT)) {
return addTest(conf, clazz, testNames);
}
}
if (server.equals(JBOSS) || server.equals(ANY)) {
if (server == JBOSS || server == ANY) {
registerJBoss();
if (isRegistered(JBOSS)) {
return addTest(conf, clazz, testNames);
Expand Down Expand Up @@ -254,7 +254,7 @@ protected static boolean isRegistered(Server server) {
if (!addServerTestsCalled) {
throw new IllegalStateException("Cannot call isRegistered here. It is allowed only in suite method after addServerTests is called.");
}
if (server.equals(ANY)) {
if (server == ANY) {
return !alreadyRegistered.isEmpty();
} else {
return alreadyRegistered.contains(server);
Expand All @@ -277,7 +277,7 @@ protected J2eeServerNode getServerNode(Server server) {
return J2eeServerNode.invoke("Tomcat");
case ANY:
for (Server serv : Server.values()) {
if (serv.equals(ANY)) {
if (serv == ANY) {
continue;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public List<org.netbeans.spi.editor.hints.ErrorDescription> run(CompilationInfo
return null;
}
//Logger.getAnonymousLogger().log(Level.SEVERE, "---"+el+" "+(treePath.getLeaf() != null ? treePath.getLeaf().getKind() : "no kind"));
if (el.asType() == null || !el.asType().getKind().equals(TypeKind.DECLARED)) {
if (el.asType() == null || el.asType().getKind() != TypeKind.DECLARED) {
return null;
}
if (!isEEType(info, el.asType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.EnumSet;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -961,11 +962,10 @@ public void run(WorkingCopy workingCopy) throws IOException {
make.Literal(wsdlUrl)))); //NOI18N
// create field modifier: private(static) with @WebServiceRef annotation
// FileObject targetFo = workingCopy.getFileObject();
Set<Modifier> modifiers = new HashSet<Modifier>();
Set<Modifier> modifiers = EnumSet.of(Modifier.PRIVATE);
// if (Car.getCar(targetFo) != null) {
// modifiers.add(Modifier.STATIC);
// }
modifiers.add(Modifier.PRIVATE);
ModifiersTree methodModifiers = make.Modifiers(
modifiers,
Collections.<AnnotationTree>singletonList(wsRefAnnotation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ public static ResultProcess startServer(PayaraServer server,
// Add debug parameters read from domain.xml.
// It's important to add them before java options specified by user
// in case user specified it by himslef.
if (mode.equals(StartMode.DEBUG)) {
if (mode == StartMode.DEBUG) {
String debugOpts = propMap.get("debug-options");
String[] debugOptsSplited = debugOpts.split("\\s+(?=-)");
optList.addAll(Arrays.asList(debugOptsSplited));
}
// add profile parameters
if (mode.equals(StartMode.PROFILE)) {
if (mode == StartMode.PROFILE) {
}
// appending IDE specified options after the ones got from domain.xml
// IDE specified are takind precedence this way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ else if ( type instanceof WildcardType ){
private boolean hasModifier ( Element element , Modifier mod){
Set<Modifier> modifiers = element.getModifiers();
for (Modifier modifier : modifiers) {
if ( modifier.equals( mod )){
if (modifier == mod) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.EnumSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.el.ELException;
Expand Down Expand Up @@ -90,7 +91,7 @@ public final class ELTypeUtilities {
}

private static void put(Class<? extends Node> node, TypeKind... kinds) {
Set<TypeKind> kindSet = new HashSet<>();
Set<TypeKind> kindSet = EnumSet.noneOf(TypeKind.class);
kindSet.addAll(Arrays.asList(kinds));
TYPES.put(node, kindSet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.EnumMap;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.LogRecord;
Expand All @@ -63,7 +64,7 @@ public static enum Scope {

SCOPE_FACESCONFIG, SCOPE_PROJECT, SCOPE_ALL_FACESCONFIG
}
private static Map<Scope, String> scope2String = new HashMap<Scope, String>();
private static Map<Scope, String> scope2String = new EnumMap<>(Scope.class);
private static Map<String, Scope> string2Scope = new HashMap<String, Scope>();
private static final String TT_SCOPE = NbBundle.getMessage(PageFlowToolbarUtilities.class, "TT_Scope_DropDown");
private static final String LBL_SCOPE_FACESCONFIG = NbBundle.getMessage(PageFlowToolbarUtilities.class, "LBL_Scope_FacesConfig");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public boolean isValidProperty(ExecutableElement executableElement, Source sourc

// method has not parameters and return types are assignable.
if ( executableElement.getParameters().isEmpty() &&
( (TypeKind.VOID.equals(elementReturnType.getKind()) && VOID_RETURN_TYPE.equals(attributeReturnType)) ||
( (TypeKind.VOID == elementReturnType.getKind() && VOID_RETURN_TYPE.equals(attributeReturnType)) ||
(types.isAssignable(elementReturnType, attributeReturnTypeElement.asType())) ) ) {
return true;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public boolean isValidProperty(ExecutableElement executableElement, Source sourc
}

// Return types of the element and attribute are void
if (TypeKind.VOID.equals(elementReturnType.getKind()) && VOID_RETURN_TYPE.equals(attributeReturnType)) {
if (TypeKind.VOID == elementReturnType.getKind() && VOID_RETURN_TYPE.equals(attributeReturnType)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ static List<TypeElement> getImplementedInterfaces( TypeElement type ,
List<TypeElement> result = new ArrayList<TypeElement>(interfaces
.size());
for (TypeMirror typeMirror : interfaces) {
if (TypeKind.DECLARED.equals(typeMirror.getKind())) {
if (TypeKind.DECLARED == typeMirror.getKind()) {
Element element = ((DeclaredType) typeMirror).asElement();
if (ElementKind.INTERFACE.equals(element.getKind())) {
if (ElementKind.INTERFACE == element.getKind()) {
result.add( (TypeElement) element );
List<TypeElement> superInterfaces =
getImplementedInterfaces((TypeElement) element, helper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.EnumSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -1067,7 +1068,7 @@ public void run(CompilationController compilationController) throws IOException
MethodModel.Variable.create("java.lang.String", "string")
),
Collections.<String>emptyList(),
Collections.<Modifier>emptySet() //no modifiers
Collections.<Modifier>emptySet() //no modifiers
) : null;

String entityReferenceName = entityClass;
Expand Down Expand Up @@ -1697,13 +1698,16 @@ private static MethodTree createMethod(WorkingCopy workingCopy, Modifier[] modif
i++;
}

Set<Modifier> modifiersSet = EnumSet.noneOf(Modifier.class);
modifiersSet.addAll(Arrays.asList(modifiers));

MethodModel methodModel = MethodModel.create(
name,
returnType,
body,
paramsList,
Arrays.asList(exceptions),
new HashSet<Modifier>(Arrays.asList(modifiers))
modifiersSet
);
return MethodModelSupport.createMethodTree(workingCopy, methodModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.EnumSet;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
Expand Down
Loading