2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.plugins.groovy.lang.psi
18 import com.intellij.psi.PsiDocumentManager
19 import com.intellij.testFramework.LightProjectDescriptor
20 import groovy.transform.CompileStatic
21 import groovy.transform.TypeCheckingMode
22 import org.jetbrains.plugins.groovy.GroovyLightProjectDescriptor
23 import org.jetbrains.plugins.groovy.LightGroovyTestCase
26 class GroovyModificationTrackersTest extends LightGroovyTestCase {
28 LightProjectDescriptor projectDescriptor = GroovyLightProjectDescriptor.GROOVY_LATEST
30 void 'test class method'() {
38 void 'test class initializer'() {
48 void 'test class body'() {
56 void 'test script body'() {
57 doTest '<caret>', false
60 void 'test script variable'() {
61 doTest 'def a<caret>= 1', true
64 @CompileStatic(TypeCheckingMode.SKIP)
65 void doTest(String text, boolean shouldChange) {
66 fixture.configureByText '_.groovy', text
67 def (beforeStructure, beforeOutOfCodeBlock) = getModificationCounts()
69 PsiDocumentManager.getInstance(project).commitDocument(editor.document)
70 def (afterStructure, afterOutOfCodeBlock) = getModificationCounts()
72 assert beforeStructure < afterStructure
73 assert beforeOutOfCodeBlock < afterOutOfCodeBlock
76 assert beforeStructure == afterStructure
77 assert beforeOutOfCodeBlock == afterOutOfCodeBlock
82 List<Long> getModificationCounts() {
83 psiManager.modificationTracker.with {
84 [javaStructureModificationCount, outOfCodeBlockModificationCount]