refactoring-tests is out of dependency cycle

This commit is contained in:
Dmitry Jemerov
2011-12-16 17:43:21 +01:00
parent 66f5e6d3f2
commit 905b9726dc
3 changed files with 897 additions and 0 deletions
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.mock;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.util.IncorrectOperationException;
import com.intellij.lang.Language;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
*/
public class MockPsiDirectory extends MockPsiElement implements PsiDirectory {
private final PsiPackage myPackage;
public MockPsiDirectory(final PsiPackage aPackage, @NotNull Disposable parentDisposable) {
super(parentDisposable);
myPackage = aPackage;
}
@Override
public boolean isDirectory() {
return true;
}
@NotNull
@Override
public Language getLanguage() {
return Language.ANY;
}
@Override
public void checkCreateFile(@NotNull final String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Method checkCreateFile is not yet implemented in " + getClass().getName());
}
@Override
public void checkCreateSubdirectory(@NotNull final String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Method checkCreateSubdirectory is not yet implemented in " + getClass().getName());
}
@Override
public PsiDirectory getParent() {
return getParentDirectory();
}
@Override
@NotNull
public PsiFile createFile(@NotNull final String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Method createFile is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public PsiFile copyFileFrom(@NotNull final String newName, @NotNull final PsiFile originalFile) throws IncorrectOperationException {
throw new IncorrectOperationException("Method copyFileFrom is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public PsiDirectory createSubdirectory(@NotNull final String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Method createSubdirectory is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiFile findFile(@NotNull @NonNls final String name) {
throw new UnsupportedOperationException("Method findFile is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiDirectory findSubdirectory(@NotNull final String name) {
throw new UnsupportedOperationException("Method findSubdirectory is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public PsiFile[] getFiles() {
throw new UnsupportedOperationException("Method getFiles is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public String getName() {
throw new UnsupportedOperationException("Method getName is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiDirectory getParentDirectory() {
final PsiPackage psiPackage = myPackage.getParentPackage();
return psiPackage == null ? null : new MockPsiDirectory(psiPackage, getProject());
}
@Override
@NotNull
public PsiDirectory[] getSubdirectories() {
throw new UnsupportedOperationException("Method getSubdirectories is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public VirtualFile getVirtualFile() {
throw new UnsupportedOperationException("Method getVirtualFile is not yet implemented in " + getClass().getName());
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
throw new UnsupportedOperationException("Method processChildren is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public PsiElement setName(@NotNull final String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Method setName is not yet implemented in " + getClass().getName());
}
@Override
public void checkSetName(final String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Method checkSetName is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public ItemPresentation getPresentation() {
throw new UnsupportedOperationException("Method getPresentation is not yet implemented in " + getClass().getName());
}
}
@@ -0,0 +1,378 @@
/*
* Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.mock;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.pom.Navigatable;
import com.intellij.psi.*;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.List;
/**
* @author peter
*/
public class MockPsiElement extends UserDataHolderBase implements PsiElement, Navigatable {
private final String myText;
private final Project myProject;
private final List<PsiElement> myDeclarations = new SmartList<PsiElement>();
private Ref<PsiElement> myParent;
private PsiManager myManager;
public MockPsiElement(@NotNull Disposable parentDisposable) {
this(null, new MockProjectEx(parentDisposable));
}
private MockPsiElement(final String text, @NotNull Project project) {
myText = text;
myProject = project;
}
@Override
public void navigate(boolean requestFocus) {
throw new UnsupportedOperationException("Method navigate is not yet implemented in " + getClass().getName());
}
@Override
public boolean canNavigate() {
throw new UnsupportedOperationException("Method canNavigate is not yet implemented in " + getClass().getName());
}
@Override
public boolean canNavigateToSource() {
throw new UnsupportedOperationException("Method canNavigateToSource is not yet implemented in " + getClass().getName());
}
public List<PsiElement> getDeclarations() {
return myDeclarations;
}
@Override
public void accept(@NotNull final PsiElementVisitor visitor) {
throw new UnsupportedOperationException("Method accept is not yet implemented in " + getClass().getName());
}
@Override
public void acceptChildren(@NotNull final PsiElementVisitor visitor) {
throw new UnsupportedOperationException("Method acceptChildren is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement add(@NotNull final PsiElement element) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method add is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement addAfter(@NotNull final PsiElement element, final PsiElement anchor) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method addAfter is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement addBefore(@NotNull final PsiElement element, final PsiElement anchor) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method addBefore is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement addRange(final PsiElement first, final PsiElement last) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method addRange is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement addRangeAfter(final PsiElement first, final PsiElement last, final PsiElement anchor) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method addRangeAfter is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement addRangeBefore(@NotNull final PsiElement first, @NotNull final PsiElement last, final PsiElement anchor) throws
IncorrectOperationException {
throw new UnsupportedOperationException("Method addRangeBefore is not yet implemented in " + getClass().getName());
}
@Override
public void checkAdd(@NotNull final PsiElement element) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method checkAdd is not yet implemented in " + getClass().getName());
}
@Override
public void checkDelete() throws IncorrectOperationException {
throw new UnsupportedOperationException("Method checkDelete is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement copy() {
throw new UnsupportedOperationException("Method copy is not yet implemented in " + getClass().getName());
}
@Override
public void delete() throws IncorrectOperationException {
throw new UnsupportedOperationException("Method delete is not yet implemented in " + getClass().getName());
}
@Override
public void deleteChildRange(final PsiElement first, final PsiElement last) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method deleteChildRange is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiElement findElementAt(final int offset) {
throw new UnsupportedOperationException("Method findElementAt is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiReference findReferenceAt(final int offset) {
throw new UnsupportedOperationException("Method findReferenceAt is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public PsiElement[] getChildren() {
throw new UnsupportedOperationException("Method getChildren is not yet implemented in " + getClass().getName());
}
@Override
public PsiFile getContainingFile() throws PsiInvalidElementAccessException {
throw new UnsupportedOperationException("Method getContainingFile is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiElement getContext() {
return getParent();
}
@Override
@Nullable
public <T> T getCopyableUserData(final Key<T> key) {
throw new UnsupportedOperationException("Method getCopyableUserData is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiElement getFirstChild() {
throw new UnsupportedOperationException("Method getFirstChild is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public Language getLanguage() {
throw new UnsupportedOperationException("Method getLanguage is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiElement getLastChild() {
throw new UnsupportedOperationException("Method getLastChild is not yet implemented in " + getClass().getName());
}
@Override
public PsiManager getManager() {
return myManager;
}
public void setManager(final PsiManager manager) {
myManager = manager;
}
@Override
public PsiElement getNavigationElement() {
throw new UnsupportedOperationException("Method getNavigationElement is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public PsiElement getNextSibling() {
throw new UnsupportedOperationException("Method getNextSibling is not yet implemented in " + getClass().getName());
}
@Override
@Nullable
public ASTNode getNode() {
throw new UnsupportedOperationException("Method getNode is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement getOriginalElement() {
throw new UnsupportedOperationException("Method getOriginalElement is not yet implemented in " + getClass().getName());
}
public void setParent(PsiElement parent) {
myParent = Ref.create(parent);
}
@Override
public PsiElement getParent() {
if (myParent == null) {
throw new UnsupportedOperationException("Method getParent is not yet implemented in " + getClass().getName());
}
return myParent.get();
}
@Override
@Nullable
public PsiElement getPrevSibling() {
throw new UnsupportedOperationException("Method getPrevSibling is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public Project getProject() {
return myProject;
}
@Override
@Nullable
public PsiReference getReference() {
throw new UnsupportedOperationException("Method getReference is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public PsiReference[] getReferences() {
throw new UnsupportedOperationException("Method getReferences is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public GlobalSearchScope getResolveScope() {
throw new UnsupportedOperationException("Method getResolveScope is not yet implemented in " + getClass().getName());
}
@Override
public int getStartOffsetInParent() {
throw new UnsupportedOperationException("Method getStartOffsetInParent is not yet implemented in " + getClass().getName());
}
@Override
@NonNls
public String getText() {
return myText;
}
@Override
public int getTextLength() {
return myText.length();
}
@Override
public int getTextOffset() {
return getTextRange().getStartOffset();
}
@Override
public TextRange getTextRange() {
throw new UnsupportedOperationException("Method getTextRange is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public SearchScope getUseScope() {
throw new UnsupportedOperationException("Method getUseScope is not yet implemented in " + getClass().getName());
}
@Override
public boolean isPhysical() {
return false;
}
@Override
public boolean isValid() {
return true;
}
@Override
public boolean isWritable() {
throw new UnsupportedOperationException("Method isWritable is not yet implemented in " + getClass().getName());
}
@Nullable
protected <T extends PsiNamedElement> T findDeclaration(String name, Class<T> aClass) {
for (final PsiElement declaration : myDeclarations) {
if (declaration instanceof PsiNamedElement) {
final PsiNamedElement psiNamedElement = (PsiNamedElement)declaration;
if (name.equals(psiNamedElement.getName()) && aClass.isInstance(psiNamedElement)) {
return (T)psiNamedElement;
}
}
}
return null;
}
public void addDeclaration(PsiElement declaration) {
if (myDeclarations.contains(declaration)) {
myDeclarations.remove(declaration);
}
else if (declaration instanceof PsiNamedElement) {
myDeclarations.remove(findDeclaration(((PsiNamedElement)declaration).getName(), ((PsiNamedElement)declaration).getClass()));
}
myDeclarations.add(declaration);
}
@Override
public boolean processDeclarations(@NotNull final PsiScopeProcessor processor,
@NotNull final ResolveState state, final PsiElement lastParent, @NotNull final PsiElement place) {
for (final PsiElement declaration : myDeclarations) {
if (!processor.execute(declaration, state)) return false;
}
return true;
}
@Override
public <T> void putCopyableUserData(final Key<T> key, final T value) {
throw new UnsupportedOperationException("Method putCopyableUserData is not yet implemented in " + getClass().getName());
}
@Override
public PsiElement replace(@NotNull final PsiElement newElement) throws IncorrectOperationException {
throw new UnsupportedOperationException("Method replace is not yet implemented in " + getClass().getName());
}
@Override
public boolean textContains(final char c) {
throw new UnsupportedOperationException("Method textContains is not yet implemented in " + getClass().getName());
}
@Override
public boolean textMatches(@NotNull final PsiElement element) {
throw new UnsupportedOperationException("Method textMatches is not yet implemented in " + getClass().getName());
}
@Override
public boolean textMatches(@NotNull final CharSequence text) {
throw new UnsupportedOperationException("Method textMatches is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public char[] textToCharArray() {
throw new UnsupportedOperationException("Method textToCharArray is not yet implemented in " + getClass().getName());
}
@Override
public Icon getIcon(final int flags) {
return null;
}
@Override
public boolean isEquivalentTo(final PsiElement another) {
return this == another;
}
}
@@ -0,0 +1,382 @@
package com.intellij.mock;
import com.intellij.lang.FileASTNode;
import com.intellij.lang.Language;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.psi.search.SearchScope;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.LocalTimeCounter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class MockPsiFile extends MockPsiElement implements PsiFile {
private final long myModStamp = LocalTimeCounter.currentTime();
private VirtualFile myVirtualFile = null;
public boolean valid = true;
public String text = "";
private final FileViewProvider myFileViewProvider;
private final PsiManager myPsiManager;
public MockPsiFile(@NotNull PsiManager psiManager) {
super(psiManager.getProject());
myPsiManager = psiManager;
myFileViewProvider = new SingleRootFileViewProvider(getManager(), new LightVirtualFile("noname", getFileType(), ""));
}
public MockPsiFile(@NotNull VirtualFile virtualFile, @NotNull PsiManager psiManager) {
super(psiManager.getProject());
myPsiManager = psiManager;
myVirtualFile = virtualFile;
myFileViewProvider = new SingleRootFileViewProvider(getManager(), virtualFile);
}
@Override
public VirtualFile getVirtualFile() {
return myVirtualFile;
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
return true;
}
@Override
@NotNull
public String getName() {
return "mock.file";
}
@Override
@Nullable
public ItemPresentation getPresentation() {
return null;
}
@Override
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Not implemented");
}
@Override
public void checkSetName(String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Not implemented");
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public PsiDirectory getContainingDirectory() {
return null;
}
@Nullable
public PsiDirectory getParentDirectory() {
throw new UnsupportedOperationException("Method getParentDirectory is not yet implemented in " + getClass().getName());
}
@Override
public long getModificationStamp() {
return myModStamp;
}
@Override
@NotNull
public PsiFile getOriginalFile() {
return this;
}
@Override
@NotNull
public FileType getFileType() {
return StdFileTypes.JAVA;
}
@Override
@NotNull
public Language getLanguage() {
return StdFileTypes.JAVA.getLanguage();
}
@Override
@NotNull
public PsiFile[] getPsiRoots() {
return new PsiFile[]{this};
}
@Override
@NotNull
public FileViewProvider getViewProvider() {
return myFileViewProvider;
}
@Override
public PsiManager getManager() {
return myPsiManager;
}
@Override
@NotNull
public PsiElement[] getChildren() {
return PsiElement.EMPTY_ARRAY;
}
@Override
public PsiDirectory getParent() {
return null;
}
@Override
public PsiElement getFirstChild() {
return null;
}
@Override
public PsiElement getLastChild() {
return null;
}
@Override
public void acceptChildren(@NotNull PsiElementVisitor visitor) {
}
@Override
public PsiElement getNextSibling() {
return null;
}
@Override
public PsiElement getPrevSibling() {
return null;
}
@Override
public PsiFile getContainingFile() {
return null;
}
@Override
public TextRange getTextRange() {
return null;
}
@Override
public int getStartOffsetInParent() {
return 0;
}
@Override
public int getTextLength() {
return 0;
}
@Override
public PsiElement findElementAt(int offset) {
return null;
}
@Override
public PsiReference findReferenceAt(int offset) {
return null;
}
@Override
public int getTextOffset() {
return 0;
}
@Override
public String getText() {
return text;
}
@Override
@NotNull
public char[] textToCharArray() {
return ArrayUtil.EMPTY_CHAR_ARRAY;
}
@Override
public boolean textMatches(@NotNull CharSequence text) {
return false;
}
@Override
public boolean textMatches(@NotNull PsiElement element) {
return false;
}
@Override
public boolean textContains(char c) {
return false;
}
@Override
public void accept(@NotNull PsiElementVisitor visitor) {
}
@Override
public PsiElement copy() {
return null;
}
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
return null;
}
@Override
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
return null;
}
@Override
public PsiElement addAfter(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
return null;
}
@Override
public void checkAdd(@NotNull PsiElement element) throws IncorrectOperationException {
}
@Override
public PsiElement addRange(PsiElement first, PsiElement last) throws IncorrectOperationException {
return null;
}
@Override
public PsiElement addRangeBefore(@NotNull PsiElement first, @NotNull PsiElement last, PsiElement anchor)
throws IncorrectOperationException {
return null;
}
@Override
public PsiElement addRangeAfter(PsiElement first, PsiElement last, PsiElement anchor)
throws IncorrectOperationException {
return null;
}
@Override
public void delete() throws IncorrectOperationException {
}
@Override
public void checkDelete() throws IncorrectOperationException {
}
@Override
public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException {
}
@Override
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
return null;
}
@Override
public boolean isValid() {
return valid;
}
@Override
public boolean isWritable() {
return false;
}
@Override
public PsiReference getReference() {
return null;
}
@Override
@NotNull
public PsiReference[] getReferences() {
return PsiReference.EMPTY_ARRAY;
}
@Override
public <T> T getCopyableUserData(Key<T> key) {
return null;
}
@Override
public <T> void putCopyableUserData(Key<T> key, T value) {
}
@Override
@NotNull
public Project getProject() {
final PsiManager manager = getManager();
if (manager == null) throw new PsiInvalidElementAccessException(this);
return manager.getProject();
}
@Override
public boolean isPhysical() {
return true;
}
@Override
public PsiElement getNavigationElement() {
return this;
}
@Override
public PsiElement getOriginalElement() {
return this;
}
@Override
@NotNull
public GlobalSearchScope getResolveScope() {
return GlobalSearchScope.EMPTY_SCOPE;
}
@Override
@NotNull
public SearchScope getUseScope() {
return GlobalSearchScope.EMPTY_SCOPE;
}
@Override
public FileASTNode getNode() {
return null;
}
@Override
public void subtreeChanged() {
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public PsiElement getContext() {
return FileContextUtil.getFileContext(this);
}
}