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)));
}
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));
}
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"));
}
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;
}
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);
}
}
Aggregations