Search in sources :

Example 31 with OCFile

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

the class IwyuPragmasTest method singeRange_parseExportBeginEnd.

@Test
public void singeRange_parseExportBeginEnd() {
    OCFile file = createFile("public/foo.h", "/** Stuff */", "// IWYU pragma: begin_exports", "#include <private/memory>", "#include \"private/foo1.h\"", "#include \"private/foo2.h\"", "// IWYU pragma: end_exports", "#include \"private/foo3.h\"");
    IwyuPragmas pragmas = IwyuPragmas.parse(file);
    assertThat(pragmas.exports).containsExactly(ExportPragma.create(IncludePath.create("private/memory", Delimiters.ANGLE_BRACKETS)), ExportPragma.create(IncludePath.create("private/foo1.h", Delimiters.QUOTES)), ExportPragma.create(IncludePath.create("private/foo2.h", Delimiters.QUOTES)));
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) Test(org.junit.Test)

Example 32 with OCFile

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

the class IwyuPragmasTest method parseAssociated.

@Test
public void parseAssociated() {
    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.QUOTES));
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) Test(org.junit.Test)

Example 33 with OCFile

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

the class DelegatingSwitchToHeaderOrSourceProvider method getItems.

@Override
public List<? extends GotoRelatedItem> getItems(PsiElement psiElement) {
    PsiFile psiFile = psiElement.getContainingFile();
    Project project = psiElement.getProject();
    if (!(psiFile instanceof OCFile) || !Blaze.isBlazeProject(project)) {
        return ImmutableList.of();
    }
    OCFile ocFile = (OCFile) psiFile;
    // Try to find the corresponding file quickly. If we can't even figure that out (e.g.,
    // if headers are stored in a different directory) then delegate to the original provider.
    OCFile correspondingFile = SwitchToHeaderOrSourceSearch.getCorrespondingFile(ocFile);
    if (correspondingFile == null) {
        Optional<List<? extends GotoRelatedItem>> fromDelegate = getItemsWithTimeout(() -> DELEGATE.getItems(psiElement));
        if (fromDelegate.isPresent()) {
            return fromDelegate.get();
        }
        logger.info("Timed out without a fallback.");
        return ImmutableList.of();
    }
    return ImmutableList.of(new GotoRelatedItem(correspondingFile, correspondingFile.isHeader() ? "Headers" : "Sources"));
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem)

Example 34 with OCFile

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

the class SwitchToHeaderOrSourceSearch method correlateTestToHeader.

@Nullable
private static OCFile correlateTestToHeader(OCFile file) {
    // Quickly check foo_test.cc -> foo.h as well. "getAssociatedFileWithSameName" only does
    // foo.cc <-> foo.h. However, if you do goto-related-symbol again, it will go from
    // foo.h -> foo.cc instead of back to foo_test.cc.
    PsiManager psiManager = PsiManager.getInstance(file.getProject());
    String pathWithoutExtension = FileUtil.getNameWithoutExtension(file.getVirtualFile().getPath());
    for (String testSuffix : TEST_SUFFIXES) {
        if (pathWithoutExtension.endsWith(testSuffix)) {
            String possibleHeaderName = StringUtil.trimEnd(pathWithoutExtension, testSuffix) + ".h";
            VirtualFile virtualFile = VfsUtil.findFileByIoFile(new File(possibleHeaderName), false);
            if (virtualFile != null) {
                PsiFile psiFile = psiManager.findFile(virtualFile);
                if (psiFile instanceof OCFile) {
                    return (OCFile) psiFile;
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OCFile(com.jetbrains.cidr.lang.psi.OCFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) OCFile(com.jetbrains.cidr.lang.psi.OCFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 35 with OCFile

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

the class BlazeCppSyncStatusFileNodeDecorator method decorate.

@Override
public void decorate(ProjectViewNode node, PresentationData data) {
    if (!(node instanceof PsiFileNode)) {
        return;
    }
    PsiFile psiFile = ((PsiFileNode) node).getValue();
    if (!(psiFile instanceof OCFile)) {
        return;
    }
    VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile == null) {
        return;
    }
    Project project = node.getProject();
    if (SyncStatusHelper.isUnsynced(project, virtualFile)) {
        data.clearText();
        data.addText(psiFile.getName(), SimpleTextAttributes.GRAY_ATTRIBUTES);
        data.addText(" (unsynced)", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
}
Also used : OCFile(com.jetbrains.cidr.lang.psi.OCFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) PsiFile(com.intellij.psi.PsiFile)

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