use of com.intellij.codeInsight.folding.JavaCodeFoldingSettings in project intellij-community by JetBrains.
the class JavaFoldingBuilderBase method isRegionCollapsedByDefault.
@Override
protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) {
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node);
JavaCodeFoldingSettings settings = JavaCodeFoldingSettings.getInstance();
if (element instanceof PsiNewExpression || element instanceof PsiJavaToken && element.getParent() instanceof PsiAnonymousClass) {
return settings.isCollapseLambdas();
}
if (element instanceof PsiJavaToken && element.getParent() instanceof PsiCodeBlock && element.getParent().getParent() instanceof PsiMethod) {
return settings.isCollapseOneLineMethods();
}
if (element instanceof PsiReferenceParameterList) {
return settings.isCollapseConstructorGenericParameters();
}
if (element instanceof PsiImportList) {
return settings.isCollapseImports();
} else if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiCodeBlock) {
if (element instanceof PsiMethod) {
if (!settings.isCollapseAccessors() && !settings.isCollapseMethods()) {
return false;
}
if (isSimplePropertyAccessor((PsiMethod) element)) {
return settings.isCollapseAccessors();
}
}
return settings.isCollapseMethods();
} else if (element instanceof PsiAnonymousClass) {
return settings.isCollapseAnonymousClasses();
} else if (element instanceof PsiClass) {
return !(element.getParent() instanceof PsiFile) && settings.isCollapseInnerClasses();
} else if (element instanceof PsiDocComment) {
PsiElement parent = element.getParent();
if (parent instanceof PsiJavaFile) {
if (((PsiJavaFile) parent).getName().equals(PsiPackage.PACKAGE_INFO_FILE)) {
return false;
}
PsiElement firstChild = parent.getFirstChild();
if (firstChild instanceof PsiWhiteSpace) {
firstChild = firstChild.getNextSibling();
}
if (element.equals(firstChild)) {
return settings.isCollapseFileHeader();
}
}
return settings.isCollapseJavadocs();
} else if (element instanceof PsiJavaFile) {
return settings.isCollapseFileHeader();
} else if (element instanceof PsiAnnotation) {
return settings.isCollapseAnnotations();
} else if (element instanceof PsiComment) {
return settings.isCollapseEndOfLineComments();
} else if (element instanceof PsiLambdaExpression) {
return settings.isCollapseAnonymousClasses();
} else {
LOG.error("Unknown element:" + element);
return false;
}
}
use of com.intellij.codeInsight.folding.JavaCodeFoldingSettings in project kotlin by JetBrains.
the class AbstractKotlinFoldingTest method doTestWithSettings.
protected static void doTestWithSettings(@NotNull String fileText, @NotNull Function<String, Void> runnable) {
JavaCodeFoldingSettings settings = JavaCodeFoldingSettings.getInstance();
JavaCodeFoldingSettingsImpl restoreSettings = new JavaCodeFoldingSettingsImpl();
restoreSettings.loadState((JavaCodeFoldingSettingsImpl) settings);
try {
SettingsConfigurator configurator = new SettingsConfigurator(fileText, settings);
configurator.configureSettings();
runnable.apply(fileText);
} finally {
((JavaCodeFoldingSettingsImpl) JavaCodeFoldingSettings.getInstance()).loadState(restoreSettings);
}
}
use of com.intellij.codeInsight.folding.JavaCodeFoldingSettings in project intellij-community by JetBrains.
the class GroovyFoldingBuilder method isRegionCollapsedByDefault.
@Override
protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) {
final JavaCodeFoldingSettings settings = JavaCodeFoldingSettings.getInstance();
if (node.getElementType() == GroovyElementTypes.IMPORT_STATEMENT) {
return settings.isCollapseImports();
}
if (node.getElementType() == GroovyDocElementTypes.GROOVY_DOC_COMMENT || node.getElementType() == GroovyTokenTypes.mML_COMMENT) {
PsiElement element = node.getPsi();
PsiElement parent = element.getParent();
if (parent instanceof GroovyFile) {
PsiElement firstChild = parent.getFirstChild();
if (firstChild instanceof PsiWhiteSpace) {
firstChild = firstChild.getNextSibling();
}
if (element.equals(firstChild)) {
return settings.isCollapseFileHeader();
}
}
if (node.getElementType() == GroovyDocElementTypes.GROOVY_DOC_COMMENT) {
return settings.isCollapseJavadocs();
}
}
if ((node.getElementType() == GroovyElementTypes.OPEN_BLOCK || node.getElementType() == GroovyElementTypes.CONSTRUCTOR_BODY) && node.getTreeParent().getElementType() == GroovyElementTypes.METHOD_DEFINITION) {
return settings.isCollapseMethods();
}
if (node.getElementType() == GroovyElementTypes.CLOSABLE_BLOCK) {
return settings.isCollapseAnonymousClasses();
}
if (node.getElementType() == GroovyElementTypes.CLASS_BODY) {
final PsiElement parent = node.getPsi().getParent();
if (parent instanceof PsiClass) {
if (parent instanceof PsiAnonymousClass) {
return settings.isCollapseAnonymousClasses();
}
if (((PsiClass) parent).getContainingClass() != null) {
return settings.isCollapseInnerClasses();
}
}
}
if (node.getElementType() == GroovyTokenTypes.mSL_COMMENT) {
return settings.isCollapseEndOfLineComments();
}
return false;
}
Aggregations