Skip to content

Commit

Permalink
Accept different separators in docsting generation preferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 2, 2024
1 parent 3da663b commit a65c47e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public class DocstringPreferences {
public static final String DEFAULT_TYPETAG_GENERATION = TYPETAG_GENERATION_NEVER;

public static final String DONT_GENERATE_TYPETAGS = "DONT_GENERATE_TYPETAGS_PREFIXES";
public static final String DEFAULT_DONT_GENERATE_TYPETAGS = "sz\0n\0f";
public static final String DEFAULT_DONT_GENERATE_TYPETAGS = "sz,n,f";

public static final String TYPETAG_SEPARATORS = ",; \n";

/**
* Getter for the preferred docstring character. Only a shortcut.
Expand Down Expand Up @@ -86,16 +88,15 @@ public static boolean getTypeTagShouldBeGenerated(String parameterName) {
return GENERATE_TYPE_DOCSTRING_ON_TESTS;
}
IEclipsePreferences preferences = PydevPrefs.getEclipsePreferences();
String preference = preferences.get(TYPETAG_GENERATION,
DEFAULT_TYPETAG_GENERATION);
if (preference.equals(TYPETAG_GENERATION_NEVER)) {
String preference = preferences.get(TYPETAG_GENERATION, DEFAULT_TYPETAG_GENERATION).toLowerCase().strip();

if (preference.equals(TYPETAG_GENERATION_NEVER.toLowerCase())) {
return false;
} else if (preference.equals(TYPETAG_GENERATION_ALWAYS)) {
} else if (preference.equals(TYPETAG_GENERATION_ALWAYS.toLowerCase())) {
return true;
} else {// TYPETAG_GENERATION_CUSTOM - check prefix.
String prefixesString = preferences.get(DONT_GENERATE_TYPETAGS,
DEFAULT_DONT_GENERATE_TYPETAGS);
StringTokenizer st = new StringTokenizer(prefixesString, "\0"); // "\0" is the separator
String prefixesString = preferences.get(DONT_GENERATE_TYPETAGS, DEFAULT_DONT_GENERATE_TYPETAGS);
StringTokenizer st = new StringTokenizer(prefixesString, DocstringPreferences.TYPETAG_SEPARATORS);

while (st.hasMoreTokens()) {
if (parameterName.startsWith(st.nextToken())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.preference.ListEditor;
import org.eclipse.swt.widgets.Composite;
import org.python.pydev.core.docstrings.DocstringPreferences;
import org.python.pydev.shared_core.structure.LinkedListWarningOnSlowOperations;

/**
Expand All @@ -29,7 +30,7 @@ protected String createList(String[] items) {
StringBuilder sb = new StringBuilder();
for (String item : items) {
sb.append(item);
sb.append("\0");
sb.append(",");
}
return sb.toString();
}
Expand All @@ -44,7 +45,7 @@ protected String getNewInputObject() {
@Override
protected String[] parseString(String stringList) {
List<String> items = new LinkedListWarningOnSlowOperations<String>();
StringTokenizer st = new StringTokenizer(stringList, "\0");
StringTokenizer st = new StringTokenizer(stringList, DocstringPreferences.TYPETAG_SEPARATORS);

while (st.hasMoreTokens()) {
items.add(st.nextToken());
Expand Down

0 comments on commit a65c47e

Please sign in to comment.