diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker.log b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker.log new file mode 100644 index 000000000000..a5583b532040 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker.log @@ -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 \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D1.java.new b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D1.java.new new file mode 100644 index 000000000000..64ff895b23a1 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D1.java.new @@ -0,0 +1,8 @@ + +public class D1 { + public String field; + + public String method (Integer param) { + return param.toString(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D2.java.new b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D2.java.new new file mode 100644 index 000000000000..69ee85bef618 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D2.java.new @@ -0,0 +1,8 @@ + +public class D2 { + public String field; + + public String method (Integer param) { + return param.toString(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D3.java.new b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D3.java.new new file mode 100644 index 000000000000..0bc75d1b9eee --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D3.java.new @@ -0,0 +1,8 @@ + +public class D3 { + public String field; + + public String method (Integer param) { + return param.toString(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D4.java.new b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D4.java.new new file mode 100644 index 000000000000..f754900e811d --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/D4.java.new @@ -0,0 +1,8 @@ + +public class D4 { + public String field; + + public String method (Integer param) { + return param.toString(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C1.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C1.java new file mode 100644 index 000000000000..fa747d2e7140 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C1.java @@ -0,0 +1,4 @@ +public class C1 { + void foo(D1 data) { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C2.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C2.java new file mode 100644 index 000000000000..0d224e00c3f2 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C2.java @@ -0,0 +1,5 @@ +public class C2 { + void foo(D2 data) { + String str = data.field; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C3.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C3.java new file mode 100644 index 000000000000..a728982d7b56 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C3.java @@ -0,0 +1,5 @@ +public class C3 { + void foo(D3 data) { + data.method(new Integer(10)); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C4.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C4.java new file mode 100644 index 000000000000..f7a3ebc0375c --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/C4.java @@ -0,0 +1,5 @@ +public class C4 { + void foo(D4 data) { + data.method(new Integer(10)); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1.java new file mode 100644 index 000000000000..4fba932c3d94 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1.java @@ -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(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1Sub.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1Sub.java new file mode 100644 index 000000000000..d51623c5db8b --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1Sub.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1Sub2.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1Sub2.java new file mode 100644 index 000000000000..f6c1412d4392 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D1Sub2.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2.java new file mode 100644 index 000000000000..56348d1573b6 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2.java @@ -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(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2Sub.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2Sub.java new file mode 100644 index 000000000000..f0e3f9e72a2e --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2Sub.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2Sub2.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2Sub2.java new file mode 100644 index 000000000000..1f5e27a12c1c --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D2Sub2.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3.java new file mode 100644 index 000000000000..a8f1d4dd9f5c --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3.java @@ -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(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3Sub.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3Sub.java new file mode 100644 index 000000000000..e4469a270762 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3Sub.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3Sub2.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3Sub2.java new file mode 100644 index 000000000000..44bcbd0cb35a --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D3Sub2.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4.java new file mode 100644 index 000000000000..bed51b7254c3 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4.java @@ -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(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4Sub.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4Sub.java new file mode 100644 index 000000000000..1f70d45f5ee6 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4Sub.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4Sub2.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4Sub2.java new file mode 100644 index 000000000000..5181611183e4 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/D4Sub2.java @@ -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{ +} \ No newline at end of file diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/org/jetbrains/jps/builders/java/dependencyView/MockAnnotation.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/org/jetbrains/jps/builders/java/dependencyView/MockAnnotation.java new file mode 100644 index 000000000000..b1891689f572 --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/org/jetbrains/jps/builders/java/dependencyView/MockAnnotation.java @@ -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 { +} diff --git a/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/org/jetbrains/jps/builders/java/dependencyView/MockHierarchyAnnotation.java b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/org/jetbrains/jps/builders/java/dependencyView/MockHierarchyAnnotation.java new file mode 100644 index 000000000000..2895f52b4b6c --- /dev/null +++ b/java/java-tests/testData/compileServer/incremental/annotations/annotationsTracker/src/org/jetbrains/jps/builders/java/dependencyView/MockHierarchyAnnotation.java @@ -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 { +} diff --git a/jps/jps-builders/testSrc/META-INF/services/org.jetbrains.jps.builders.java.dependencyView.AnnotationsChangeTracker b/jps/jps-builders/testSrc/META-INF/services/org.jetbrains.jps.builders.java.dependencyView.AnnotationsChangeTracker new file mode 100644 index 000000000000..7dbd802b5aae --- /dev/null +++ b/jps/jps-builders/testSrc/META-INF/services/org.jetbrains.jps.builders.java.dependencyView.AnnotationsChangeTracker @@ -0,0 +1 @@ +org.jetbrains.jps.builders.java.dependencyView.MockAnnotationsChangeTracker \ No newline at end of file diff --git a/jps/jps-builders/testSrc/org/jetbrains/ether/AnnotationTest.java b/jps/jps-builders/testSrc/org/jetbrains/ether/AnnotationTest.java index 7343b863793b..d80044107f0f 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/ether/AnnotationTest.java +++ b/jps/jps-builders/testSrc/org/jetbrains/ether/AnnotationTest.java @@ -116,4 +116,8 @@ public class AnnotationTest extends IncrementalTestCase { public void testConservativeNonIncremental1() throws Exception { doTest(); } + + public void testAnnotationsTracker() throws Exception { + doTest(); + } } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockAnnotation.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockAnnotation.java new file mode 100644 index 000000000000..c92980e5176f --- /dev/null +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockAnnotation.java @@ -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 { +} diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockAnnotationsChangeTracker.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockAnnotationsChangeTracker.java new file mode 100644 index 000000000000..3fb206bca7bf --- /dev/null +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockAnnotationsChangeTracker.java @@ -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 methodAnnotationsChanged(DependencyContext context, MethodRepr method, Difference.Specifier annotationsDiff, Difference.Specifier paramAnnotationsDiff) { + //return RECOMPILE_NONE; + return handleChanges(context, ContainerUtil.concat( + annotationsDiff.added(), + annotationsDiff.removed(), + toTypeCollection(paramAnnotationsDiff.added()), + toTypeCollection(paramAnnotationsDiff.removed())) + ); + } + + @NotNull + public Set fieldAnnotationsChanged(DependencyContext context, FieldRepr field, Difference.Specifier annotationsDiff) { + //return RECOMPILE_NONE; + return handleChanges(context, ContainerUtil.concat(annotationsDiff.added(), annotationsDiff.removed())); + } + + @NotNull + public Set classAnnotationsChanged(DependencyContext context, ClassRepr aClass, Difference.Specifier annotationsDiff) { + //return RECOMPILE_NONE; + return handleChanges(context, ContainerUtil.concat(annotationsDiff.added(), annotationsDiff.removed())); + } + + @NotNull + public Set handleChanges(DependencyContext context, Iterable changes) { + final int annot = context.get(ANOTATION_NAME); + final Set 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 toTypeCollection(final Iterable paramCollection) { + return new Iterable() { + public Iterator iterator() { + final Iterator iterator = paramCollection.iterator(); + return new Iterator() { + 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 classes) { + for (TypeRepr.ClassType type : classes) { + if (annotationName == type.className) { + return true; + } + } + return false; + } +} diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockHierarchyAnnotation.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockHierarchyAnnotation.java new file mode 100644 index 000000000000..594ee7c0d01b --- /dev/null +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/java/dependencyView/MockHierarchyAnnotation.java @@ -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 { +}