KT-3729 Quick documentation support

#KT-3729 Fixed
This commit is contained in:
Nikolay Krasko
2013-07-04 20:48:26 +04:00
parent c8f79e1966
commit 141c544775
11 changed files with 247 additions and 16 deletions
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2013 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.jet.editor.quickDoc;
import com.intellij.codeInsight.documentation.DocumentationManager;
import com.intellij.codeInsight.navigation.CtrlMouseHandler;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.InTextDirectivesUtils;
import org.jetbrains.jet.plugin.ProjectDescriptorWithStdlibSources;
import java.util.List;
public abstract class AbstractJetQuickDocProviderTest extends LightCodeInsightFixtureTestCase {
public void doTest(@NotNull String path) throws Exception {
myFixture.configureByFile(path);
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
assertNotNull("Can't find element at caret in file: " + path, element);
DocumentationManager documentationManager = DocumentationManager.getInstance(myFixture.getProject());
PsiElement targetElement = documentationManager.findTargetElement(myFixture.getEditor(), myFixture.getFile());
List<String> directives = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.getFile().getText(), "INFO:");
assertTrue("Documentation to check should be added to test file with // INFO: directive " + path, 1 == directives.size());
assertEquals(directives.get(0), CtrlMouseHandler.getInfo(targetElement, element));
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ProjectDescriptorWithStdlibSources.INSTANCE;
}
}
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2013 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.jet.editor.quickDoc;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.editor.quickDoc.AbstractJetQuickDocProviderTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/editor/quickDoc")
public class JetQuickDocProviderTestGenerated extends AbstractJetQuickDocProviderTest {
public void testAllFilesPresentInQuickDoc() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/editor/quickDoc"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("MethodFromStdLib.kt")
public void testMethodFromStdLib() throws Exception {
doTest("idea/testData/editor/quickDoc/MethodFromStdLib.kt");
}
@TestMetadata("OnClassDeclarationWithNoPackage.kt")
public void testOnClassDeclarationWithNoPackage() throws Exception {
doTest("idea/testData/editor/quickDoc/OnClassDeclarationWithNoPackage.kt");
}
@TestMetadata("OnFunctionDeclarationWithPackage.kt")
public void testOnFunctionDeclarationWithPackage() throws Exception {
doTest("idea/testData/editor/quickDoc/OnFunctionDeclarationWithPackage.kt");
}
@TestMetadata("OnMethodUsage.kt")
public void testOnMethodUsage() throws Exception {
doTest("idea/testData/editor/quickDoc/OnMethodUsage.kt");
}
}