Search in sources :

Example 1 with OCImportSymbolFix

use of com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix in project intellij by bazelbuild.

the class BlazeCppAutoImportHelperTest method stlPathsUnderWorkspaceRoot_importStlHeader.

@Test
public void stlPathsUnderWorkspaceRoot_importStlHeader() {
    ProjectView projectView = projectView(directories("foo/bar"), targets("//foo/bar:bar"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo/bar:bar", Kind.CC_LIBRARY, sources("foo/bar/bar.cc"), sources())).addTarget(createCcTarget("//third_party/stl:stl", Kind.CC_LIBRARY, sources(), sources("third_party/stl/vector.h"))).build();
    // Normally this is <vector> without .h, but we need to trick the file type detector into
    // realizing that this is an OCFile.
    OCFile header = createFile("third_party/stl/vector.h", "namespace std {", "template<typename T> class vector {};", "}");
    OCFile file = createFile("foo/bar/bar.cc", "std::vector<int> my_vector;");
    resolve(projectView, targetMap, file, header);
    testFixture.openFileInEditor(file.getVirtualFile());
    OCReferenceElement referenceElement = testFixture.findElementByText("std::vector<int>", OCReferenceElement.class);
    OCImportSymbolFix fix = new OCImportSymbolFix(referenceElement);
    assertThat(fix.isAvailable(getProject(), testFixture.getEditor(), file)).isTrue();
    assertThat(fix.getAutoImportItems()).hasSize(1);
    assertThat(fix.getAutoImportItems().get(0).getTitleAndLocation().getFirst()).isEqualTo("class 'std::vector'");
    assertThat(fix.getAutoImportItems().get(0).getTitleAndLocation().getSecond()).isEqualTo("<vector.h>");
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) OCReferenceElement(com.jetbrains.cidr.lang.psi.OCReferenceElement) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) OCImportSymbolFix(com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 2 with OCImportSymbolFix

use of com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix in project intellij by bazelbuild.

the class BlazeCppAutoImportHelperTest method differentDirectory_importUserHeader.

@Test
public void differentDirectory_importUserHeader() {
    ProjectView projectView = projectView(directories("foo/bar", "baz"), targets("//foo/bar", "//baz"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo/bar:bar", Kind.CC_LIBRARY, sources("foo/bar/bar.cc"), sources())).addTarget(createCcTarget("//baz:baz", Kind.CC_LIBRARY, sources(""), sources("baz/test.h"))).build();
    OCFile header = createFile("baz/test.h", "class SomeClass {};");
    OCFile file = createFile("foo/bar/bar.cc", "SomeClass* my_class = new SomeClass();");
    resolve(projectView, targetMap, file, header);
    testFixture.openFileInEditor(file.getVirtualFile());
    OCReferenceElement referenceElement = testFixture.findElementByText("SomeClass*", OCReferenceElement.class);
    OCImportSymbolFix fix = new OCImportSymbolFix(referenceElement);
    assertThat(fix.isAvailable(getProject(), testFixture.getEditor(), file)).isTrue();
    assertThat(fix.getAutoImportItems()).hasSize(1);
    assertThat(fix.getAutoImportItems().get(0).getTitleAndLocation().getFirst()).isEqualTo("class 'SomeClass'");
    assertThat(fix.getAutoImportItems().get(0).getTitleAndLocation().getSecond()).isEqualTo("\"baz/test.h\"");
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) OCReferenceElement(com.jetbrains.cidr.lang.psi.OCReferenceElement) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) OCImportSymbolFix(com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 3 with OCImportSymbolFix

use of com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix in project intellij by bazelbuild.

the class BlazeCppAutoImportHelperTest method sameDirectory_importUserHeader.

@Test
public void sameDirectory_importUserHeader() {
    ProjectView projectView = projectView(directories("foo/bar"), targets("//foo/bar:bar"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo/bar:bar", Kind.CC_LIBRARY, sources("foo/bar/bar.cc"), sources("foo/bar/test.h"))).build();
    OCFile header = createFile("foo/bar/test.h", "class SomeClass {};");
    OCFile file = createFile("foo/bar/bar.cc", "SomeClass* my_class = new SomeClass();");
    resolve(projectView, targetMap, file, header);
    testFixture.openFileInEditor(file.getVirtualFile());
    OCReferenceElement referenceElement = testFixture.findElementByText("SomeClass*", OCReferenceElement.class);
    OCImportSymbolFix fix = new OCImportSymbolFix(referenceElement);
    assertThat(fix.isAvailable(getProject(), testFixture.getEditor(), file)).isTrue();
    assertThat(fix.getAutoImportItems()).hasSize(1);
    assertThat(fix.getAutoImportItems().get(0).getTitleAndLocation().getFirst()).isEqualTo("class 'SomeClass'");
    assertThat(fix.getAutoImportItems().get(0).getTitleAndLocation().getSecond()).isEqualTo("\"foo/bar/test.h\"");
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) OCReferenceElement(com.jetbrains.cidr.lang.psi.OCReferenceElement) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) OCImportSymbolFix(com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)3 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)3 OCFile (com.jetbrains.cidr.lang.psi.OCFile)3 OCReferenceElement (com.jetbrains.cidr.lang.psi.OCReferenceElement)3 OCImportSymbolFix (com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix)3 Test (org.junit.Test)3