-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[apex] Add validation of ApexDoc comments #1314
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d500e7b
Add ApexDocRule
jeffhube cba80b2
Update rule since version
jeffhube a17f38a
Remove autogenerated doc changes
jeffhube 42ab055
Merge branch 'master' into apexdoc
jeffhube df7cc1c
Add ASTFormalComment
jeffhube e86166e
Add ASTFormalComment as first child, calculate position
jeffhube 86dc44d
Revert changes to ApexRootNode
jeffhube File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFormalComment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.lang.apex.ast; | ||
|
||
public class ASTFormalComment extends AbstractApexNodeBase { | ||
private String token; | ||
|
||
public ASTFormalComment(String token) { | ||
super(ASTFormalComment.class); | ||
this.token = token; | ||
} | ||
|
||
@Override | ||
Object jjtAccept(ApexParserVisitor visitor, Object data) { | ||
return visitor.visit(this, data); | ||
} | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNodeBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.lang.apex.ast; | ||
|
||
import net.sourceforge.pmd.lang.ast.AbstractNode; | ||
import net.sourceforge.pmd.lang.ast.Node; | ||
import net.sourceforge.pmd.lang.ast.SourceCodePositioner; | ||
|
||
public abstract class AbstractApexNodeBase extends AbstractNode { | ||
|
||
public AbstractApexNodeBase(int id) { | ||
super(id); | ||
} | ||
|
||
public AbstractApexNodeBase(Class<?> klass) { | ||
super(klass.hashCode()); | ||
} | ||
|
||
public void calculateLineNumbers(SourceCodePositioner positioner, int startOffset, int endOffset) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should not be public - it's enough, if it can be called from classes within the same package ( |
||
// end column will be interpreted as inclusive, while endOffset/endIndex | ||
// is exclusive | ||
endOffset -= 1; | ||
|
||
this.beginLine = positioner.lineNumberFromOffset(startOffset); | ||
this.beginColumn = positioner.columnFromOffset(this.beginLine, startOffset); | ||
this.endLine = positioner.lineNumberFromOffset(endOffset); | ||
this.endColumn = positioner.columnFromOffset(this.endLine, endOffset); | ||
|
||
if (this.endColumn < 0) { | ||
this.endColumn = 0; | ||
} | ||
} | ||
|
||
/** | ||
* Accept the visitor. * | ||
*/ | ||
abstract Object jjtAccept(ApexParserVisitor visitor, Object data); | ||
|
||
/** | ||
* Accept the visitor. * | ||
*/ | ||
public Object childrenAccept(ApexParserVisitor visitor, Object data) { | ||
if (children != null) { | ||
for (int i = 0; i < children.length; ++i) { | ||
@SuppressWarnings("unchecked") | ||
// we know that the children here are all ApexNodes | ||
AbstractApexNodeBase apexNode = (AbstractApexNodeBase) children[i]; | ||
apexNode.jjtAccept(visitor, data); | ||
} | ||
} | ||
return data; | ||
} | ||
|
||
@Override | ||
public int getBeginLine() { | ||
if (this.beginLine > 0) { | ||
return this.beginLine; | ||
} | ||
Node parent = jjtGetParent(); | ||
if (parent != null) { | ||
return parent.getBeginLine(); | ||
} | ||
throw new RuntimeException("Unable to determine beginning line of Node."); | ||
} | ||
|
||
@Override | ||
public int getBeginColumn() { | ||
if (this.beginColumn > 0) { | ||
return this.beginColumn; | ||
} | ||
Node parent = jjtGetParent(); | ||
if (parent != null) { | ||
return parent.getBeginColumn(); | ||
} | ||
throw new RuntimeException("Unable to determine beginning column of Node."); | ||
} | ||
|
||
@Override | ||
public int getEndLine() { | ||
if (this.endLine > 0) { | ||
return this.endLine; | ||
} | ||
Node parent = jjtGetParent(); | ||
if (parent != null) { | ||
return parent.getEndLine(); | ||
} | ||
throw new RuntimeException("Unable to determine ending line of Node."); | ||
} | ||
|
||
@Override | ||
public int getEndColumn() { | ||
if (this.endColumn > 0) { | ||
return this.endColumn; | ||
} | ||
Node parent = jjtGetParent(); | ||
if (parent != null) { | ||
return parent.getEndColumn(); | ||
} | ||
throw new RuntimeException("Unable to determine ending column of Node."); | ||
} | ||
|
||
@Override | ||
public final String getXPathNodeName() { | ||
return this.getClass().getSimpleName().replaceFirst("^AST", ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all instances of a node type using this constructor would have the same id.. I'm not sure it would affect our current use, but maybe we should avoid this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind, we already did it this way.. to be revised in a different PR