2 * Copyright 2000-2007 JetBrains s.r.o.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 package org.jetbrains.plugins.groovy.lang.resolve;
19 import com.intellij.openapi.util.text.StringUtil;
20 import com.intellij.openapi.vfs.VfsUtil;
21 import com.intellij.openapi.vfs.VirtualFile;
22 import com.intellij.psi.PsiReference;
23 import org.jetbrains.annotations.NonNls;
24 import org.jetbrains.annotations.Nullable;
25 import org.jetbrains.plugins.groovy.LightGroovyTestCase;
28 import java.io.IOException;
33 public abstract class GroovyResolveTestCase extends LightGroovyTestCase {
34 @NonNls protected static final String MARKER = "<ref>";
37 protected void setUp() throws Exception {
39 if (new File(myFixture.getTestDataPath() + "/" + getTestName(true)).exists()) {
40 myFixture.copyDirectoryToProject(getTestName(true), "");
44 protected PsiReference configureByFile(@NonNls String filePath, @Nullable String newFilePath) throws IOException {
45 filePath = StringUtil.trimStart(filePath, getTestName(true) + "/");
46 final VirtualFile vFile = myFixture.getTempDirFixture().getFile(filePath);
47 assertNotNull("file " + filePath + " not found", vFile);
49 String fileText = StringUtil.convertLineSeparators(VfsUtil.loadText(vFile));
51 int offset = fileText.indexOf(MARKER);
52 assertTrue(offset >= 0);
53 fileText = fileText.substring(0, offset) + fileText.substring(offset + MARKER.length());
55 if (newFilePath == null) {
56 myFixture.configureByText(vFile.getName(), fileText);
59 myFixture.configureByText(newFilePath, fileText);
62 PsiReference ref = myFixture.getFile().findReferenceAt(offset);
67 protected PsiReference configureByFile(@NonNls String filePath) throws Exception {
68 return configureByFile(filePath, null);