Skip to content

Commit

Permalink
Issue #4431: Modified ModifierOrderCheckTest.java and moved its input…
Browse files Browse the repository at this point in the history
… files to the modifierorder subdirectory
  • Loading branch information
Subbu Dantu authored and rnveach committed Jun 8, 2017
1 parent 0fcbcf3 commit ad2db09
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 17 deletions.
Expand Up @@ -39,13 +39,13 @@ public class ModifierOrderCheckTest
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "modifier" + File.separator + filename);
+ "modifier" + File.separator + "modifierorder" + File.separator + filename);
}

@Override
protected String getNonCompilablePath(String filename) throws IOException {
return super.getNonCompilablePath("checks" + File.separator
+ "modifier" + File.separator + filename);
+ "modifier" + File.separator + "modifierorder" + File.separator + filename);
}

@Test
Expand All @@ -68,7 +68,7 @@ public void testIt() throws Exception {
"49:35: " + getCheckMessage(MSG_ANNOTATION_ORDER, "@MyAnnotation4"),
"157:14: " + getCheckMessage(MSG_MODIFIER_ORDER, "default"),
};
verify(checkConfig, getPath("InputModifier.java"), expected);
verify(checkConfig, getPath("InputModifierOrderIt.java"), expected);
}

@Test
Expand All @@ -77,7 +77,7 @@ public void testDefaultMethods()
final DefaultConfiguration checkConfig =
createCheckConfig(ModifierOrderCheck.class);
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputModifier2.java"), expected);
verify(checkConfig, getPath("InputModifierOrderDefaultMethods.java"), expected);
}

@Test
Expand Down Expand Up @@ -121,7 +121,8 @@ public void testSkipTypeAnnotations() throws Exception {
final String[] expected = {
"103:13: " + getCheckMessage(MSG_ANNOTATION_ORDER, "@MethodAnnotation"),
};
verify(checkConfig, getNonCompilablePath("InputTypeAnnotations.java"), expected);
verify(checkConfig, getNonCompilablePath("InputModifierOrderTypeAnnotations.java"),
expected);
}

@Test
Expand Down
@@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.checks.modifier;
package com.puppycrawl.tools.checkstyle.checks.modifier.modifierorder;

import java.io.File;
import java.io.IOException;
Expand All @@ -10,7 +10,7 @@
import java.util.List;
import java.util.Map;

public class InputTypeAnnotations extends MyClass {
public class InputModifierOrderTypeAnnotations extends MyClass {

// Simple type definitions with type annotations
private @TypeAnnotation String hello = "Hello, World!";
Expand Down

This file was deleted.

@@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.checks.modifier;
package com.puppycrawl.tools.checkstyle.checks.modifier.modifierorder;

public @InterfaceAnnotation @interface InputModifierOrderAnnotationDeclaration {
int getValue();
Expand Down
@@ -0,0 +1,9 @@
package com.puppycrawl.tools.checkstyle.checks.modifier.modifierorder;
import java.util.Comparator;

public interface InputModifierOrderDefaultMethods extends Comparator<Integer> {
@Override
default int compare(Integer a, Integer b) {
return 0;
}
}
@@ -0,0 +1,160 @@
////////////////////////////////////////////////////////////////////////////////
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.checks.modifier.modifierorder;

/**
* Test case for Modifier checks:
* - order of modifiers
* - use of 'public' in interface definition
* @author lkuehne
*/
strictfp final class InputModifierOrderIt // illegal order of modifiers for class
{

/** Illegal order of modifiers for variables */
static private boolean sModifierOrderVar = false;

/**
* Illegal order of modifiers for methods. Make sure that the
* first and last modifier from the JLS sequence is used.
*/
strictfp private void doStuff()
{
}

/** Single annotation without other modifiers */
@MyAnnotation2 void someMethod()
{
}

/** Illegal order of annotation - must come first */
private @MyAnnotation2 void someMethod2()
{
}

/** Annotation in middle of other modifiers otherwise in correct order */
private @MyAnnotation2 strictfp void someMethod3()
{
}

/** Correct order */
@MyAnnotation2 private strictfp void someMethod4()
{
}

/** Annotation in middle of other modifiers otherwise in correct order */
@MyAnnotation2 private static @MyAnnotation4 strictfp void someMethod5()
{
}

/** holder for redundant 'public' modifier check. */
public static interface InputRedundantPublicModifier // violation
{
/** redundant 'public' modifier */
public void a(); // violation

/** all OK */
void b();

/** redundant abstract modifier */
abstract void c(); // violation

/** redundant 'public' modifier */
public float PI_PUBLIC = (float) 3.14; // violation

/** redundant 'abstract' modifier (field can not be abstract) */
// abstract float PI_ABSTRACT = (float) 3.14;

/** redundant 'final' modifier */
final float PI_FINAL = (float) 3.14; // violation

/** all OK */
float PI_OK = (float) 3.14;
}

/** redundant 'final' modifier */
private final void method() // violation
{
}
}

/** Holder for redundant 'final' check. */
final class RedundantFinalClass
{
/** redundant 'final' modifier */
public final void finalMethod() // violation
{
}

/** OK */
public void method()
{
}
}

/** Holder for redundant modifiers of inner implementation */
abstract interface InnerImplementation // violation
{
InnerImplementation inner =
new InnerImplementation()
{
/** compiler requires 'public' modifier */
public void method()
{
}
};

void method();
}

/** Holder for redundant modifiers of annotation fields/variables */
@interface Annotation
{
public String s1 = ""; // violation
final String s2 = ""; // violation
static String s3 = ""; // violation
String s4 = "";
public String blah(); // violation
abstract String blah2(); // violation
}

@interface MyAnnotation2 {
}

@interface MyAnnotation4 {
}

class SafeVarargsUsage {
@Deprecated
@SafeVarargs
private final void foo(int... k) {}

@Deprecated
@SafeVarargs
@SuppressWarnings("")
private final void foo1(Object... obj) {}
}

enum TestEnum {
;

public void method() {
}
}

/** holder for interface specific modifier check. */
interface InputDefaultPublicModifier
{
/** correct order */
default strictfp void a()
{
}

/** wrong order */
strictfp default void b() // violation
{
}
}

0 comments on commit ad2db09

Please sign in to comment.