Skip to content

Commit

Permalink
more checkstyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Holy committed Jul 20, 2011
1 parent ae1431e commit 8738e7f
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 101 deletions.
2 changes: 2 additions & 0 deletions checkstyle-suppressions.xml
Expand Up @@ -8,4 +8,6 @@

<!-- Tone down the checking for test code -->
<suppress checks="MethodName" files=".*[\\/]test[\\/].*Test\.java"/>
<suppress checks="JavadocType" files=".*[\\/]test[\\/].*Test\.java"/>
<suppress checks="JavadocMethod" files=".*[\\/]test[\\/].*Test\.java"/>
</suppressions>
9 changes: 6 additions & 3 deletions jh-sun-eclipse-checkstyle.xml
Expand Up @@ -5,8 +5,9 @@
This configuration file was written by the eclipse-cs plugin configuration editor
-->
<!--
Checkstyle-Configuration: jh - Sun Checks (Eclipse)
Description: none
Checkstyle-Configuration: jh's Sun Checks (Eclipse)
Description:
JH - slightly modified version of Sun Checks that better matches the default code formatter setting of Eclipse and my preferences.
-->
<module name="Checker">
<property name="severity" value="warning"/>
Expand Down Expand Up @@ -35,7 +36,9 @@
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="AvoidStarImport"/>
<module name="AvoidStarImport">
<property name="allowStaticMemberImports" value="true"/>
</module>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
Expand Down
1 change: 1 addition & 0 deletions static-jsfexpression-validator-core/README
Expand Up @@ -28,6 +28,7 @@ TODO
'#{bean.listProperty[0].elementProperty}': PropertyNotFoundException - Property 'elementProperty' not found on class net.jakubholy.jeeutils.jsfelcheck.validator.MockObjectOfUnknownType]; expression=#{bean.listProperty[0].elementProperty}, file=/mypage.jsp, tagLine=126]
- better error msg. for PropertyNotFoundException on class Error_YouMustDelcareTypeForThisVariable => include advice how to solve it
=> make it clear the solution is st. like propertyTypeOverrides.put("bean.listProperty.*", TheElementType.class);
- analyzer: replace the map arguments with method like declareLocalVariable ... (more readable, understandable)

...
- don't mock implementations of Map/Collection, instantiate them instead (eg ArrayList)
Expand Down
Expand Up @@ -24,11 +24,19 @@
*/
public interface ManagedBeanFinder {

/**
* Definition of a managed bean.
*/
public static class ManagedBeanDescriptor {

private final String name;
private final Class<?> type;

/**
* New descriptor.
* @param name (required) the managed bean's name
* @param type (required) the managed bean's class
*/
public ManagedBeanDescriptor(final String name, final Class<?> type) {
if (name == null) {
throw new IllegalArgumentException("name: String must be set");
Expand Down Expand Up @@ -59,6 +67,7 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
// CHECKSTYLE:OFF
if (this == obj)
return true;
if (obj == null)
Expand All @@ -77,6 +86,7 @@ public boolean equals(Object obj) {
} else if (!type.equals(other.type))
return false;
return true;
// CHECKSTYLE:ON
}

@Override
Expand All @@ -85,6 +95,11 @@ public String toString() {
}
}

public Collection<ManagedBeanDescriptor> findDefinedBackingBeans();
/**
* Find all managed beans defined in the application
* (those this particular finder can discover).
* @return possibly empty collection
*/
Collection<ManagedBeanDescriptor> findDefinedBackingBeans();

}
Expand Up @@ -37,22 +37,27 @@ public class SpringContextBeanFinder implements ManagedBeanFinder {

private final Collection<File> springContextFiles;

/**
* New finder reading Spring beans from the given applicationContext XML files.
* @param springContextFiles (optional) nothing done if empty/null
*/
public SpringContextBeanFinder(final Collection<File> springContextFiles) {
if (springContextFiles == null || springContextFiles.isEmpty()) {
throw new IllegalArgumentException("springContextFiles: Collection<File> cannot be null/empty, is: " + springContextFiles);
throw new IllegalArgumentException(
"springContextFiles: Collection<File> cannot be null/empty, is: " + springContextFiles);
}

for (File file : springContextFiles) {
if (!file.canRead()) {
throw new IllegalArgumentException("The supplied Spring application context XML file " +
"cannot be opened for reading: " + file);
throw new IllegalArgumentException("The supplied Spring application context XML file "
+ "cannot be opened for reading: " + file);
}
}

this.springContextFiles = new LinkedList<File>(springContextFiles);
}

//@Override
/** {@inheritDoc} */
public Collection<ManagedBeanDescriptor> findDefinedBackingBeans() {
Collection<ManagedBeanDescriptor> allBeans = new LinkedList<ManagedBeanFinder.ManagedBeanDescriptor>();

Expand Down Expand Up @@ -80,11 +85,11 @@ private Class<?> loadBeanClass(String beanName, String beanClassName) {
}
}

private Resource[] toResources(Collection<File> springContextFiles) {
Resource[] locations = new Resource[springContextFiles.size()];
private Resource[] toResources(Collection<File> resourceFiles) {
Resource[] locations = new Resource[resourceFiles.size()];

int index = 0;
for (File configFile : springContextFiles) {
for (File configFile : resourceFiles) {
locations[index++] = new FileSystemResource(configFile);
}

Expand Down
Expand Up @@ -31,12 +31,24 @@ public class AttributesValidationResult extends ValidationResult {
private Map<String, ValidationResult> results = new Hashtable<String, ValidationResult>();
private boolean error = false;

/**
* Add results of validation of the given attribute.
* @param attribute (required) the name of the tag's attribute
* @param result (required)
*/
public void add(String attribute, ValidationResult result) {
if (result == null) throw new IllegalArgumentException("result: ValidationResult may not be null");
if (result == null) {
throw new IllegalArgumentException("result: ValidationResult may not be null");
}
results.put(attribute, result);
error |= result.hasErrors();
}

/**
* Get results of validating EL in the given attribute.
* @param attribute (required)
* @return null if the attribute had no EL
*/
public ValidationResult get(String attribute) {
return results.get(attribute);
}
Expand All @@ -46,6 +58,10 @@ public boolean hasErrors() {
return error;
}

/**
* True if any attribute's value contained an EL.
* @return see above
*/
public boolean jsfExpressionsFound() {
return !results.isEmpty();
}
Expand Down
Expand Up @@ -22,7 +22,7 @@
import java.util.List;

import net.jakubholy.jeeutils.jsfelcheck.CollectedValidationResults;
import net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.jasper.variables.MissingLocalVariableTypeDeclarationException;
import net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.jasper.variables.MissingLocalVariableTypeDeclarationException; // SUPPRESS CHECKSTYLE
import net.jakubholy.jeeutils.jsfelcheck.validator.results.JsfExpressionDescriptor;
import net.jakubholy.jeeutils.jsfelcheck.validator.results.MultipleValidationResults;
import net.jakubholy.jeeutils.jsfelcheck.validator.results.ValidationResult;
Expand All @@ -48,20 +48,30 @@ protected void postAddSingleResult(ValidationResult singleResult) {
descriptor.setTagLineNumber(currentTagLineNumber);
}

public void addAllFromTagLineNr(int currentTagLineNumber,
/**
* Add results of validating ELs in attributes of a tag that appeared at a particular line.
* @param currentTagLine number of the line in the source file where the tag starts
* @param allResults (required) the results to add
*/
public void addAllFromTagLineNr(int currentTagLine,
Collection<ValidationResult> allResults) {
this.currentTagLineNumber = currentTagLineNumber;
this.currentTagLineNumber = currentTagLine;
super.addAll(allResults);

}

/**
* Report a local variable for which there was no type declaration.
* @param e (required)
*/
public void reportContextVariableNeedingTypeDeclaration(
MissingLocalVariableTypeDeclarationException e) {
getVariablesNeedingTypeDeclaration().add(e);
}

/* (non-Javadoc)
* @see net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.jasper.CollectedValidationResults#getVariablesNeedingTypeDeclaration()
* @see net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.jasper.CollectedValidationResults
* #getVariablesNeedingTypeDeclaration()
*/
//@Override
public Collection<MissingLocalVariableTypeDeclarationException> getVariablesNeedingTypeDeclaration() {
Expand Down
Expand Up @@ -21,14 +21,14 @@
import java.util.logging.Logger;

import net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.jasper.variables.ContextVariableRegistry;
import net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.jasper.variables.MissingLocalVariableTypeDeclarationException;
import net.jakubholy.jeeutils.jsfelcheck.expressionfinder.impl.jasper.variables.MissingLocalVariableTypeDeclarationException; // SUPPRESS CHECKSTYLE
import net.jakubholy.jeeutils.jsfelcheck.validator.JsfElValidator;
import net.jakubholy.jeeutils.jsfelcheck.validator.exception.InternalValidatorFailureException;
import net.jakubholy.jeeutils.jsfelcheck.validator.results.JsfExpressionDescriptor;

/**
* The main processing class for the Jasper-based implementation: retrieves information about
* JSP tags of interest and JSF EL extraction and validation while maintaining the local variable stack.
* JSP tags of interest and triggers JSF EL extraction and validation while maintaining the local variable stack.
*/
public class JsfElValidatingPageNodeListener implements PageNodeListener {

Expand All @@ -39,17 +39,23 @@ public class JsfElValidatingPageNodeListener implements PageNodeListener {
private final CollectedValidationResultsImpl validationResults = new CollectedValidationResultsImpl();

private Stack<String> jspFileInclusionStack = new Stack<String>();
private String jspFile;

public JsfElValidatingPageNodeListener(JsfElValidator expressionValidator, ContextVariableRegistry contextVarRegistry) {
private String currentJspFile;

/**
* New listener using the given validator and resolving local variables via the given registry.
* @param expressionValidator (required)
* @param contextVarRegistry (required)
*/
public JsfElValidatingPageNodeListener(
JsfElValidator expressionValidator, ContextVariableRegistry contextVarRegistry) {
this.contextVarRegistry = contextVarRegistry;
this.nodeValidator = new PageNodeExpressionValidator(expressionValidator);
}

//@Override
/** {@inheritDoc} */
public void nodeEntered(PageNode jspTag) {
LOG.fine("PROCESSING " + jspTag.getqName() + " at " +
jspTag.getLineNumber() + " id " + jspTag.getId()
LOG.fine("PROCESSING " + jspTag.getQName() + " at "
+ jspTag.getLineNumber() + " id " + jspTag.getId()
+ ", class: " + jspTag.getTagHandlerClass().getName()
+ ", attrs: " + jspTag.getAttributes());

Expand All @@ -65,44 +71,44 @@ public void nodeEntered(PageNode jspTag) {
contextVarRegistry.extractContextVariables(jspTag, resolvedJsfExpressions);
} catch (MissingLocalVariableTypeDeclarationException e) {
e.setTagLineNumber(jspTag.getLineNumber());
e.setJspFile(jspFile);
e.setJspFile(currentJspFile);
validationResults.reportContextVariableNeedingTypeDeclaration(e);
} catch (InternalValidatorFailureException e) {
e.setExpressionDescriptor(new JsfExpressionDescriptor(jspTag.getLineNumber(), jspFile));
e.setExpressionDescriptor(new JsfExpressionDescriptor(jspTag.getLineNumber(), currentJspFile));
throw e;
}
}

//@Override
/** {@inheritDoc} */
public void nodeLeft(PageNode jspTag) {
LOG.fine("DONE WITH " + jspTag.getId());
contextVarRegistry.discardContextFor(jspTag);
}

//@Override
public void fileEntered(String jspFile) {
setCurrentJspFile(jspFile);
LOG.info(">>> STARTED FOR '" + jspFile + " #############################################");
/** {@inheritDoc} */
public void fileEntered(String newJspFile) {
setCurrentJspFile(newJspFile);
LOG.info(">>> STARTED FOR '" + newJspFile + " #############################################");
}

public CollectedValidationResultsImpl getValidationResults() {
return validationResults;
}

//@Override
/** {@inheritDoc} */
public void includedFileEntered(String includedFileName) {
jspFileInclusionStack.push(jspFile);
jspFileInclusionStack.push(currentJspFile);
setCurrentJspFile(includedFileName);
}

//@Override
/** {@inheritDoc} */
public void includedFileLeft(String includedFileName) {
setCurrentJspFile(jspFileInclusionStack.pop());
}

private void setCurrentJspFile(String jspFile) {
this.jspFile = jspFile;
this.validationResults.setCurrentJspFile(jspFile);
private void setCurrentJspFile(String currentJspFile) {
this.currentJspFile = currentJspFile;
this.validationResults.setCurrentJspFile(currentJspFile);
}

}
Expand Up @@ -25,7 +25,10 @@
*/
public class JspCParsingToNodesOnly extends JspC {

/** Overriden to return the class of ours (default = null => JdtCompiler)*/
/**
* {@inheritDoc}
* Overriden to return the class of ours (default = null => JdtCompiler.
*/
@Override
public String getCompilerClassName() {
return OnlyReadingJspPseudoCompiler.class.getName();
Expand Down
Expand Up @@ -19,6 +19,7 @@

import java.util.Map;

/** Represents a tag in a JSP/JSF page, in other words a node of the page. */
public class PageNode {

private static long counter = 0;
Expand All @@ -29,6 +30,17 @@ public class PageNode {
private final Class<?> tagHandlerClass;
private final int lineNumber;

/**
* Create new page node describing a custom JSP tag.
* @param qName (required)
* qualified name of the tag, ex.: h:dataTable
* @param tagHandlerClass (required)
* the handler used for the tag, ex.: org.apache.myfaces.taglib.html.HtmlDataTableTag
* @param lineNumber (required)
* the line where the tag starts in the page source code
* @param attributeMap (required)
* map with attributes of the tag: name -> value
*/
public PageNode(String qName, Class<?> tagHandlerClass, int lineNumber,
Map<String, String> attributeMap) {
this.qName = qName;
Expand All @@ -41,7 +53,7 @@ public Map<String, String> getAttributes() {
return attributes;
}

public String getqName() {
public String getQName() {
return qName;
}

Expand Down
Expand Up @@ -101,7 +101,7 @@ public Class<?> resolveVariable(String name) {
public void extractContextVariables(PageNode jspTag,
AttributesValidationResult resolvedJsfExpressions) throws MissingLocalVariableTypeDeclarationException {

TagJsfVariableResolver resolverForTag = resolvers.get(jspTag.getqName());
TagJsfVariableResolver resolverForTag = resolvers.get(jspTag.getQName());

if (resolverForTag != null) {
try {
Expand Down
Expand Up @@ -114,11 +114,11 @@ private void appendCurrentPropertyToExpression(final String property) {
* actually is a variable)
* @param property (required) the property name such as 'property' in the EL #{bean.property}
* @return the type of the property or null if it cannot be detected
* @throws EvaluationException
* @throws PropertyNotFoundException
* @throws PropertyNotFoundException there is no such property on the target object
* @throws EvaluationException other problem
*/
private Class<?> getTypeOfCollectionOrBean(Object target, Object property) throws EvaluationException,
PropertyNotFoundException {
public Class<?> getTypeOfCollectionOrBean(Object target, Object property)
throws PropertyNotFoundException, EvaluationException {

// Would normally throw an exception for empty arrays/list not having the given index
if (target.getClass().isArray()) {
Expand Down

0 comments on commit 8738e7f

Please sign in to comment.