Search in sources :

Example 11 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class FileBasedIndexImpl method cleanupForNextTest.

@TestOnly
public void cleanupForNextTest() {
    myChangedFilesCollector.ensureUpToDate();
    myTransactionMap = SmartFMap.emptyMap();
    IndexConfiguration state = getState();
    for (ID<?, ?> indexId : state.getIndexIDs()) {
        final MapReduceIndex index = (MapReduceIndex) state.getIndex(indexId);
        assert index != null;
        final MemoryIndexStorage memStorage = (MemoryIndexStorage) index.getStorage();
        index.getWriteLock().lock();
        try {
            memStorage.clearCaches();
        } finally {
            index.getWriteLock().unlock();
        }
    }
}
Also used : MapReduceIndex(com.intellij.util.indexing.impl.MapReduceIndex) TestOnly(org.jetbrains.annotations.TestOnly)

Example 12 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class ProjectTypeStep method availableTemplateGroupsToString.

@TestOnly
public String availableTemplateGroupsToString() {
    ListModel model = myProjectTypeList.getModel();
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < model.getSize(); i++) {
        if (builder.length() > 0) {
            builder.append(", ");
        }
        builder.append(((TemplatesGroup) model.getElementAt(i)).getName());
    }
    return builder.toString();
}
Also used : CollectionListModel(com.intellij.ui.CollectionListModel) TestOnly(org.jetbrains.annotations.TestOnly)

Example 13 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class ComponentManagerImpl method registerComponentInstance.

@SuppressWarnings("unchecked")
@TestOnly
public synchronized <T> T registerComponentInstance(@NotNull Class<T> componentKey, @NotNull T componentImplementation) {
    MutablePicoContainer picoContainer = getPicoContainer();
    ComponentAdapter adapter = picoContainer.getComponentAdapter(componentKey);
    LOG.assertTrue(adapter instanceof ComponentConfigComponentAdapter);
    ComponentConfigComponentAdapter componentAdapter = (ComponentConfigComponentAdapter) adapter;
    Object oldInstance = componentAdapter.myInitializedComponentInstance;
    // we don't update pluginId - method is test only
    componentAdapter.myInitializedComponentInstance = componentImplementation;
    return (T) oldInstance;
}
Also used : CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter) TestOnly(org.jetbrains.annotations.TestOnly)

Example 14 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class JavaProjectCodeInsightSettings method setExcludedNames.

@TestOnly
public static void setExcludedNames(Project project, Disposable parentDisposable, String... excludes) {
    final JavaProjectCodeInsightSettings instance = getSettings(project);
    assert instance.excludedNames.isEmpty();
    instance.excludedNames = Arrays.asList(excludes);
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            instance.excludedNames = ContainerUtil.newArrayList();
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly)

Example 15 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class JavaSdkImpl method createMockJdk.

@NotNull
@TestOnly
public Sdk createMockJdk(@NotNull String jdkName, @NotNull String home, boolean isJre) {
    String homePath = home.replace(File.separatorChar, '/');
    File jdkHomeFile = new File(homePath);
    ProjectRootContainerImpl rootContainer = new ProjectRootContainerImpl(true);
    SdkModificator sdkModificator = new SdkModificator() {

        @Override
        public String getName() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setName(String name) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getHomePath() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setHomePath(String path) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getVersionString() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setVersionString(String versionString) {
            throw new UnsupportedOperationException();
        }

        @Override
        public SdkAdditionalData getSdkAdditionalData() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setSdkAdditionalData(SdkAdditionalData data) {
            throw new UnsupportedOperationException();
        }

        @Override
        public VirtualFile[] getRoots(OrderRootType rootType) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void removeRoot(VirtualFile root, OrderRootType rootType) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void removeRoots(OrderRootType rootType) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void removeAllRoots() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void commitChanges() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isWritable() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void addRoot(VirtualFile root, OrderRootType rootType) {
            rootContainer.addRoot(root, rootType);
        }
    };
    rootContainer.startChange();
    addClasses(jdkHomeFile, sdkModificator, isJre);
    addSources(jdkHomeFile, sdkModificator);
    rootContainer.finishChange();
    ProjectJdkImpl jdk = new ProjectJdkImpl(jdkName, this, homePath, jdkName) {

        @Override
        public void setName(@NotNull String name) {
            throwReadOnly();
        }

        @Override
        public void readExternal(@NotNull Element element) {
            throwReadOnly();
        }

        @Override
        public void readExternal(@NotNull Element element, @Nullable ProjectJdkTable projectJdkTable) {
            throwReadOnly();
        }

        @NotNull
        @Override
        public SdkModificator getSdkModificator() {
            throwReadOnly();
            return null;
        }

        @Override
        public void setSdkAdditionalData(SdkAdditionalData data) {
            throwReadOnly();
        }

        @Override
        public void addRoot(VirtualFile root, OrderRootType rootType) {
            throwReadOnly();
        }

        @Override
        public void removeRoot(VirtualFile root, OrderRootType rootType) {
            throwReadOnly();
        }

        @Override
        public void removeRoots(OrderRootType rootType) {
            throwReadOnly();
        }

        @Override
        public void removeAllRoots() {
            throwReadOnly();
        }

        @Override
        public boolean isWritable() {
            return false;
        }

        @Override
        public void update() {
            throwReadOnly();
        }

        @Override
        public VirtualFile[] getRoots(OrderRootType rootType) {
            return rootContainer.getRootFiles(rootType);
        }

        @NotNull
        @Override
        public RootProvider getRootProvider() {
            return new RootProvider() {

                @NotNull
                @Override
                public String[] getUrls(@NotNull OrderRootType rootType) {
                    return ContainerUtil.map2Array(getFiles(rootType), String.class, VirtualFile::getUrl);
                }

                @NotNull
                @Override
                public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
                    return getRoots(rootType);
                }

                @Override
                public void addRootSetChangedListener(@NotNull RootSetChangedListener listener) {
                }

                @Override
                public void addRootSetChangedListener(@NotNull RootSetChangedListener listener, @NotNull Disposable parentDisposable) {
                }

                @Override
                public void removeRootSetChangedListener(@NotNull RootSetChangedListener listener) {
                }
            };
        }

        private void throwReadOnly() {
            throw new IncorrectOperationException("Can't modify, MockJDK is read-only, consider calling .clone() first");
        }
    };
    ProjectJdkImpl.copyRoots(rootContainer, jdk);
    return jdk;
}
Also used : Disposable(com.intellij.openapi.Disposable) Element(org.jdom.Element) NotNull(org.jetbrains.annotations.NotNull) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) OrderRootType(com.intellij.openapi.roots.OrderRootType) AnnotationOrderRootType(com.intellij.openapi.roots.AnnotationOrderRootType) RootProvider(com.intellij.openapi.roots.RootProvider) IncorrectOperationException(com.intellij.util.IncorrectOperationException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) TestOnly(org.jetbrains.annotations.TestOnly) NotNull(org.jetbrains.annotations.NotNull)

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