use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class GenerationUtil method writeDocComment.
static void writeDocComment(StringBuilder buffer, PsiMember member, boolean addLineFeed) {
if (member instanceof PsiDocCommentOwner) {
final PsiDocComment comment = ((PsiDocCommentOwner) member).getDocComment();
if (comment != null) {
final String text = comment.getText();
buffer.append(text);
if (addLineFeed)
buffer.append('\n');
}
}
}
use of com.intellij.psi.javadoc.PsiDocComment 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.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class GroovyMoveClassToInnerHandler method moveClass.
@Override
public PsiClass moveClass(@NotNull PsiClass aClass, @NotNull PsiClass targetClass) {
if (!(aClass instanceof GrTypeDefinition))
return null;
GroovyChangeContextUtil.encodeContextInfo(aClass);
PsiDocComment doc = aClass.getDocComment();
PsiElement brace = targetClass.getRBrace();
PsiClass newClass = (PsiClass) targetClass.addBefore(aClass, brace);
PsiElement sibling = newClass.getPrevSibling();
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(targetClass.getProject());
if (!org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isNewLine(sibling)) {
targetClass.addBefore(factory.createLineTerminator("\n "), newClass);
} else if (doc != null) {
LOG.assertTrue(sibling != null);
sibling.replace(factory.createLineTerminator(sibling.getText() + " "));
}
if (doc != null) {
targetClass.addBefore(doc, newClass);
targetClass.addBefore(factory.createLineTerminator("\n"), newClass);
}
if (targetClass.isInterface()) {
PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
} else {
PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, true);
}
GroovyChangeContextUtil.decodeContextInfo(newClass, null, null);
return newClass;
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class SourceCodeChecker method check.
private static ThreeState check(Location location, SourcePosition position, Project project) {
Method method = DebuggerUtilsEx.getMethod(location);
// for now skip constructors, bridges, lambdas etc.
if (method == null || method.isConstructor() || method.isSynthetic() || method.isBridge() || method.isStaticInitializer() || (method.declaringType() instanceof ClassType && ((ClassType) method.declaringType()).isEnum()) || DebuggerUtilsEx.isLambda(method)) {
return ThreeState.UNSURE;
}
List<Location> locations = DebuggerUtilsEx.allLineLocations(method);
if (ContainerUtil.isEmpty(locations)) {
return ThreeState.UNSURE;
}
if (position != null) {
return ReadAction.compute(() -> {
PsiFile psiFile = position.getFile();
if (!psiFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
// only for java for now
return ThreeState.UNSURE;
}
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
if (document == null) {
return ThreeState.UNSURE;
}
boolean res = false;
PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(position);
if (psiMethod != null) {
TextRange range = psiMethod.getTextRange();
if (psiMethod instanceof PsiDocCommentOwner) {
PsiDocComment comment = ((PsiDocCommentOwner) psiMethod).getDocComment();
if (comment != null) {
range = new TextRange(comment.getTextRange().getEndOffset() + 1, range.getEndOffset());
}
}
int startLine = document.getLineNumber(range.getStartOffset()) + 1;
int endLine = document.getLineNumber(range.getEndOffset()) + 1;
res = getLinesStream(locations, psiFile).allMatch(line -> startLine <= line && line <= endLine);
if (!res) {
LOG.debug("Source check failed: Method " + method.name() + ", source: " + ((NavigationItem) psiMethod).getName() + "\nLines: " + getLinesStream(locations, psiFile).joining(", ") + "\nExpected range: " + startLine + "-" + endLine);
}
} else {
LOG.debug("Source check failed: method " + method.name() + " not found in sources");
}
if (!res) {
FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(position.getFile().getVirtualFile());
if (editor instanceof TextEditor) {
AppUIUtil.invokeOnEdt(() -> HintManager.getInstance().showErrorHint(((TextEditor) editor).getEditor(), DebuggerBundle.message("warning.source.code.not.match")));
} else {
XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("warning.source.code.not.match"), NotificationType.WARNING).notify(project);
}
return ThreeState.NO;
}
return ThreeState.YES;
});
}
return ThreeState.YES;
}
use of com.intellij.psi.javadoc.PsiDocComment in project intellij-community by JetBrains.
the class EncapsulateFieldsProcessor method generateAccessors.
private void generateAccessors() {
// generate accessors
myNameToGetter = new HashMap<>();
myNameToSetter = new HashMap<>();
for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
final DocCommentPolicy<PsiDocComment> commentPolicy = new DocCommentPolicy<>(myDescriptor.getJavadocPolicy());
PsiField field = fieldDescriptor.getField();
final PsiDocComment docComment = field.getDocComment();
if (myDescriptor.isToEncapsulateGet()) {
final PsiMethod prototype = fieldDescriptor.getGetterPrototype();
assert prototype != null;
final PsiMethod getter = addOrChangeAccessor(prototype, myNameToGetter);
if (docComment != null) {
final PsiDocComment getterJavadoc = (PsiDocComment) getter.addBefore(docComment, getter.getFirstChild());
commentPolicy.processNewJavaDoc(getterJavadoc);
}
}
if (myDescriptor.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL)) {
PsiMethod prototype = fieldDescriptor.getSetterPrototype();
assert prototype != null;
addOrChangeAccessor(prototype, myNameToSetter);
}
if (docComment != null) {
commentPolicy.processOldJavaDoc(docComment);
}
}
}
Aggregations