Search in sources :

Example 46 with TestOnly

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;
}
Also used : Project(com.intellij.openapi.project.Project) TestOnly(org.jetbrains.annotations.TestOnly) Nullable(org.jetbrains.annotations.Nullable)

Example 47 with TestOnly

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestOnly(org.jetbrains.annotations.TestOnly)

Example 48 with TestOnly

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));
}
Also used : ReferenceQueue(java.lang.ref.ReferenceQueue) SoftReference(java.lang.ref.SoftReference) TestOnly(org.jetbrains.annotations.TestOnly)

Example 49 with TestOnly

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PositionManagerImpl(com.intellij.debugger.engine.PositionManagerImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) SourcePosition(com.intellij.debugger.SourcePosition) NoDataException(com.intellij.debugger.NoDataException) TestOnly(org.jetbrains.annotations.TestOnly)

Example 50 with TestOnly

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);
        });
    });
}
Also used : JavaAwareProjectJdkTableImpl(com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module) TestOnly(org.jetbrains.annotations.TestOnly)

Aggregations

TestOnly (org.jetbrains.annotations.TestOnly)56 Disposable (com.intellij.openapi.Disposable)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)5 Application (com.intellij.openapi.application.Application)4 Document (com.intellij.openapi.editor.Document)3 Editor (com.intellij.openapi.editor.Editor)3 THashSet (gnu.trove.THashSet)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)2 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 CollectionListModel (com.intellij.ui.CollectionListModel)2 THashMap (gnu.trove.THashMap)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 Pass (com.intellij.codeHighlighting.Pass)1 AutoPopupController (com.intellij.codeInsight.AutoPopupController)1 com.intellij.codeInsight.daemon (com.intellij.codeInsight.daemon)1