Search in sources :

Example 16 with OCFile

use of com.jetbrains.cidr.lang.psi.OCFile 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 17 with OCFile

use of com.jetbrains.cidr.lang.psi.OCFile 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)

Example 18 with OCFile

use of com.jetbrains.cidr.lang.psi.OCFile in project intellij by bazelbuild.

the class BlazeCppIntegrationTestCase method createFile.

protected OCFile createFile(String relativePath, String... contentLines) {
    PsiFile file = workspace.createPsiFile(new WorkspacePath(relativePath), contentLines);
    assertThat(file).isInstanceOf(OCFile.class);
    return (OCFile) file;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) OCFile(com.jetbrains.cidr.lang.psi.OCFile) PsiFile(com.intellij.psi.PsiFile)

Example 19 with OCFile

use of com.jetbrains.cidr.lang.psi.OCFile in project intellij by bazelbuild.

the class IwyuPragmasTest method parseAssociatedAngle.

@Test
public void parseAssociatedAngle() {
    OCFile file = createFile("implementation.cc", "#include <some/interface.h> // IWYU pragma: associated", "", "#include \"other_stuff.h\"");
    IwyuPragmas pragmas = IwyuPragmas.parse(file);
    assertThat(pragmas.associatedHeader.isPresent()).isTrue();
    assertThat(pragmas.associatedHeader.get()).isEqualTo(IncludePath.create("some/interface.h", Delimiters.ANGLE_BRACKETS));
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) Test(org.junit.Test)

Example 20 with OCFile

use of com.jetbrains.cidr.lang.psi.OCFile in project intellij by bazelbuild.

the class IwyuPragmasTest method incompletePath_parse.

@Test
public void incompletePath_parse() {
    OCFile file = createFile("bar.cc", "#include <memory>", "#include <vecto");
    IwyuPragmas pragmas = IwyuPragmas.parse(file);
    assertThat(pragmas.keeps).isEmpty();
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) Test(org.junit.Test)

Aggregations

OCFile (com.jetbrains.cidr.lang.psi.OCFile)35 Test (org.junit.Test)28 PrivatePragma (com.google.idea.blaze.cpp.includes.IwyuPragmas.PrivatePragma)8 PsiFile (com.intellij.psi.PsiFile)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)3 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)3 Project (com.intellij.openapi.project.Project)3 OCReferenceElement (com.jetbrains.cidr.lang.psi.OCReferenceElement)3 OCImportSymbolFix (com.jetbrains.cidr.lang.quickfixes.OCImportSymbolFix)3 ImmutableList (com.google.common.collect.ImmutableList)2 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)1 Couple (com.intellij.openapi.util.Couple)1