本文整理汇总了Java中org.netbeans.modules.editor.indent.spi.CodeStylePreferences类的典型用法代码示例。如果您正苦于以下问题:Java CodeStylePreferences类的具体用法?Java CodeStylePreferences怎么用?Java CodeStylePreferences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeStylePreferences类属于org.netbeans.modules.editor.indent.spi包,在下文中一共展示了CodeStylePreferences类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTabInsertString
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
/** @deprecated
* @see Formatter.insertTabString()
*/
public static String getTabInsertString(BaseDocument doc, int offset)
throws BadLocationException {
int col = getVisualColumn(doc, offset);
Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
boolean expandTabs = prefs.getBoolean(SimpleValueNames.EXPAND_TABS, EditorPreferencesDefaults.defaultExpandTabs);
if (expandTabs) {
int spacesPerTab = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
if (spacesPerTab <= 0) {
return ""; //NOI18N
}
int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
return new String(Analyzer.getSpacesBuffer(len), 0, len);
} else { // insert pure tab
return "\t"; // NOI18N
}
}
示例2: checkSetIndentation
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
private void checkSetIndentation(String before, int indent, String after, boolean indentWithTabs) throws Exception {
int offset = before.indexOf('^');
// Must indicate caret pos!
assertTrue(offset != -1);
before = before.substring(0, offset) + before.substring(offset + 1);
BaseDocument doc = getDocument(before);
if (indentWithTabs) {
CodeStylePreferences.get(doc).getPreferences().putBoolean(SimpleValueNames.EXPAND_TABS, false);
CodeStylePreferences.get(doc).getPreferences().putInt(SimpleValueNames.TAB_SIZE, 8);
}
GsfUtilities.setLineIndentation(doc, offset, indent);
assertEquals(after, doc.getText(0, doc.getLength()));
}
示例3: testFieldLocation233440
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public void testFieldLocation233440() throws Exception {
Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
prefs.put("classMemberInsertionPoint", InsertionPoint.CARET_LOCATION.name());
IntroduceHint.INSERT_CLASS_MEMBER = new InsertClassMember();
performFixTest("package test;\n" +
"public class Test {\n" +
" String s = \"text\";\n" +
" public void method() {\n" +
" String local = |\"text\"|;\n" +
" }\n" +
"}\n",
"package test; public class Test { private String text = \"text\"; String s = text; public void method() { String local = text; } } ",
new DialogDisplayerImpl2(null, IntroduceFieldPanel.INIT_FIELD, true, EnumSet
.<Modifier>of(Modifier.PRIVATE), false, true),
5, 2);
}
示例4: testConstantFix208072a
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public void testConstantFix208072a() throws Exception {
Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
performFixTest("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" private static final int II = |1 + 2 * 3|;\n" +
"}\n",
("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" private static final int ZZ = 1 + 2 * 3;\n" +
" private static final int II = ZZ;\n" +
"}\n").replaceAll("[ \t\n]+", " "),
new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
1, 0);
}
示例5: testConstantFix208072b
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public void testConstantFix208072b() throws Exception {
Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
performFixTest("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" static {\n" +
" II = |1 + 2 * 3|;\n" +
" }\n" +
" private static final int II;\n" +
"}\n",
("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" private static final int ZZ = 1 + 2 * 3;\n" +
" static {\n" +
" II = ZZ;\n" +
" }\n" +
" private static final int II;\n" +
"}\n").replaceAll("[ \t\n]+", " "),
new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
5, 1);
}
示例6: testConstantFix208072c
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public void testConstantFix208072c() throws Exception {
Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
performFixTest("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" {\n" +
" int ii = |1 + 2 * 3|;\n" +
" }\n" +
" private static final int II = 0;\n" +
"}\n",
("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" {\n" +
" int ii = ZZ;\n" +
" }\n" +
" private static final int II = 0;\n" +
" private static final int ZZ = 1 + 2 * 3;\n" +
"}\n").replaceAll("[ \t\n]+", " "),
new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
5, 1);
}
示例7: testConstantFix219771c
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public void testConstantFix219771c() throws Exception {
Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
prefs.put("classMembersOrder", "STATIC_INIT;FIELD;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD");
prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
performFixTest("package test;\n" +
"public class Test {\n" +
" public void method() {\n" +
" System.out.println(\"C0 = \" + |C1 * 5|);\n" +
" }\n" +
" public static final int C1 = 100;\n" +
"}\n",
("package test;\n" +
"public class Test {\n" +
" public final int C0 = C1 * 5;\n" +
" public void method() {\n" +
" System.out.println(\"C0 = \" + C0);\n" +
" }\n" +
" public static final int C1 = 100;\n" +
"}\n").replaceAll("[ \t\n]+", " "),
new DialogDisplayerImpl2("C0", IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PUBLIC), true, true),
5, 2);
}
示例8: testFieldFix208072d
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public void testFieldFix208072d() throws Exception {
Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
performFixTest("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" static {\n" +
" int ii = |1 + 2 * 3|;\n" +
" }\n" +
" private static final int II = 0;\n" +
"}\n",
("package test;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"public class Test {\n" +
" private static int ZZ = 1 + 2 * 3;\n" +
" static {\n" +
" int ii = ZZ;\n" +
" }\n" +
" private static final int II = 0;\n" +
"}\n").replaceAll("[ \t\n]+", " "),
new DialogDisplayerImpl2("ZZ", IntroduceFieldPanel.INIT_FIELD, false, EnumSet.<Modifier>of(Modifier.PRIVATE), false, true),
5, 2);
}
示例9: PlainTextEditor
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public PlainTextEditor (final String text) {
initComponents();
final JEditorPane editor = UI_COMPO_FACTORY.makeEditorPane();
editor.setEditorKit(getEditorKit());
this.document = Utilities.getDocument(editor);
setText(text);
final Preferences docPreferences = CodeStylePreferences.get(this.document).getPreferences();
this.oldWrapping = Wrapping.findFor(docPreferences.get(SimpleValueNames.TEXT_LINE_WRAP, "none"));
this.wrapping = oldWrapping;
this.lastComponent = makeEditorForText(this.document);
this.lastComponent.setPreferredSize(new Dimension(620, 440));
this.add(this.lastComponent, BorderLayout.CENTER);
this.labelWrapMode.setMinimumSize(new Dimension(55, this.labelWrapMode.getMinimumSize().height));
updateBottomPanel();
}
示例10: operate
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
protected boolean operate(String simpleValueName, String value) {
boolean codeStyleChangeNeeded = false;
Preferences codeStyle = CodeStylePreferences.get(file, file.getMIMEType()).getPreferences();
String currentValue = codeStyle.get(simpleValueName, "");
LOG.log(Level.INFO, "\u00ac Current value: {0}", currentValue);
LOG.log(Level.INFO, "\u00ac New value: {0}", value);
if (currentValue.equals(value)) {
LOG.log(Level.INFO, "\u00ac No change needed");
} else {
codeStyle.put(simpleValueName, value);
codeStyleChangeNeeded = true;
LOG.log(Level.INFO, "\u00ac Changing value from \"{0}\" to \"{1}\"",
new Object[]{currentValue, value});
}
return codeStyleChangeNeeded;
}
示例11: insertTabString
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
/** Modify the line to move the text starting at dotPos one tab
* column to the right. Whitespace preceeding dotPos may be
* replaced by a TAB character if tabs expanding is on.
* @param doc document to operate on
* @param dotPos insertion point
*/
static void insertTabString (final BaseDocument doc, final int dotPos) throws BadLocationException {
final BadLocationException[] badLocationExceptions = new BadLocationException [1];
doc.runAtomic (new Runnable () {
public void run () {
try {
// Determine first white char before dotPos
int rsPos = Utilities.getRowStart(doc, dotPos);
int startPos = Utilities.getFirstNonWhiteBwd(doc, dotPos, rsPos);
startPos = (startPos >= 0) ? (startPos + 1) : rsPos;
int startCol = Utilities.getVisualColumn(doc, startPos);
int endCol = Utilities.getNextTabColumn(doc, dotPos);
Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
String tabStr = Analyzer.getWhitespaceString(
startCol, endCol,
prefs.getBoolean(SimpleValueNames.EXPAND_TABS, EditorPreferencesDefaults.defaultExpandTabs),
prefs.getInt(SimpleValueNames.TAB_SIZE, EditorPreferencesDefaults.defaultTabSize));
// Search for the first non-common char
char[] removeChars = doc.getChars(startPos, dotPos - startPos);
int ind = 0;
while (ind < removeChars.length && removeChars[ind] == tabStr.charAt(ind)) {
ind++;
}
startPos += ind;
doc.remove(startPos, dotPos - startPos);
doc.insertString(startPos, tabStr.substring(ind), null);
} catch (BadLocationException ex) {
badLocationExceptions [0] = ex;
}
}
});
if (badLocationExceptions[0] != null)
throw badLocationExceptions [0];
}
示例12: getNextTabColumn
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
/** Get the visual column corresponding to the position after pressing
* the TAB key.
* @param doc document to work with
* @param offset position at which the TAB was pressed
*/
public static int getNextTabColumn(BaseDocument doc, int offset)
throws BadLocationException {
// FIXME -- this should be delegated to LineDocumentUtils.
int col = getVisualColumn(doc, offset);
Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
int tabSize = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
return tabSize <= 0 ? col : (col + tabSize) / tabSize * tabSize;
}
示例13: performUnaryVsBinaryTest187556
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
private void performUnaryVsBinaryTest187556(final Kind first, final Kind second, String goldenSnippet) throws Exception {
String test = "public class Test { void m(int x) { int y = (|2 + 1); } }";
String golden = "public class Test { void m(int x) { int y = " + goldenSnippet + "(2 + 1); } }";
testFile = new File(getWorkDir(), "Test.java");
final int index = test.indexOf("|");
assertTrue(index != -1);
TestUtilities.copyStringToFile(testFile, test.replace("|", ""));
Preferences prefs = CodeStylePreferences.get(FileUtil.toFileObject(testFile), JavacParser.MIME_TYPE).getPreferences();
boolean orig = prefs.getBoolean(FmtOptions.spaceAroundBinaryOps, FmtOptions.getDefaultAsBoolean(FmtOptions.spaceAroundBinaryOps));
prefs.putBoolean(FmtOptions.spaceAroundBinaryOps, false);
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy copy) throws Exception {
if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
return;
}
Tree node = copy.getTreeUtilities().pathFor(index).getLeaf();
assertEquals(Kind.PARENTHESIZED, node.getKind());
System.out.println("node: " + node);
TreeMaker make = copy.getTreeMaker();
Tree modified = make.Binary(first, make.Literal(0), make.Unary(second, (ExpressionTree) node));
System.out.println("modified: " + modified);
copy.rewrite(node, modified);
}
};
src.runModificationTask(task).commit();
String res = TestUtilities.copyFileToString(testFile);
prefs.putBoolean(FmtOptions.spaceAroundBinaryOps, orig);
assertEquals(golden, res);
}
示例14: setCodePreferences
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
public static Map<String, String> setCodePreferences(Map<String, String> values) {
Preferences preferences = CodeStylePreferences.get(new PlainDocument(), JavacParser.MIME_TYPE).getPreferences();
Map<String, String> origValues = new HashMap<String, String>();
for (String key : values.keySet()) {
origValues.put(key, preferences.get(key, null));
}
setValues(preferences, values);
return origValues;
}
示例15: textLimitWidth
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; //导入依赖的package包/类
@Override
protected int textLimitWidth() {
Document doc = getDocument();
if (doc != null) {
int textLimit = CodeStylePreferences.get(doc).getPreferences().
getInt(SimpleValueNames.TEXT_LIMIT_WIDTH, 80);
if (textLimit > 0) {
return textLimit;
}
}
return super.textLimitWidth();
}