use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCodeInsightFixtureTestCase method findElementAtCaretOrInSelection.
@NotNull
protected PsiElement findElementAtCaretOrInSelection() {
SelectionModel selectionModel = myFixture.getEditor().getSelectionModel();
if (selectionModel.hasSelection()) {
PsiElement left = myFixture.getFile().findElementAt(selectionModel.getSelectionStart());
PsiElement right = myFixture.getFile().findElementAt(selectionModel.getSelectionEnd() - 1);
assertNotNull(left);
assertNotNull(right);
return ObjectUtils.assertNotNull(PsiTreeUtil.findCommonParent(left, right));
} else {
return ObjectUtils.assertNotNull(myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()));
}
}
use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.
the class GotestGenerateAction method importTestingPackageIfNeeded.
@NotNull
public static String importTestingPackageIfNeeded(@NotNull GoFile file) {
GoImportSpec alreadyImportedPackage = file.getImportedPackagesMap().get(GoConstants.TESTING_PATH);
String qualifier = GoPsiImplUtil.getImportQualifierToUseInFile(alreadyImportedPackage, GoConstants.TESTING_PATH);
if (qualifier != null) {
return qualifier;
}
String localName = UniqueNameGenerator.generateUniqueName(GoConstants.TESTING_PATH, file.getImportMap().keySet());
file.addImport(GoConstants.TESTING_PATH, !GoConstants.TESTING_PATH.equals(localName) ? localName : null);
return localName;
}
use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPackageUtil method getAllPackageFiles.
@NotNull
public static List<GoFile> getAllPackageFiles(@NotNull GoFile file) {
String packageName = file.getPackageName();
PsiDirectory parent = file.getParent();
if (parent == null || StringUtil.isEmpty(packageName))
return ContainerUtil.list(file);
return getAllPackageFiles(parent, packageName);
}
use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPackageUtil method getAllPackagesInDirectory.
@NotNull
public static Collection<String> getAllPackagesInDirectory(@Nullable PsiDirectory dir, @Nullable Module contextModule, boolean trimTestSuffices) {
if (dir == null)
return Collections.emptyList();
if (contextModule != null) {
return getAllPackagesInDirectoryInner(dir, contextModule, trimTestSuffices);
}
Key<CachedValue<Collection<String>>> key = trimTestSuffices ? PACKAGES_TEST_TRIMMED_CACHE : PACKAGES_CACHE;
return CachedValuesManager.getManager(dir.getProject()).getCachedValue(dir, key, () -> {
Module module = ModuleUtilCore.findModuleForPsiElement(dir);
GoBuildTargetSettings buildTargetSettings = module != null ? GoModuleSettings.getInstance(module).getBuildTargetSettings() : null;
// todo[zolotov]: implement package modification tracker
return buildTargetSettings != null ? CachedValueProvider.Result.create(getAllPackagesInDirectoryInner(dir, module, trimTestSuffices), dir, buildTargetSettings) : CachedValueProvider.Result.create(getAllPackagesInDirectoryInner(dir, null, trimTestSuffices), dir);
}, false);
}
use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPerformanceTest method testParserAndStubs.
public void testParserAndStubs() {
File go = new File(getTestDataPath(), "go");
if (!go.exists()) {
System.err.println("For performance tests you need to have a go sources (https://storage.googleapis.com/golang/go1.4.2.src.tar.gz) inside testData/" + getBasePath() + " directory");
return;
}
PlatformTestUtil.startPerformanceTest(getTestName(true), (int) TimeUnit.MINUTES.toMillis(1), () -> {
VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(go);
assertNotNull(root);
VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile file) {
if (file.isDirectory() && "testdata".equals(file.getName()))
return SKIP_CHILDREN;
if (file.isDirectory() && "test".equals(file.getName()) && file.getParent().equals(root))
return SKIP_CHILDREN;
if (file.getFileType() != GoFileType.INSTANCE)
return CONTINUE;
try {
System.out.print(".");
buildStubTreeText(getProject(), file, FileUtil.loadFile(new File(file.getPath()), "UTF-8", true).trim(), true);
} catch (IOException ignored) {
}
return CONTINUE;
}
});
}).usesAllCPUCores().assertTiming();
}
Aggregations