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

Issue #461: FieldDeclarationsCountCheck (NEW) #480

Conversation

vorburger
Copy link
Contributor

@vorburger vorburger commented Nov 16, 2016

@vorburger
Copy link
Contributor Author

@romani I've tried, but failed, to understand what it's trying to tell me with the following violation in a new class I introduced - the exact same import appears in many other *Check classes - what on earth is it complaining about that I'm importing wrong here - can you help?

[ERROR] src/main/java/com/github/sevntu/checkstyle/checks/coding/FieldDeclarationsCountCheck.java:[22,1] (imports) ImportControl: Disallowed import - com.github.sevntu.checkstyle.Utils

@rnveach
Copy link
Contributor

rnveach commented Nov 16, 2016

@vorburger That is a check that prevents certain packages from using what he has defined as illegal imports. It means you shouldn't be importing that class in FieldDeclarationsCountCheck.
The violation is referring to this line: 0f7539f#diff-1113b12ada701bc205c9c2de790bda2aR22
Currently only com.github.sevntu.checkstyle.checks.api package is allowed to use that import. I am unfamiliar with the reasoning for this. It could be an oversight for all I know.

It looks like you added new methods to Utils. Do they need to be there instead of inside FieldDeclarationsCountCheck?
Also, you'll need to rebase your class to remove the conflicts.

@vorburger vorburger force-pushed the issue461_FieldDeclarationsCountCheck branch from 0f7539f to 9dd41b0 Compare November 17, 2016 10:55
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 98.205% when pulling 9dd41b0 on vorburger:issue461_FieldDeclarationsCountCheck into d77b072 on sevntu-checkstyle:master.

@vorburger
Copy link
Contributor Author

@vorburger That is a check that prevents certain packages from using what he has defined as illegal imports.

http://checkstyle.sourceforge.net/config_imports.html#ImportControl

It means you shouldn't be importing that class in FieldDeclarationsCountCheck.
The violation is referring to this line: 0f7539f#diff-1113b12ada701bc205c9c2de790bda2aR22

Sure, I got that, but as I asked above, "the exact same import appears in many other *Check classes", see e.g. https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/EmptyPublicCtorInClassCheck.java#L7, so why is that allowed there but in my new class it's whining about it?

Currently only com.github.sevntu.checkstyle.checks.api package is allowed to use that import. I am unfamiliar with the reasoning for this. It could be an oversight for all I know.

There is no com.github.sevntu.checkstyle.checks.api package; thus proposing #484

It looks like you added new methods to Utils.

Yeah. I'm therefore proposing to solve this confounding "problem" by adding https://github.com/sevntu-checkstyle/sevntu.checkstyle/pull/480/files#diff-42857ffc420c808e64abbf2a0e0440b4R13

Do they need to be there instead of inside FieldDeclarationsCountCheck?

Yes, because I'll be re-using those util methods in other changes from #457 I'm about to propose, as soon as we can get this one agreed upon and merged.

An alternative to sharing those as static methods in that Utils class would be to introduce a new AbstractFieldCheck kinda class and put those there (as non-static). But given that there already is a Utils class, IMHO it's better to use that instead of class hierarchy for this purpose.

Also, you'll need to rebase your class to remove the conflicts.

Sure, done.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rebase and resolve all my comments.
Please reply as "done" (or "..whatever is a reply...") to EACH of it.

}

/**
* Check node for matching class, taken both FQN and short name into account.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is FQN ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it's fully qualified name, I'll update the JavaDoc

* @param ast an AST node
* @return FQN of type
*/
public static String getTypeName(final DetailAST ast) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hosting in Utils imply no context.
So name of the method should be clear enough to not misuse. Does it work on any ast ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will rename it to getTypeNameOfFirstToken(), does that work better for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, for now

* @param fqnClassName
* @return true if type name of first token in node is fqnClassName, or its short name; false otherwise
*/
public static boolean isMatchingClass(final DetailAST ast, final String fqnClassName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make it as single point of exit from method.
Please rename it and make i like "matchesFullyQualifiedName"

Copy link
Contributor Author

@vorburger vorburger Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will be done in next push.

import com.puppycrawl.tools.checkstyle.api.TokenTypes;

/**
* Checks that classes have at most 1 field of the given className.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc in sevntu project is all that users have to read about Check. Please extend description place examples of usage, see other checks for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

}

@Override
public int[] getDefaultTokens() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please override all methods http://checkstyle.sourceforge.net/writingchecks.html#Understanding_token_sets
in most recent releases of checkstyle these methods become abstract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, if you say so.. I've just implemented getRequiredTokens() and getAcceptableTokens() as return getDefaultTokens(). There is no setTokens(). If that is NOK, please update that documentation to clarify, or point me to an example in another existing *Check to follow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that our documentation is not ideal .... . Unfortunately usage of them is different for each Check, in some Check all of them return different in size array of Tokens (but always interchangeable).
Can you give us advices on how you would like too see this doc (in separate issue) ? For now I am blind as I spent too much time with that project.

/**
* Field to hold previously seen Logger.
*/
private String prevSeenClassName = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all fields of Checks that are not properties of Check, should be reset in beginTree method, to avoid causing cache problems on multi-file launch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks a lot for pointing this out; done in next iteration.

* @author Milos Fabian, Pantheon Technologies - original author (in OpenDaylight)
* @author Michael Vorburger.ch - refactored and made more generalized for contribution to Sevntu
*/
public class FieldDeclarationsCountCheck extends AbstractCheck {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check is named as "Count" , but no count could be adjusted.
Add property or rename a Check.

Copy link
Contributor Author

@vorburger vorburger Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, renamed to FieldSingleDeclarationCheck in next iteration (also FieldSingleDeclarationCheckTest)


public class FieldDeclarationsCountCheckOK {

org.slf4j.Logger logger;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make UT with class with two fields with full name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sure, if you insist.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FieldDeclarationsCountCheckNOK {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add examples of usage in classes that have subclasses with loggers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOK, because my understanding is that Checkstyle cannot handle this, because its based on analysing the AST of a single file; AFAIK I couldn't check parent class fields, right? So.. no point, I would have thought.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I meant inner classes. I did a comment one more time in my second iteration of review.

public class FieldDeclarationsCountCheckNOK {

// both FQN and import'ed type names work:
Logger logger1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make a test case with "Logger" from different(not slf4j) package in imports.
there should be no violation.
Check have to process imports to know what short name is actually used, we have examples in other Checks for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOK, I do not know how to do this.. can you point me to an existing Check with a corresponding Test that does this, so I can copy and learn from it? This seems a lower priority to me - perhaps something that could be dealt with in a follow-up, after this is accepted and merged?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples:

~/java/github/sevntu-checkstyle/sevntu.checkstyle/sevntu-checks/src/main/java [master|✔] 
$ grep -R "IMPORT" * | head -n 5 
com/github/sevntu/checkstyle/checks/coding/ForbidInstantiationCheck.java:        return new int[] {TokenTypes.IMPORT, TokenTypes.LITERAL_NEW };
com/github/sevntu/checkstyle/checks/coding/ForbidInstantiationCheck.java:            case TokenTypes.IMPORT:
com/github/sevntu/checkstyle/checks/coding/ForbidInstantiationCheck.java:     *        literal node ("IMPORT" or "LITERAL_NEW" node types).
com/github/sevntu/checkstyle/checks/coding/ForbidInstantiationCheck.java:     *         "IMPORT" node or instanstiated class Name&Path for given
com/github/sevntu/checkstyle/checks/coding/ForbidCertainImportsCheck.java:                TokenTypes.IMPORT, TokenTypes.LITERAL_NEW, };

https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/ForbidInstantiationCheck.java

Yes, it could be postponed but in this case please mention this in javadoc as limitation that could be improved in future.

@vorburger vorburger force-pushed the issue461_FieldDeclarationsCountCheck branch 3 times, most recently from 7666545 to 59d112a Compare November 22, 2016 17:16
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 98.234% when pulling 59d112a on vorburger:issue461_FieldDeclarationsCountCheck into 29b5ac0 on sevntu-checkstyle:master.

Copy link
Contributor

@rnveach rnveach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vorburger Please look into full file difference in checkstyle-extensions.xml. I think we should only see your additions.

@@ -10,6 +10,7 @@
<allow pkg="com.google.common"/>
<allow pkg="com.puppycrawl.tools.checkstyle.api"/>
<allow pkg="com.puppycrawl.tools.checkstyle.checks"/>
<allow class="com.github.sevntu.checkstyle.Utils"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already fixed in previous PR, you can see it a few lines down from here. Please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

if (findFirstToken != null) {
final FullIdent ident = CheckUtils.createFullType(findFirstToken);
if (ident != null) {
return ident.getText();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single return point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done. (BTW: If this is important to you guys, how about activating Checkstyle rule for enforcing this?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already an open issue in main project where sevntu get its configuration from.
Just no one has worked on it.

public static String getClassName(final DetailAST ast) {
DetailAST parent = ast.getParent();
while (parent.getType() != TokenTypes.CLASS_DEF
&& parent.getType() != TokenTypes.ENUM_DEF) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a common utility and your going up the chain, you have to be careful that you don't miss the top level class and create an NPE.
This looks like your missing INTERFACE_DEF and ANNOTATION_DEF.
It may not be pertinent to your check, but this is a common utility now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done; introduced a new isTypeDefinition() utility method

/**
* Field to hold previously seen Logger.
*/
private String prevSeenClassName = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we init with empty string and then set to null in begin tree and then back to empty string in finishTree? Let's be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done, using empty string instead of null consistently everywhere now.

/**
* Class name check for.
*/
private String className;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No default value means this check will issue an NPE if used without setting className.
@romani Should org.slf4j.Logger be the default value or should we have null protection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnveach FYI I originally proposed this as a SingleLoggerCheck, and @romani objected saying that it had to be more general ... ;-) so I'll assume that he doesn't want org.slf4j.Logger to be the default value for className. I've added a null check in visitToken() now, with a IllegalStateException. Personally I like that much better than null check and just ignoring it - as a user, if I've configured this Check, I want to be clearly told (by a failure) why it doesn't do something, rather tha nit just silently not doing anything. PS: In an ideal world, I guess CS could have real concept of mandatory VS optional configuration properties... one day.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally Check should be more general than default configuration.
If default configuration is not possible to make as reasonable, Check should do nothing and no crashes are expected.

}

@Override
public void finishTree(DetailAST rootAST) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you do reset of fields in beginTree, this isn't needed. You really only need one or the other. beginTree is preferred so it will hit before check visit begins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, removed.

@@ -33,6 +33,7 @@ either.log.or.throw=Either log or throw exception.
explicit.init=Variable ''{0}'' explicitly initialized to ''{1}'' (default value for its type).
fall.through=Fall through from previous branch of the switch statement.
fall.through.last=Fall through from the last branch of the switch statement.
field.count={0} might be declared only once.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might? It describes 'possibility' of something. We already know it is declared multiple times, so we should be more direct with violations like should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think that was meant to be an imperative "may" instead of "might", but "should" is better; done.


@Override
public void visitToken(DetailAST ast) {
if (isVariable(ast) && Utils.matchesFullyQualifiedName(ast, className)) {
Copy link
Contributor

@rnveach rnveach Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not looking at import statements. User can import class Logger and it not be from org.slf4j, but you would still mark it as violation if they didn't fully qualify it, right?
Why do I need to define full path in check, org.slf4j.Logger as your examples show, if check won't obey it? You could just give Logger only and it will be same result.
This seems similar to the check EitherLogOrThrowCheck.
@romani your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnveach you're right, I think (from what I understand of CS). But this almost more of a limitation of CS.. I had a quick look at EitherLogOrThrowCheck, and see how that Check has code to deal with this (hasLoggerClassInImports), but... that almost looks a like a one off hack to me. If you would like Checks to be able to be written for both full and local type names, then shouldn't there be better shared infrastructure available for writing such Checks? I would argue that mixed types of Logger is extremely atypical, and so while I agree this isn't completely perfect strictly speaking, it seems like a very minor problem in real world, and we should ignore this for now, and move forward. @romani your thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared infrastructure available for writing such Checks?

Yes we lack a lot on infrastructure util methods and examples and .... our team is very very tiny.
All we have is what you see in repo, all re welcome to improve :) .

it seems like a very minor problem in real world, and we should ignore this for now, and move forward.

we could, I am ok with multi-step development. All depends on your time.
But on each step logic should be clear for user. So if we agree on limitation, it should be in javadoc and user should clear see this, in other case there will be storm of requests/bugs from users.

if (isVariable(ast) && Utils.matchesFullyQualifiedName(ast, className)) {
final String nowVisitingClassName = Utils.getClassName(ast);
if (this.prevSeenClassName != null
&& this.prevSeenClassName.equals(nowVisitingClassName)) {
Copy link
Contributor

@rnveach rnveach Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vorburger This line puzzles me.
I am not sure when prevSeenClassName will not equal nowVisitingClassName. User gave specific class, so it should always be said class, right? I assume we are passing line/branch coverage here.
Can you point me to instance where equals evaluates to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've inherited this code from someone else. This is a left over from when it didn't reset in beginTree and finishTree; so it kept track of which class its visiting. Meanwhile, I guess this could be written differently now - could you please have a look at the latest iteration - makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New iteration definitely makes more sense to me.

@vorburger
Copy link
Contributor Author

@rnveach re. "Please look into full file difference in checkstyle-extensions.xml. I think we should only see your additions.", this will be fixed by #490; unfortunately once again only one-off. In an ideal world, we really should do checkstyle/checkstyle#893 so we can do checkstyle/checkstyle#3557

@vorburger vorburger force-pushed the issue461_FieldDeclarationsCountCheck branch from 59d112a to 60519f6 Compare November 23, 2016 11:59
@vorburger
Copy link
Contributor Author

@romani could you please advise how to address the coverage problem shown below, which is due to the introduction of getAcceptableTokens() you've requested earlier above here.. I've no idea what that does, and don't see what one would have to do in the test to make that covered - can you point to a line in an existing test which leads to coverage of getAcceptableTokens() ? This is required because you seem to (now, new; since you've fixed Cobertura) be enforcing 100% test coverage.

[ERROR] com.github.sevntu.checkstyle.checks.coding.FieldSingleDeclarationCheck failed coverage check. Line coverage rate of 93.7% is below 100.0%

@rnveach
Copy link
Contributor

rnveach commented Nov 23, 2016

how to address the coverage problem shown below, which is due to the introduction of getAcceptableTokens()

@vorburger
getAcceptableTokens is called in TreeWalker when it is first registering the check. It is only called when user specifies tokens and we have to verify if they should be allowed.
Every check accepts a property tokens. It is how we allow users to customize what some check validates pertaining to specific nodes. It is easier than specifying a bunch of boolean properties to turn things on and off.

Try adding something like config.addAttribute("tokens", "CLASS_DEF"); to a new test.
Edit: Might have to be VARIABLE_DEF, CLASS_DEF.

@vorburger vorburger force-pushed the issue461_FieldDeclarationsCountCheck branch from 60519f6 to f6759e4 Compare November 23, 2016 13:41
@vorburger
Copy link
Contributor Author

@rnveach thank you, that seems to work; done.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 98.093% when pulling f6759e4 on vorburger:issue461_FieldDeclarationsCountCheck into 4f77fc6 on sevntu-checkstyle:master.

@vorburger vorburger force-pushed the issue461_FieldDeclarationsCountCheck branch from f6759e4 to 7991b1d Compare November 25, 2016 10:01
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 98.093% when pulling 7991b1d on vorburger:issue461_FieldDeclarationsCountCheck into 12a68fd on sevntu-checkstyle:master.

Signed-off-by: Michael Vorburger <mike@vorburger.ch>
@vorburger vorburger force-pushed the issue461_FieldDeclarationsCountCheck branch from 7991b1d to 9410b85 Compare November 25, 2016 18:36
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 98.093% when pulling 9410b85 on vorburger:issue461_FieldDeclarationsCountCheck into b05ae88 on sevntu-checkstyle:master.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/**
* Check node for matching class, taken both FQN and short name into account.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put words for FQN, each static function is independent from each other , so no shared context/javadoc .

/**
* Field to remember if class was previously seen in current File.
*/
private boolean hasPreviouslySeenClass;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base on javadoc it should be named isPreviouslySeenClass

* @param className the fully qualified name (FQN) of the class
*/
public void setClassName(String className) {
this.fullyQualifiedClassName = className;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please name setter exactly as field is named (name of argument is ok), not sure why our Check (http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/SimpleAccessorNameNotationCheck.html) did not catch that ....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romani Sevntu does not run its own checks against itself. We only run Checkstyle checks.
See https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/pom.xml#L123

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
So, please remove that annotation and catch with checking exact excetion and message of it.


@Override
public int[] getDefaultTokens() {
return new int[] {TokenTypes.VARIABLE_DEF };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkstyle.sourceforge.net/writingchecks.html#Understanding_token_sets
please move that array return to getAcceptableTokens(), all other methods should call getAcceptableTokens().

if (fullyQualifiedClassName == null) {
throw new IllegalStateException("Must set mandatory className property in"
+ getClass().getSimpleName());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not good, please put some default value, it could match some class by default or to no class all like ""(empty string). In this case we will avoid null and make Check work even in misconfiguration.
In current implementation you will trow in IDE too much exceptions or in logs .... that is very inconvenient.

+ getClass().getSimpleName());
}
if (Utils.matchesFullyQualifiedName(ast, fullyQualifiedClassName)) {
if (hasPreviouslySeenClass) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see filtering for fields.
Your Check is named - FieldSingleDeclarationCheck , but you examine fields+variables.

verify(config, getPath("FieldSingleDeclarationCheck_OK.java"), new String[] {});
}

@Test(expected = CheckstyleException.class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnveach , I thought we already made a Check that control that bad practice.
sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/ForbidAnnotationElementValueCheck.html
Do we miss to add it to config ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romani See my comment above, sevntu doesn't run its own checks against itself. Only Checkstyle checks.
Plus, we don't run anything against Test in sevntu hence why there is no header in this file.


org.slf4j.Logger logger;

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see tests for cases with inner classes (in class , in method, ..... yes real life code is crazy on purpose).
If we care only about Top level class we should define this in javadoc or .... .

Copy link
Contributor

@rnveach rnveach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes from me.

Please see answers to old questions that are now hidden:
#480 (comment)
#480 (comment)

String className = "org.slf4j.Logger";
config.addAttribute("className", className);
final String expected[] = { "10: " + getCheckMessage(MSG_KEY, className) };
verify(config, getPath("FieldSingleDeclarationCheck_NOK.java"), expected);
Copy link
Contributor

@rnveach rnveach Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input files should start with Input. I just started this on other files, and main repo already encourages it.

config.addAttribute("className", className);
final String expected[] = { "10: " + getCheckMessage(MSG_KEY, className) };
verify(config, getPath("FieldSingleDeclarationCheck_NOK.java"), expected);
verify(config, getPath("FieldSingleDeclarationCheck_OK.java"), new String[] {});
Copy link
Contributor

@rnveach rnveach Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One test per method please. It is weird seeing expected variable where it is only valid for one run and the other is expecting a different result.

config.addAttribute("className", className);
final String expected[] = { "7: " + getCheckMessage(MSG_KEY, className) };
verify(config, getPath("FieldSingleDeclarationCheck_FQN_NOK.java"), expected);
verify(config, getPath("FieldSingleDeclarationCheck_OK.java"), new String[] {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, one test per method.

@romani
Copy link
Member

romani commented Dec 2, 2016

@vorburger , please rebase and add your Check to https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/sevntu-checks.xml for testing over our code base by Travis.

@romani
Copy link
Member

romani commented Jan 14, 2017

@vorburger , ping

@romani
Copy link
Member

romani commented Jan 23, 2017

@vorburger , ping .
Please let me know if you want to drop this PR , smb else might finish your work

@romani
Copy link
Member

romani commented Apr 21, 2017

@vorburger , ping .

@romani
Copy link
Member

romani commented May 19, 2019

we lost connection to Author of this code, I am closing PR .... if author or any other person ready to continue, we can reopen PR or start it from scratch.

@romani romani closed this May 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants