use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner in project intellij-community by JetBrains.
the class GroovyMembersWithDocSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
final GrDocCommentOwner owner;
final GrDocComment doc;
if (e instanceof GrDocComment) {
doc = (GrDocComment) e;
owner = GrDocCommentUtil.findDocOwner(doc);
} else {
owner = (GrDocCommentOwner) e;
doc = GrDocCommentUtil.findDocComment(owner);
}
if (doc == null || owner == null)
return Collections.emptyList();
final TextRange range = new TextRange(doc.getTextRange().getStartOffset(), owner.getTextRange().getEndOffset());
return ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, range, true);
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner in project intellij-community by JetBrains.
the class GroovyLineMarkerProvider method getLineMarkerInfo.
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
final PsiElement parent = element.getParent();
if (parent instanceof PsiNameIdentifierOwner) {
if (parent instanceof GrField && element == ((GrField) parent).getNameIdentifierGroovy()) {
for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors((GrField) parent)) {
MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superSignature != null) {
PsiMethod superMethod = superSignature.getMethod();
boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superMethod.hasModifierProperty(PsiModifier.ABSTRACT) || superMethod.getBody() != null && GrTraitUtil.isTrait(superMethod.getContainingClass());
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
final MarkerType type = GroovyMarkerTypes.OVERRIDING_PROPERTY_TYPE;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
} else if (parent instanceof GrMethod && element == ((GrMethod) parent).getNameIdentifierGroovy() && hasSuperMethods((GrMethod) element.getParent())) {
final Icon icon = AllIcons.Gutter.OverridingMethod;
final MarkerType type = GroovyMarkerTypes.GR_OVERRIDING_METHOD;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
//need to draw method separator above docComment
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
PsiElement element1 = element;
boolean isMember = false;
while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
element1 = element1.getParent();
if (element1 instanceof PsiMember || element1 instanceof GrVariableDeclarationImpl) {
isMember = true;
break;
}
}
if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) {
PsiFile file = element1.getContainingFile();
Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file);
boolean drawSeparator = false;
if (document != null) {
CharSequence documentChars = document.getCharsSequence();
int category = getGroovyCategory(element1, documentChars);
for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
int category1 = getGroovyCategory(child, documentChars);
if (category1 == 0)
continue;
drawSeparator = category != 1 || category1 != 1;
break;
}
}
if (drawSeparator) {
GrDocComment comment = null;
if (element1 instanceof GrDocCommentOwner) {
comment = ((GrDocCommentOwner) element1).getDocComment();
}
LineMarkerInfo info = new LineMarkerInfo<>(element, comment != null ? comment.getTextRange() : element.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner in project intellij-community by JetBrains.
the class MoveGroovyClassHandler method doMoveClass.
@Override
public PsiClass doMoveClass(@NotNull PsiClass aClass, @NotNull PsiDirectory moveDestination) throws IncorrectOperationException {
if (!aClass.getLanguage().equals(GroovyLanguage.INSTANCE))
return null;
PsiFile file = aClass.getContainingFile();
if (!(file instanceof GroovyFile))
return null;
final PsiPackage newPackage = JavaDirectoryService.getInstance().getPackage(moveDestination);
LOG.assertTrue(newPackage != null);
PsiClass newClass = null;
final String newPackageName = newPackage.getQualifiedName();
if (aClass instanceof GroovyScriptClass) {
final PsiClass[] classes = ((GroovyFile) file).getClasses();
if (classes.length == 1) {
if (!moveDestination.equals(file.getContainingDirectory())) {
Project project = file.getProject();
MoveFilesOrDirectoriesUtil.doMoveFile(file, moveDestination);
DumbService.getInstance(project).completeJustSubmittedTasks();
file = moveDestination.findFile(file.getName());
assert file != null;
((PsiClassOwner) file).setPackageName(newPackageName);
}
return ((GroovyFile) file).getScriptClass();
}
//script class is moved the first from the file due to MoveClassOrPackageProcessor:88 (element sort)
correctSelfReferences(aClass, newPackage);
final GroovyFile newFile = generateNewScript((GroovyFile) file, newPackage);
for (PsiElement child : file.getChildren()) {
if (!(child instanceof GrTopStatement || child instanceof PsiComment))
continue;
if (child instanceof PsiClass || child instanceof GrImportStatement || child instanceof GrPackageDefinition)
continue;
if (child instanceof GrDocComment) {
final GrDocCommentOwner owner = GrDocCommentUtil.findDocOwner((GrDocComment) child);
if (owner instanceof PsiClass)
continue;
}
child.delete();
}
if (!moveDestination.equals(file.getContainingDirectory())) {
moveDestination.add(newFile);
//aClass.getManager().moveFile(newFile, moveDestination);
}
newClass = newFile.getClasses()[0];
correctOldClassReferences(newClass, aClass);
} else {
if (!moveDestination.equals(file.getContainingDirectory()) && moveDestination.findFile(file.getName()) != null) {
// moving second of two classes which were in the same file to a different directory (IDEADEV-3089)
correctSelfReferences(aClass, newPackage);
PsiFile newFile = moveDestination.findFile(file.getName());
final FileASTNode fileNode = newFile.getNode();
fileNode.addChild(Factory.createSingleLeafElement(GroovyTokenTypes.mNLS, "\n\n", 0, 2, null, aClass.getManager()));
final PsiDocComment docComment = aClass.getDocComment();
if (docComment != null) {
newFile.add(docComment);
fileNode.addChild(Factory.createSingleLeafElement(GroovyTokenTypes.mNLS, "\n", 0, 1, null, aClass.getManager()));
}
newClass = (GrTypeDefinition) newFile.add(aClass);
correctOldClassReferences(newClass, aClass);
aClass.delete();
} else if (((GroovyFile) file).getClasses().length > 1) {
correctSelfReferences(aClass, newPackage);
Project project = aClass.getProject();
PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);
GroovyFile newFile = (GroovyFile) moveDestination.add(fileFactory.createFileFromText(aClass.getName() + "." + GroovyFileType.DEFAULT_EXTENSION, GroovyLanguage.INSTANCE, "class XXX {}"));
final PsiClass created = newFile.getClasses()[0];
PsiDocComment docComment = aClass.getDocComment();
if (docComment != null) {
newFile.addBefore(docComment, created);
docComment.delete();
}
newClass = (PsiClass) created.replace(aClass);
setPackageDefinition((GroovyFile) file, newFile, newPackageName);
correctOldClassReferences(newClass, aClass);
aClass.delete();
}
}
return newClass;
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner in project intellij-community by JetBrains.
the class GroovyDocumentationProvider method generateDocumentationContentStub.
@Override
public String generateDocumentationContentStub(PsiComment contextComment) {
if (!(contextComment instanceof GrDocComment)) {
return null;
}
final GrDocCommentOwner owner = GrDocCommentUtil.findDocOwner((GrDocComment) contextComment);
if (owner == null)
return null;
Project project = contextComment.getProject();
final CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter) LanguageCommenters.INSTANCE.forLanguage(owner.getLanguage());
StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
if (owner instanceof GrMethod) {
final GrMethod method = (GrMethod) owner;
JavaDocumentationProvider.generateParametersTakingDocFromSuperMethods(project, builder, commenter, method);
final PsiType returnType = method.getInferredReturnType();
if ((returnType != null || method.getModifierList().hasModifierProperty(GrModifier.DEF)) && !PsiType.VOID.equals(returnType)) {
builder.append(CodeDocumentationUtil.createDocCommentLine(RETURN_TAG, project, commenter));
builder.append(LINE_SEPARATOR);
}
final PsiClassType[] references = method.getThrowsList().getReferencedTypes();
for (PsiClassType reference : references) {
builder.append(CodeDocumentationUtil.createDocCommentLine(THROWS_TAG, project, commenter));
builder.append(reference.getClassName());
builder.append(LINE_SEPARATOR);
}
} else if (owner instanceof GrTypeDefinition) {
final PsiTypeParameterList typeParameterList = ((PsiClass) owner).getTypeParameterList();
if (typeParameterList != null) {
JavaDocumentationProvider.createTypeParamsListComment(builder, project, commenter, typeParameterList);
}
}
return builder.length() > 0 ? builder.toString() : null;
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner in project intellij-community by JetBrains.
the class GroovySuppressableInspectionTool method getElementToolSuppressedIn.
@Nullable
public static PsiElement getElementToolSuppressedIn(final PsiElement place, @NotNull String toolId) {
if (place == null)
return null;
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
final PsiElement statement = PsiUtil.findEnclosingStatement(place);
if (statement != null) {
PsiElement prev = statement.getPrevSibling();
while (prev != null && StringUtil.isEmpty(prev.getText().trim())) {
prev = prev.getPrevSibling();
}
if (prev instanceof PsiComment) {
String text = prev.getText();
Matcher matcher = SuppressionUtil.SUPPRESS_IN_LINE_COMMENT_PATTERN.matcher(text);
if (matcher.matches() && SuppressionUtil.isInspectionToolIdMentioned(matcher.group(1), toolId)) {
return prev;
}
}
}
GrMember member = null;
GrDocComment docComment = PsiTreeUtil.getParentOfType(place, GrDocComment.class);
if (docComment != null) {
GrDocCommentOwner owner = docComment.getOwner();
if (owner instanceof GrMember) {
member = (GrMember) owner;
}
}
if (member == null) {
member = PsiTreeUtil.getNonStrictParentOfType(place, GrMember.class);
}
while (member != null) {
GrModifierList modifierList = member.getModifierList();
for (String ids : getInspectionIdsSuppressedInAnnotation(modifierList)) {
if (SuppressionUtil.isInspectionToolIdMentioned(ids, toolId)) {
return modifierList;
}
}
member = PsiTreeUtil.getParentOfType(member, GrMember.class);
}
return null;
} finally {
accessToken.finish();
}
}
Aggregations