use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class CtrlMouseHandler method getInfo.
@Nullable
@TestOnly
public static String getInfo(@NotNull Editor editor, BrowseMode browseMode) {
Project project = editor.getProject();
if (project == null)
return null;
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null)
return null;
Info info = getInfoAt(project, editor, file, editor.getCaretModel().getOffset(), browseMode);
return info == null ? null : info.getInfo().text;
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class SmartPointerManagerImpl method getPointersNumber.
@TestOnly
public int getPointersNumber(@NotNull PsiFile containingFile) {
VirtualFile file = containingFile.getViewProvider().getVirtualFile();
SmartPointerTracker pointers = getTracker(file);
return pointers == null ? 0 : pointers.getSize();
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class GCUtil method tryGcSoftlyReachableObjects.
/**
* Try to force VM to collect soft references if possible.
* Method doesn't guarantee to succeed, and should not be used in the production code.
* Commits / hours optimized method code: 5 / 3
*/
@TestOnly
public static void tryGcSoftlyReachableObjects() {
//long started = System.nanoTime();
ReferenceQueue<Object> q = new ReferenceQueue<Object>();
SoftReference<Object> ref = new SoftReference<Object>(new Object(), q);
ArrayList<SoftReference<?>> list = ContainerUtil.newArrayListWithCapacity(100 + useReference(ref));
System.gc();
final long freeMemory = Runtime.getRuntime().freeMemory();
for (int i = 0; i < 100; i++) {
if (q.poll() != null) {
break;
}
// full gc is caused by allocation of large enough array below, SoftReference will be cleared after two full gc
int bytes = Math.min((int) (freeMemory * 0.45), Integer.MAX_VALUE / 2);
list.add(new SoftReference<Object>(new byte[bytes]));
}
// use ref is important as to loop to finish with several iterations: long runs of the method (~80 run of PsiModificationTrackerTest)
// discovered 'ref' being collected and loop iterated 100 times taking a lot of time
list.ensureCapacity(list.size() + useReference(ref));
// do not leave a chance for our created SoftReference's content to lie around until next full GC's
for (SoftReference createdReference : list) createdReference.clear();
//System.out.println("Done gc'ing refs:" + ((System.nanoTime() - started) / 1000000));
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class SourceCodeChecker method checkAllClasses.
@TestOnly
@SuppressWarnings("UseOfSystemOutOrSystemErr")
private static void checkAllClasses(DebuggerContextImpl debuggerContext) {
DebugProcessImpl process = debuggerContext.getDebugProcess();
@SuppressWarnings("ConstantConditions") VirtualMachine machine = process.getVirtualMachineProxy().getVirtualMachine();
// only default position manager for now
PositionManagerImpl positionManager = new PositionManagerImpl(process);
List<ReferenceType> types = machine.allClasses();
System.out.println("Checking " + types.size() + " classes");
int i = 0;
for (ReferenceType type : types) {
i++;
try {
for (Location loc : type.allLineLocations()) {
SourcePosition position = ReadAction.compute(() -> {
try {
return positionManager.getSourcePosition(loc);
} catch (NoDataException ignore) {
return null;
}
});
if (position == null) {
continue;
}
if (position.getFile() instanceof PsiCompiledFile) {
VirtualFile file = position.getFile().getVirtualFile();
if (file == null || file.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY) == null) {
// no mapping - skip the whole file
break;
}
if (DebuggerUtilsEx.bytecodeToSourceLine(position.getFile(), loc.lineNumber()) == -1) {
continue;
}
}
if (check(loc, position, process.getProject()) == ThreeState.NO) {
System.out.println("failed " + type);
break;
}
}
} catch (AbsentInformationException ignored) {
}
}
System.out.println("Done checking");
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class CompilerTestUtil method disableExternalCompiler.
@TestOnly
public static void disableExternalCompiler(@NotNull final Project project) {
EdtTestUtil.runInEdtAndWait(() -> {
final JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
ApplicationManager.getApplication().runWriteAction(() -> {
Sdk internalJdk = table.getInternalJdk();
List<Module> modulesToRestore = new SmartList<>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null && sdk.equals(internalJdk)) {
modulesToRestore.add(module);
}
}
table.removeJdk(internalJdk);
for (Module module : modulesToRestore) {
ModuleRootModificationUtil.setModuleSdk(module, internalJdk);
}
BuildManager.getInstance().clearState(project);
});
});
}
Aggregations