blob: 85dc750aadb44007cbe0cdeb59d3ffcabb5d9af2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 xored software, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* xored software, Inc. - initial API and Implementation (Vladimir Belov)
*******************************************************************************/
package org.eclipse.dltk.javascript.formatter.internal.nodes;
import org.eclipse.dltk.formatter.IFormatterDocument;
import org.eclipse.dltk.javascript.ast.JSNode;
import org.eclipse.dltk.javascript.ast.ReturnStatement;
import org.eclipse.dltk.javascript.formatter.JavaScriptFormatterConstants;
public class ArrayBracketsConfiguration implements IBracketsConfiguration,
IPunctuationConfiguration {
private IFormatterDocument document;
private final JSNode node;
public ArrayBracketsConfiguration(IFormatterDocument document, JSNode node) {
this.document = document;
this.node = node;
}
protected IFormatterDocument getDocument() {
return this.document;
}
public boolean isBeginLineBreaking() {
if (!canBreak()) {
return false;
}
String value = document
.getString(JavaScriptFormatterConstants.BRACE_ARRAY);
return JavaScriptFormatterConstants.BRACE_NEXT_LINE.equals(value)
|| JavaScriptFormatterConstants.BRACE_NEXT_LINE_INDENTED
.equals(value);
}
private boolean canBreak() {
if (node.getParent() instanceof ReturnStatement) {
return false;
}
return true;
}
public boolean isBracketsIndenting() {
return JavaScriptFormatterConstants.BRACE_NEXT_LINE_INDENTED
.equals(document
.getString(JavaScriptFormatterConstants.BRACE_ARRAY));
}
public boolean isEndLineBreaking() {
return false;
}
public boolean isIndenting() {
String value = document
.getString(JavaScriptFormatterConstants.BRACE_ARRAY);
return JavaScriptFormatterConstants.BRACE_NEXT_LINE.equals(value)
|| JavaScriptFormatterConstants.BRACE_NEXT_LINE_INDENTED
.equals(value);
}
public boolean insertSpaceAfter() {
// TODO introduce option for it?
return true;
}
public boolean insertSpaceBefore() {
// TODO introduce option for it?
return false;
}
}