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.transformations
18 import com.intellij.psi.PsiClass
19 import com.intellij.psi.util.InheritanceUtil
20 import com.intellij.testFramework.LightProjectDescriptor
21 import groovy.transform.CompileStatic
22 import org.jetbrains.plugins.groovy.GroovyLightProjectDescriptor
23 import org.jetbrains.plugins.groovy.LightGroovyTestCase
24 import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl
25 import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass
28 class BaseScriptTransformationSupportTest extends LightGroovyTestCase {
30 LightProjectDescriptor projectDescriptor = GroovyLightProjectDescriptor.GROOVY_LATEST
33 void setUp() throws Exception {
35 fixture.addFileToProject 'base.groovy', 'abstract class MyBaseScript extends Script {}'
38 private void doTest(String text) {
39 def file = fixture.addFileToProject('Zzz.groovy', """\
40 import groovy.transform.BaseScript
43 """) as GroovyFileImpl
44 def clazz = fixture.findClass('Zzz')
45 assert clazz instanceof GroovyScriptClass
46 assert InheritanceUtil.isInheritor(clazz as PsiClass, 'MyBaseScript')
47 assert !file.contentsLoaded
50 void 'test top level'() {
51 doTest '@BaseScript MyBaseScript hello'
54 void 'test script block level'() {
55 doTest 'if (true) @BaseScript MyBaseScript hello'
58 void 'test within method'() {
61 @BaseScript MyBaseScript hello