use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrIntroduceValidatorEngine method validateVariableOccurrencesUp.
private void validateVariableOccurrencesUp(PsiElement startElement, MultiMap<PsiElement, String> conflicts, @NotNull String varName, double startOffset) {
PsiElement prevSibling = startElement.getPrevSibling();
while (prevSibling != null) {
if (!(GroovyRefactoringUtil.isAppropriateContainerForIntroduceVariable(prevSibling) && prevSibling.getTextRange().getEndOffset() < startOffset)) {
validateOccurrencesDown(prevSibling, conflicts, varName, startOffset);
}
prevSibling = prevSibling.getPrevSibling();
}
PsiElement parent = startElement.getParent();
// Do not check context out of method, type definition and directories
if (parent == null || parent instanceof GrMethod || parent instanceof GrTypeDefinition || parent instanceof GroovyFileBase || parent instanceof PsiDirectory) {
return;
}
validateVariableOccurrencesUp(parent, conflicts, varName, startOffset);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition 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.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyRefactoringUtil method getExpressionOccurrences.
public static PsiElement[] getExpressionOccurrences(@NotNull PsiElement expr, @NotNull PsiElement scope) {
ArrayList<PsiElement> occurrences = new ArrayList<>();
Comparator<PsiElement> comparator = (element1, element2) -> {
if (element1 != null && element1.equals(element2))
return 0;
if (element1 instanceof GrParameter && element2 instanceof GrParameter) {
final String name1 = ((GrParameter) element1).getName();
final String name2 = ((GrParameter) element2).getName();
return name1.compareTo(name2);
}
return 1;
};
if (scope instanceof GrLoopStatement) {
PsiElement son = expr;
while (son.getParent() != null && !(son.getParent() instanceof GrLoopStatement)) {
son = son.getParent();
}
assert scope.equals(son.getParent());
collectOccurrences(expr, son, occurrences, comparator, false);
} else {
collectOccurrences(expr, scope, occurrences, comparator, scope instanceof GrTypeDefinition || scope instanceof GroovyFileBase);
}
return PsiUtilCore.toPsiElementArray(occurrences);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class ClassItemGeneratorImpl method collectMethods.
@Override
public Collection<PsiMethod> collectMethods(PsiClass typeDefinition) {
List<PsiMethod> result = ContainerUtil.filter(typeDefinition.getMethods(), m -> !GroovyObjectTransformationSupport.isGroovyObjectSupportMethod(m));
if (typeDefinition instanceof GroovyScriptClass) {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(context.project);
final String name = typeDefinition.getName();
GrTypeDefinition tempClass = factory.createTypeDefinition("class " + name + " extends groovy.lang.Script {\n" + " def " + name + "(groovy.lang.Binding binding){\n" + " super(binding);\n" + " }\n" + " def " + name + "(){\n" + " super();\n" + " }\n" + "}");
ContainerUtil.addAll(result, tempClass.getCodeConstructors());
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrMemberInfoStorage method buildSubClassesMap.
@Override
protected void buildSubClassesMap(PsiClass aClass) {
if (aClass instanceof GrTypeDefinition) {
final GrExtendsClause extendsList = ((GrTypeDefinition) aClass).getExtendsClause();
if (extendsList != null) {
buildSubClassesMapForList(extendsList.getReferencedTypes(), (GrTypeDefinition) aClass);
}
final GrImplementsClause implementsList = ((GrTypeDefinition) aClass).getImplementsClause();
if (implementsList != null) {
buildSubClassesMapForList(implementsList.getReferencedTypes(), (GrTypeDefinition) aClass);
}
}
}
Aggregations