AnnotationsChangeTracker extension tests

This commit is contained in:
Eugene Zhuravlev
2016-08-08 23:13:29 +02:00
parent 43018d26ab
commit 42947cdc2a
28 changed files with 343 additions and 0 deletions
@@ -0,0 +1,40 @@
Cleaning output files:
out/production/AnnotationsTracker/D1.class
out/production/AnnotationsTracker/D2.class
out/production/AnnotationsTracker/D3.class
out/production/AnnotationsTracker/D4.class
End of files
Compiling files:
src/D1.java
src/D2.java
src/D3.java
src/D4.java
End of files
Cleaning output files:
out/production/AnnotationsTracker/C1.class
out/production/AnnotationsTracker/C2.class
out/production/AnnotationsTracker/C3.class
out/production/AnnotationsTracker/C4.class
out/production/AnnotationsTracker/D1Sub.class
out/production/AnnotationsTracker/D1Sub2.class
out/production/AnnotationsTracker/D2Sub.class
out/production/AnnotationsTracker/D2Sub2.class
out/production/AnnotationsTracker/D3Sub.class
out/production/AnnotationsTracker/D3Sub2.class
out/production/AnnotationsTracker/D4Sub.class
out/production/AnnotationsTracker/D4Sub2.class
End of files
Compiling files:
src/C1.java
src/C2.java
src/C3.java
src/C4.java
src/D1Sub.java
src/D1Sub2.java
src/D2Sub.java
src/D2Sub2.java
src/D3Sub.java
src/D3Sub2.java
src/D4Sub.java
src/D4Sub2.java
End of files
@@ -0,0 +1,8 @@
public class D1 {
public String field;
public String method (Integer param) {
return param.toString();
}
}
@@ -0,0 +1,8 @@
public class D2 {
public String field;
public String method (Integer param) {
return param.toString();
}
}
@@ -0,0 +1,8 @@
public class D3 {
public String field;
public String method (Integer param) {
return param.toString();
}
}
@@ -0,0 +1,8 @@
public class D4 {
public String field;
public String method (Integer param) {
return param.toString();
}
}
@@ -0,0 +1,4 @@
public class C1 {
void foo(D1 data) {
}
}
@@ -0,0 +1,5 @@
public class C2 {
void foo(D2 data) {
String str = data.field;
}
}
@@ -0,0 +1,5 @@
public class C3 {
void foo(D3 data) {
data.method(new Integer(10));
}
}
@@ -0,0 +1,5 @@
public class C4 {
void foo(D4 data) {
data.method(new Integer(10));
}
}
@@ -0,0 +1,12 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
@MockAnnotation
@MockHierarchyAnnotation
public class D1 {
public String field;
public String method (Integer param) {
return param.toString();
}
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D1Sub extends D1{
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D1Sub2 extends D1Sub{
}
@@ -0,0 +1,12 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D2 {
@MockAnnotation
@MockHierarchyAnnotation
public String field;
public String method (Integer param) {
return param.toString();
}
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D2Sub extends D2{
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D2Sub2 extends D2Sub{
}
@@ -0,0 +1,12 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D3 {
public String field;
@MockAnnotation
@MockHierarchyAnnotation
public String method (Integer param) {
return param.toString();
}
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D3Sub extends D3{
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D3Sub2 extends D3Sub{
}
@@ -0,0 +1,10 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D4 {
public String field;
public String method (@MockAnnotation @MockHierarchyAnnotation Integer param) {
return param.toString();
}
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D4Sub extends D4{
}
@@ -0,0 +1,5 @@
import org.jetbrains.jps.builders.java.dependencyView.MockAnnotation;
import org.jetbrains.jps.builders.java.dependencyView.MockHierarchyAnnotation;
public class D4Sub2 extends D4Sub{
}
@@ -0,0 +1,8 @@
package org.jetbrains.jps.builders.java.dependencyView;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
public @interface MockAnnotation {
}
@@ -0,0 +1,8 @@
package org.jetbrains.jps.builders.java.dependencyView;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
public @interface MockHierarchyAnnotation {
}
@@ -0,0 +1 @@
org.jetbrains.jps.builders.java.dependencyView.MockAnnotationsChangeTracker
@@ -116,4 +116,8 @@ public class AnnotationTest extends IncrementalTestCase {
public void testConservativeNonIncremental1() throws Exception {
doTest();
}
public void testAnnotationsTracker() throws Exception {
doTest();
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jps.builders.java.dependencyView;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
public @interface MockAnnotation {
}
@@ -0,0 +1,99 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Set;
/**
* @author Eugene Zhuravlev
* Date: 08-Aug-16
*/
public class MockAnnotationsChangeTracker extends AnnotationsChangeTracker{
private static final String ANOTATION_NAME = MockAnnotation.class.getName().replace('.', '/');
private static final String HIERARCHY_ANOTATION_NAME = MockHierarchyAnnotation.class.getName().replace('.', '/');
@NotNull
public Set<Recompile> methodAnnotationsChanged(DependencyContext context, MethodRepr method, Difference.Specifier<TypeRepr.ClassType, Difference> annotationsDiff, Difference.Specifier<ParamAnnotation, Difference> paramAnnotationsDiff) {
//return RECOMPILE_NONE;
return handleChanges(context, ContainerUtil.concat(
annotationsDiff.added(),
annotationsDiff.removed(),
toTypeCollection(paramAnnotationsDiff.added()),
toTypeCollection(paramAnnotationsDiff.removed()))
);
}
@NotNull
public Set<Recompile> fieldAnnotationsChanged(DependencyContext context, FieldRepr field, Difference.Specifier<TypeRepr.ClassType, Difference> annotationsDiff) {
//return RECOMPILE_NONE;
return handleChanges(context, ContainerUtil.concat(annotationsDiff.added(), annotationsDiff.removed()));
}
@NotNull
public Set<Recompile> classAnnotationsChanged(DependencyContext context, ClassRepr aClass, Difference.Specifier<TypeRepr.ClassType, Difference> annotationsDiff) {
//return RECOMPILE_NONE;
return handleChanges(context, ContainerUtil.concat(annotationsDiff.added(), annotationsDiff.removed()));
}
@NotNull
public Set<Recompile> handleChanges(DependencyContext context, Iterable<TypeRepr.ClassType> changes) {
final int annot = context.get(ANOTATION_NAME);
final Set<Recompile> result = EnumSet.noneOf(Recompile.class);
if (containsAnnotation(annot, changes)) {
result.add(Recompile.USAGES);
}
final int hierarchyAnnot = context.get(HIERARCHY_ANOTATION_NAME);
if (containsAnnotation(hierarchyAnnot, changes)) {
result.add(Recompile.SUBCLASSES);
}
return result;
}
private static Iterable<TypeRepr.ClassType> toTypeCollection(final Iterable<ParamAnnotation> paramCollection) {
return new Iterable<TypeRepr.ClassType>() {
public Iterator<TypeRepr.ClassType> iterator() {
final Iterator<ParamAnnotation> iterator = paramCollection.iterator();
return new Iterator<TypeRepr.ClassType>() {
public boolean hasNext() {
return iterator.hasNext();
}
public TypeRepr.ClassType next() {
return iterator.next().type;
}
public void remove() {
iterator.remove();
}
};
}
};
}
private static boolean containsAnnotation(int annotationName, Iterable<TypeRepr.ClassType> classes) {
for (TypeRepr.ClassType type : classes) {
if (annotationName == type.className) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jps.builders.java.dependencyView;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
public @interface MockHierarchyAnnotation {
}