Search in sources :

Example 81 with PsiElement

use of com.intellij.psi.PsiElement in project qi4j-sdk by Qi4j.

the class CreateConcernOfInPackageAction method isAvailable.

@Override
protected final boolean isAvailable(DataContext dataContext) {
    boolean isAvailable = super.isAvailable(dataContext);
    if (!isAvailable) {
        return false;
    }
    PsiElement psiElement = PSI_ELEMENT.getData(dataContext);
    if (psiElement == null) {
        return false;
    }
    GlobalSearchScope searchScope = determineSearchScope(psiElement);
    if (searchScope == null) {
        return false;
    }
    Project project = PROJECT.getData(dataContext);
    PsiClass psiClass = getConcernOfClass(project, searchScope);
    return psiClass != null;
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement)

Example 82 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-plugins by StepicOrg.

the class AbstractMoveHandlerDelegate method doMove.

@Override
public void doMove(Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
    List<PsiFileSystemItem> sources = Arrays.stream(elements).filter(psiElement -> isNotMovableOrRenameElement(psiElement, acceptableClasses)).map(ProjectPsiFilesUtils::getFile).filter(Objects::nonNull).collect(Collectors.toList());
    StringBuilder message = new StringBuilder();
    if (sources.size() > 1) {
        message.append("You can not move the following elements:");
    } else {
        PsiFileSystemItem source = sources.get(0);
        message.append("You can not move the ").append(source.isDirectory() ? "directory" : "file").append(":");
    }
    for (PsiFileSystemItem file : sources) {
        message.append("\n").append(file.getVirtualFile().getPath());
    }
    MessagesEx.error(project, message.toString(), "Move").showNow();
}
Also used : MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) Arrays(java.util.Arrays) ProjectPsiFilesUtils.isNotMovableOrRenameElement(org.stepik.plugin.utils.ProjectPsiFilesUtils.isNotMovableOrRenameElement) MoveCallback(com.intellij.refactoring.move.MoveCallback) MessagesEx(com.intellij.openapi.ui.ex.MessagesEx) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils.isCanNotBeTarget(org.stepik.plugin.utils.ProjectPsiFilesUtils.isCanNotBeTarget) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils)

Example 83 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GroovyEditorTextProvider method getEditorText.

@Override
public TextWithImports getEditorText(PsiElement elementAtCaret) {
    String result = "";
    PsiElement element = findExpressionInner(elementAtCaret, true);
    if (element != null) {
        if (element instanceof GrReferenceExpression) {
            final GrReferenceExpression reference = (GrReferenceExpression) element;
            if (reference.getQualifier() == null) {
                final PsiElement resolved = reference.resolve();
                if (resolved instanceof PsiEnumConstant) {
                    final PsiEnumConstant enumConstant = (PsiEnumConstant) resolved;
                    final PsiClass enumClass = enumConstant.getContainingClass();
                    if (enumClass != null) {
                        result = enumClass.getName() + "." + enumConstant.getName();
                    }
                }
            }
        }
        if (result.isEmpty()) {
            result = element.getText();
        }
    }
    return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, result);
}
Also used : PsiEnumConstant(com.intellij.psi.PsiEnumConstant) PsiClass(com.intellij.psi.PsiClass) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 84 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GroovyPositionManager method findReferenceTypeSourceImage.

@Nullable
private static GroovyPsiElement findReferenceTypeSourceImage(SourcePosition position) {
    PsiFile file = position.getFile();
    if (!(file instanceof GroovyFileBase))
        return null;
    PsiElement element = file.findElementAt(position.getOffset());
    if (element == null)
        return null;
    return PsiTreeUtil.getParentOfType(element, GrClosableBlock.class, GrTypeDefinition.class);
}
Also used : GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 85 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GroovyStatementMover method nlsAfter.

private static boolean nlsAfter(@Nullable PsiElement element) {
    if (element == null)
        return false;
    PsiElement sibling = element;
    while (true) {
        sibling = PsiTreeUtil.nextLeaf(sibling);
        if (sibling == null) {
            //eof
            return true;
        }
        final String text = sibling.getText();
        if (text.contains("\n")) {
            return text.charAt(CharArrayUtil.shiftForward(text, 0, " \t")) == '\n';
        }
        if (!(sibling instanceof PsiComment) && !StringUtil.isEmptyOrSpaces(text) && !text.equals(";")) {
            return false;
        }
    }
}
Also used : PsiComment(com.intellij.psi.PsiComment) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3198 Nullable (org.jetbrains.annotations.Nullable)493 PsiFile (com.intellij.psi.PsiFile)474 NotNull (org.jetbrains.annotations.NotNull)442 TextRange (com.intellij.openapi.util.TextRange)239 PsiReference (com.intellij.psi.PsiReference)227 Project (com.intellij.openapi.project.Project)222 VirtualFile (com.intellij.openapi.vfs.VirtualFile)210 ArrayList (java.util.ArrayList)195 ASTNode (com.intellij.lang.ASTNode)142 XmlTag (com.intellij.psi.xml.XmlTag)134 PsiClass (com.intellij.psi.PsiClass)115 Editor (com.intellij.openapi.editor.Editor)112 Document (com.intellij.openapi.editor.Document)109 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)85 PsiDirectory (com.intellij.psi.PsiDirectory)80 IElementType (com.intellij.psi.tree.IElementType)78 Module (com.intellij.openapi.module.Module)77 PsiMethod (com.intellij.psi.PsiMethod)73 UsageInfo (com.intellij.usageView.UsageInfo)70