use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class GroovyStatementMover method getElementToMove.
@Nullable
private static GroovyPsiElement getElementToMove(GroovyFileBase file, int offset) {
offset = CharArrayUtil.shiftForward(file.getText(), offset, " \t");
PsiElement element = file.findElementAt(offset);
final GrDocComment docComment = PsiTreeUtil.getParentOfType(element, GrDocComment.class);
if (docComment != null) {
final GrDocCommentOwner owner = docComment.getOwner();
if (owner != null) {
element = owner;
}
}
if (element instanceof PsiComment) {
element = PsiTreeUtil.nextVisibleLeaf(element);
}
return (GroovyPsiElement) PsiTreeUtil.findFirstParent(element, element11 -> isMoveable(element11));
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class GrAnnotatorImpl method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (FileIndexFacade.getInstance(element.getProject()).isInLibrarySource(element.getContainingFile().getVirtualFile()))
return;
if (element instanceof GroovyPsiElement) {
final GroovyAnnotator annotator = new GroovyAnnotator(holder);
((GroovyPsiElement) element).accept(annotator);
if (PsiUtil.isCompileStatic(element)) {
final GroovyStaticTypeCheckVisitor typeCheckVisitor = myTypeCheckVisitorThreadLocal.get();
assert typeCheckVisitor != null;
typeCheckVisitor.accept((GroovyPsiElement) element, holder);
}
} else if (element instanceof PsiComment) {
String text = element.getText();
if (text.startsWith("/*") && !(text.endsWith("*/"))) {
TextRange range = element.getTextRange();
holder.createErrorAnnotation(TextRange.create(range.getEndOffset() - 1, range.getEndOffset()), GroovyBundle.message("doc.end.expected"));
}
} else {
final PsiElement parent = element.getParent();
if (parent instanceof GrMethod) {
if (element.equals(((GrMethod) parent).getNameIdentifierGroovy()) && ((GrMethod) parent).getReturnTypeElementGroovy() == null) {
GroovyAnnotator.checkMethodReturnType((GrMethod) parent, element, holder);
}
} else if (parent instanceof GrField) {
final GrField field = (GrField) parent;
if (element.equals(field.getNameIdentifierGroovy())) {
final GrAccessorMethod[] getters = field.getGetters();
for (GrAccessorMethod getter : getters) {
GroovyAnnotator.checkMethodReturnType(getter, field.getNameIdentifierGroovy(), holder);
}
final GrAccessorMethod setter = field.getSetter();
if (setter != null) {
GroovyAnnotator.checkMethodReturnType(setter, field.getNameIdentifierGroovy(), holder);
}
}
}
}
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class ChangeToEndOfLineCommentIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final PsiComment comment = (PsiComment) element;
final JavaPsiFacade manager = JavaPsiFacade.getInstance(comment.getProject());
final PsiElement parent = comment.getParent();
assert parent != null;
final PsiElementFactory factory = manager.getElementFactory();
final String commentText = comment.getText();
final PsiElement whitespace = comment.getNextSibling();
final String text = commentText.substring(2, commentText.length() - 2);
final String[] lines = text.split("\n");
for (int i = lines.length - 1; i >= 1; i--) {
final PsiComment nextComment = factory.createCommentFromText("//" + lines[i].trim() + '\n', parent);
parent.addAfter(nextComment, comment);
/* if (whitespace != null) {
final PsiElement newWhiteSpace =
factory.createWhiteSpaceFromText(whitespace.getText());
parent.addAfter(newWhiteSpace, comment);
} */
}
final PsiComment newComment = factory.createCommentFromText("//" + lines[0], parent);
comment.replace(newComment);
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class EndOfLineCommentPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiComment)) {
return false;
}
if (element instanceof PsiDocComment) {
return false;
}
final PsiComment comment = (PsiComment) element;
final IElementType type = comment.getTokenType();
return GroovyTokenTypes.mSL_COMMENT.equals(type);
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class ChangeToCStyleCommentIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final PsiComment selectedComment = (PsiComment) element;
PsiComment firstComment = selectedComment;
while (true) {
final PsiElement prevComment = getPrevNonWhiteSpace(firstComment);
if (!isEndOfLineComment(prevComment)) {
break;
}
firstComment = (PsiComment) prevComment;
}
final JavaPsiFacade manager = JavaPsiFacade.getInstance(selectedComment.getProject());
final PsiElementFactory factory = manager.getElementFactory();
String text = getCommentContents(firstComment);
final List<PsiElement> commentsToDelete = new ArrayList<>();
PsiElement nextComment = firstComment;
while (true) {
nextComment = getNextNonWhiteSpace(nextComment);
if (!isEndOfLineComment(nextComment)) {
break;
}
text += //to get the whitespace for proper spacing
nextComment.getPrevSibling().getText() + " " + getCommentContents((PsiComment) nextComment);
commentsToDelete.add(nextComment);
}
final PsiComment newComment = factory.createCommentFromText("/*" + text + " */", selectedComment.getParent());
firstComment.replace(newComment);
for (PsiElement commentToDelete : commentsToDelete) {
commentToDelete.delete();
}
}
Aggregations