Skip to content

Commit

Permalink
HV-1377 Adding a check if the type was already processed
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta authored and gsmet committed Jun 23, 2017
1 parent 657cb07 commit 636a0d6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
Expand Up @@ -11,6 +11,7 @@
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic;
Expand All @@ -33,6 +34,8 @@
*/
public class ClassVisitor extends AbstractElementVisitor<Void, Void> {

private final Set<Name> processedTypes;

private final ClassCheckFactory factory;

private final Elements elementUtils;
Expand All @@ -54,6 +57,8 @@ public ClassVisitor(
)
)
);

this.processedTypes = CollectionHelper.newHashSet();
}

/**
Expand Down Expand Up @@ -101,8 +106,12 @@ public Void visitExecutableAsMethod(ExecutableElement element, Void aVoid) {
* @param typeElement inner elements of which you want to visit
*/
private void visitAllMyElements(TypeElement typeElement) {
for ( Element element : elementUtils.getAllMembers( typeElement ) ) {
visit( element );
Name qualifiedName = typeElement.getQualifiedName();
if ( !processedTypes.contains( qualifiedName ) ) {
processedTypes.add( qualifiedName );
for ( Element element : elementUtils.getAllMembers( typeElement ) ) {
visit( element );
}
}
}

Expand Down
@@ -0,0 +1,32 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.ap;

import static org.testng.Assert.assertTrue;

import org.hibernate.validator.ap.testmodel.circular.CircularProperty;
import org.hibernate.validator.ap.testmodel.circular.CircularPropertyImpl;
import org.testng.annotations.Test;

/**
* Tests that in case of circular nested types there's no infinite loop during analysis.
*
* @author Marko Bekhta
*/
public class CircularNestedTypesTest extends ConstraintValidationProcessorTestBase {

@Test
public void testNoInfiniteLoop() {
boolean compilationResult =
compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics,
compilerHelper.getSourceFile( CircularPropertyImpl.class ),
compilerHelper.getSourceFile( CircularProperty.class )
);

assertTrue( compilationResult );
}
}
@@ -0,0 +1,20 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.ap.testmodel.circular;

/**
* @author Marko Bekhta
*/
public interface CircularProperty {

void doSomething();

interface ImprovedCircularProperty extends CircularProperty {

void maybeDoSomething();
}
}
@@ -0,0 +1,18 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.ap.testmodel.circular;

/**
* @author Marko Bekhta
*/
public class CircularPropertyImpl implements CircularProperty {

@Override
public void doSomething() {
//nothing here
}
}

0 comments on commit 636a0d6

Please sign in to comment.