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;
}
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();
}
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);
}
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);
}
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;
}
}
}
Aggregations