Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 22, 2024
1 parent 6132a4f commit 5306e23
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import org.python.pydev.ast.adapters.offsetstrategy.BeginOffset;
import org.python.pydev.ast.adapters.offsetstrategy.EndOffset;
import org.python.pydev.ast.adapters.offsetstrategy.IOffsetStrategy;
import org.python.pydev.ast.assist_assign.AssistAssign;
import org.python.pydev.core.docutils.PySelection;
import org.python.pydev.core.docutils.PySelection.LineStartingScope;
import org.python.pydev.core.docutils.PyStringUtils;
import org.python.pydev.core.log.Log;
import org.python.pydev.core.proposals.CompletionProposalFactory;
import org.python.pydev.core.templates.PyDocumentTemplateContext;
import org.python.pydev.editor.correctionassist.heuristics.AssistAssign;
import org.python.pydev.parser.jython.ast.ClassDef;
import org.python.pydev.parser.jython.ast.Pass;
import org.python.pydev.parser.visitors.NodeUtils;
Expand Down
1 change: 1 addition & 0 deletions plugins/org.python.pydev.ast/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Export-Package: org.python.pydev.ast,
org.python.pydev.ast.adapters.visitors.selection,
org.python.pydev.ast.analysis,
org.python.pydev.ast.analysis.messages,
org.python.pydev.ast.assist_assign,
org.python.pydev.ast.builder,
org.python.pydev.ast.codecompletion,
org.python.pydev.ast.codecompletion.revisited,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author Fabio Zadrozny
*/
package org.python.pydev.editor.correctionassist.heuristics;
package org.python.pydev.ast.assist_assign;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -20,8 +20,8 @@
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.templates.TemplateContext;
import org.eclipse.jface.text.templates.TemplateContextType;
import org.python.pydev.codingstd.ICodingStd;
import org.python.pydev.core.IAssistProps;
import org.python.pydev.core.ICodingStd;
import org.python.pydev.core.IIndentPrefs;
import org.python.pydev.core.IPyEdit;
import org.python.pydev.core.IPythonNature;
Expand All @@ -31,10 +31,10 @@
import org.python.pydev.core.docutils.PyStringUtils;
import org.python.pydev.core.docutils.SyntaxErrorException;
import org.python.pydev.core.log.Log;
import org.python.pydev.core.preferences.PyDevCodeStylePreferences;
import org.python.pydev.core.proposals.CompletionProposalFactory;
import org.python.pydev.core.templates.PyAddTemplateResolvers;
import org.python.pydev.core.templates.PyDocumentTemplateContext;
import org.python.pydev.plugin.preferences.PyCodeStylePreferencesPage;
import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle;
import org.python.pydev.shared_core.code_completion.IPyCompletionProposal;
import org.python.pydev.shared_core.image.IImageCache;
Expand All @@ -56,7 +56,7 @@ public AssistAssign() {

@Override
public boolean localsAndAttrsCamelcase() {
return PyCodeStylePreferencesPage.useLocalsAndAttrsCamelCase();
return PyDevCodeStylePreferences.useLocalsAndAttrsCamelCase();
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Please see the license.txt included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
*/
package org.python.pydev.codingstd;
package org.python.pydev.core;

public interface ICodingStd {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.python.pydev.core.preferences;

import org.python.pydev.shared_core.SharedCorePlugin;

public class PyDevCodeStylePreferences {

public static final String USE_LOCALS_AND_ATTRS_CAMELCASE = "USE_LOCALS_AND_ATTRS_CAMELCASE";
public static final String USE_METHODS_FORMAT = "USE_METHODS_FORMAT";
public static final boolean DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE = false;
public static final int METHODS_FORMAT_CAMELCASE_FIRST_LOWER = 0;
public static final int METHODS_FORMAT_CAMELCASE_FIRST_UPPER = 1;
public static final int METHODS_FORMAT_UNDERSCORE_SEPARATED = 2;
public static final int DEFAULT_USE_METHODS_FORMAT = METHODS_FORMAT_UNDERSCORE_SEPARATED;

public static final String[][] LABEL_AND_VALUE = new String[][] {
{ "underscore_separated", String.valueOf(METHODS_FORMAT_UNDERSCORE_SEPARATED) },
{ "CamelCase() with first upper", String.valueOf(METHODS_FORMAT_CAMELCASE_FIRST_UPPER) },
{ "camelCase() with first lower", String.valueOf(METHODS_FORMAT_CAMELCASE_FIRST_LOWER) }, };

public static final String[][] LOCALS_LABEL_AND_VALUE = new String[][] {
{ "underscore_separated", String.valueOf(false) },
{ "camelCase with first lower", String.valueOf(true) }, };

public static int TESTING_METHOD_FORMAT = DEFAULT_USE_METHODS_FORMAT;

public static int useMethodsCamelCase() {
if (SharedCorePlugin.inTestMode()) {
return TESTING_METHOD_FORMAT;
}
return PydevPrefs.getEclipsePreferences().getInt(USE_METHODS_FORMAT, DEFAULT_USE_METHODS_FORMAT);
}

public static boolean TESTING_METHOD_LOCALS_AND_ATTRS_CAMEL_CASE = DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE;

public static boolean useLocalsAndAttrsCamelCase() {
if (SharedCorePlugin.inTestMode()) {
return TESTING_METHOD_LOCALS_AND_ATTRS_CAMEL_CASE;
}
return PydevPrefs.getEclipsePreferences().getBoolean(USE_LOCALS_AND_ATTRS_CAMELCASE,
DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.viewers.ISelection;
import org.python.pydev.ast.assist_assign.AssistAssign;
import org.python.pydev.core.docutils.PySelection;
import org.python.pydev.core.log.Log;
import org.python.pydev.editor.PySelectionFromEditor;
import org.python.pydev.editor.codecompletion.ConvertCompletionProposals;
import org.python.pydev.editor.correctionassist.PyCorrectionAssistant;
import org.python.pydev.editor.correctionassist.heuristics.AssistAssign;
import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle;
import org.python.pydev.shared_interactive_console.console.ui.internal.ScriptConsoleViewer;
import org.python.pydev.shared_ui.SharedUiPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import org.python.pydev.ast.adapters.IClassDefAdapter;
import org.python.pydev.ast.adapters.INodeAdapter;
import org.python.pydev.ast.adapters.PropertyTextAdapter;
import org.python.pydev.core.preferences.PyDevCodeStylePreferences;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.jython.ast.factory.AdapterPrefs;
import org.python.pydev.parser.jython.ast.factory.NodeHelper;
import org.python.pydev.plugin.preferences.PyCodeStylePreferencesPage;
import org.python.pydev.refactoring.core.request.IRefactoringRequest;
import org.python.pydev.shared_core.string.StringUtils;

Expand Down Expand Up @@ -122,11 +122,11 @@ public String getPropertyName() {
*/
public static String getAccessorName(String accessType, String attributeName) {
accessType += "_" + attributeName;
int useMethodsCamelCase = PyCodeStylePreferencesPage.useMethodsCamelCase();
if (useMethodsCamelCase == PyCodeStylePreferencesPage.METHODS_FORMAT_CAMELCASE_FIRST_LOWER) {
int useMethodsCamelCase = PyDevCodeStylePreferences.useMethodsCamelCase();
if (useMethodsCamelCase == PyDevCodeStylePreferences.METHODS_FORMAT_CAMELCASE_FIRST_LOWER) {
return StringUtils.asStyleCamelCaseFirstLower(accessType);
}
if (useMethodsCamelCase == PyCodeStylePreferencesPage.METHODS_FORMAT_CAMELCASE_FIRST_UPPER) {
if (useMethodsCamelCase == PyDevCodeStylePreferences.METHODS_FORMAT_CAMELCASE_FIRST_UPPER) {
return StringUtils.asStyleCamelCaseFirstUpper(accessType);
}
//default is underscore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
******************************************************************************/
package org.python.pydev.refactoring.tests.codegenerator.generateproperties;

import org.python.pydev.plugin.preferences.PyCodeStylePreferencesPage;
import org.python.pydev.core.preferences.PyDevCodeStylePreferences;
import org.python.pydev.refactoring.codegenerator.generateproperties.request.GeneratePropertiesRequest;

import junit.framework.TestCase;
Expand All @@ -31,13 +31,13 @@ public static void main(String[] args) {
}

public void testCodingStd() {
PyCodeStylePreferencesPage.TESTING_METHOD_FORMAT = PyCodeStylePreferencesPage.METHODS_FORMAT_CAMELCASE_FIRST_LOWER;
PyDevCodeStylePreferences.TESTING_METHOD_FORMAT = PyDevCodeStylePreferences.METHODS_FORMAT_CAMELCASE_FIRST_LOWER;
assertEquals("delMyAttr", GeneratePropertiesRequest.getAccessorName("del", "my_attr"));

PyCodeStylePreferencesPage.TESTING_METHOD_FORMAT = PyCodeStylePreferencesPage.METHODS_FORMAT_CAMELCASE_FIRST_UPPER;
PyDevCodeStylePreferences.TESTING_METHOD_FORMAT = PyDevCodeStylePreferences.METHODS_FORMAT_CAMELCASE_FIRST_UPPER;
assertEquals("DelMyAttr", GeneratePropertiesRequest.getAccessorName("del", "my_attr"));

PyCodeStylePreferencesPage.TESTING_METHOD_FORMAT = PyCodeStylePreferencesPage.METHODS_FORMAT_UNDERSCORE_SEPARATED;
PyDevCodeStylePreferences.TESTING_METHOD_FORMAT = PyDevCodeStylePreferences.METHODS_FORMAT_UNDERSCORE_SEPARATED;
assertEquals("del_my_attr", GeneratePropertiesRequest.getAccessorName("del", "my_attr"));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import org.python.pydev.core.proposals.ICompletionProposalFactory;
import org.python.pydev.editor.codecompletion.PyTemplateProposal;
import org.python.pydev.editor.codefolding.PyCalltipsContextInformationFromIToken;
import org.python.pydev.editor.correctionassist.AssistAssignCompletionProposal;
import org.python.pydev.editor.correctionassist.FixCompletionProposal;
import org.python.pydev.editor.correctionassist.IgnoreCompletionProposal;
import org.python.pydev.editor.correctionassist.IgnoreCompletionProposalInSameLine;
import org.python.pydev.editor.correctionassist.IgnoreFlake8CompletionProposalInSameLine;
import org.python.pydev.editor.correctionassist.IgnorePyLintCompletionProposalInSameLine;
import org.python.pydev.editor.correctionassist.docstrings.AssistDocstringCompletionProposal;
import org.python.pydev.editor.correctionassist.heuristics.AssistAssignCompletionProposal;
import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle;
import org.python.pydev.shared_core.code_completion.IPyCompletionProposal.ICompareContext;
import org.python.pydev.shared_core.image.IImageHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Please see the license.txt included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
*/
package org.python.pydev.editor.correctionassist.heuristics;
package org.python.pydev.editor.correctionassist;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.ui.texteditor.spelling.SpellingAnnotation;
import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor;
import org.eclipse.ui.texteditor.spelling.SpellingProblem;
import org.python.pydev.ast.assist_assign.AssistAssign;
import org.python.pydev.ast.codecompletion.ProposalsComparator;
import org.python.pydev.ast.surround_with.AssistSurroundWith;
import org.python.pydev.core.ExtensionHelper;
Expand All @@ -40,7 +41,6 @@
import org.python.pydev.core.docutils.PySelection;
import org.python.pydev.core.log.Log;
import org.python.pydev.editor.PyEdit;
import org.python.pydev.editor.correctionassist.heuristics.AssistAssign;
import org.python.pydev.editor.correctionassist.heuristics.AssistImport;
import org.python.pydev.editor.correctionassist.heuristics.AssistImportToLocal;
import org.python.pydev.editor.correctionassist.heuristics.AssistPercentToFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,11 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.python.pydev.core.preferences.PydevPrefs;
import org.python.pydev.core.preferences.PyDevCodeStylePreferences;
import org.python.pydev.plugin.PydevPlugin;
import org.python.pydev.shared_core.SharedCorePlugin;

public class PyCodeStylePreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

public static final String USE_LOCALS_AND_ATTRS_CAMELCASE = "USE_LOCALS_AND_ATTRS_CAMELCASE";

public static final String USE_METHODS_FORMAT = "USE_METHODS_FORMAT";

public static final boolean DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE = false;

public static final int METHODS_FORMAT_CAMELCASE_FIRST_LOWER = 0;
public static final int METHODS_FORMAT_CAMELCASE_FIRST_UPPER = 1;
public static final int METHODS_FORMAT_UNDERSCORE_SEPARATED = 2;

public static final int DEFAULT_USE_METHODS_FORMAT = METHODS_FORMAT_UNDERSCORE_SEPARATED;

public static final String[][] LABEL_AND_VALUE = new String[][] {
{ "underscore_separated", String.valueOf(METHODS_FORMAT_UNDERSCORE_SEPARATED) },
{ "CamelCase() with first upper", String.valueOf(METHODS_FORMAT_CAMELCASE_FIRST_UPPER) },
{ "camelCase() with first lower", String.valueOf(METHODS_FORMAT_CAMELCASE_FIRST_LOWER) }, };

public static final String[][] LOCALS_LABEL_AND_VALUE = new String[][] {
{ "underscore_separated", String.valueOf(false) },
{ "camelCase with first lower", String.valueOf(true) }, };

private Label labelLocalsFormat;
private Label labelMethodsFormat;

Expand All @@ -59,19 +37,19 @@ public PyCodeStylePreferencesPage() {
public void createFieldEditors() {
Composite p = getFieldEditorParent();

useLocalsAndAttrsCamelCase = new RadioGroupFieldEditor(USE_LOCALS_AND_ATTRS_CAMELCASE,
"Locals and attributes format (used for assign quick-assist)?", 1, LOCALS_LABEL_AND_VALUE, p, true);
useLocalsAndAttrsCamelCase = new RadioGroupFieldEditor(PyDevCodeStylePreferences.USE_LOCALS_AND_ATTRS_CAMELCASE,
"Locals and attributes format (used for assign quick-assist)?", 1, PyDevCodeStylePreferences.LOCALS_LABEL_AND_VALUE, p, true);
addField(useLocalsAndAttrsCamelCase);

useMethodsFormat = new RadioGroupFieldEditor(USE_METHODS_FORMAT,
"Methods format (used for generate properties refactoring)", 1, LABEL_AND_VALUE, p, true);
useMethodsFormat = new RadioGroupFieldEditor(PyDevCodeStylePreferences.USE_METHODS_FORMAT,
"Methods format (used for generate properties refactoring)", 1, PyDevCodeStylePreferences.LABEL_AND_VALUE, p, true);
addField(useMethodsFormat);

labelLocalsFormat = new Label(p, SWT.NONE);

labelMethodsFormat = new Label(p, SWT.NONE);
updateLabelLocalsAndAttrs(useLocalsAndAttrsCamelCase());
updateLabelMethods(useMethodsCamelCase());
updateLabelLocalsAndAttrs(PyDevCodeStylePreferences.useLocalsAndAttrsCamelCase());
updateLabelMethods(PyDevCodeStylePreferences.useMethodsCamelCase());

}

Expand All @@ -80,10 +58,10 @@ public void createFieldEditors() {
*/
private void updateLabelMethods(int useMethodsFormat) {

if (useMethodsFormat == METHODS_FORMAT_CAMELCASE_FIRST_UPPER) {
if (useMethodsFormat == PyDevCodeStylePreferences.METHODS_FORMAT_CAMELCASE_FIRST_UPPER) {
labelMethodsFormat.setText("Refactoring property methods in the format def MyMethod() ");

} else if (useMethodsFormat == METHODS_FORMAT_UNDERSCORE_SEPARATED) {
} else if (useMethodsFormat == PyDevCodeStylePreferences.METHODS_FORMAT_UNDERSCORE_SEPARATED) {
labelMethodsFormat.setText("Refactoring property methods in the format def my_method() ");

} else {
Expand All @@ -107,25 +85,6 @@ private void updateLabelLocalsAndAttrs(boolean useCamelCase) {
public void init(IWorkbench workbench) {
}

public static int TESTING_METHOD_FORMAT = DEFAULT_USE_METHODS_FORMAT;

public static int useMethodsCamelCase() {
if (SharedCorePlugin.inTestMode()) {
return TESTING_METHOD_FORMAT;
}
return PydevPrefs.getEclipsePreferences().getInt(USE_METHODS_FORMAT, DEFAULT_USE_METHODS_FORMAT);
}

public static boolean TESTING_METHOD_LOCALS_AND_ATTRS_CAMEL_CASE = DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE;

public static boolean useLocalsAndAttrsCamelCase() {
if (SharedCorePlugin.inTestMode()) {
return TESTING_METHOD_LOCALS_AND_ATTRS_CAMEL_CASE;
}
return PydevPrefs.getEclipsePreferences().getBoolean(USE_LOCALS_AND_ATTRS_CAMELCASE,
DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE);
}

@Override
public void propertyChange(PropertyChangeEvent event) {
super.propertyChange(event);
Expand All @@ -140,7 +99,7 @@ public void propertyChange(PropertyChangeEvent event) {
String newValue = (String) event.getNewValue();
val = Integer.parseInt(newValue);
} catch (NumberFormatException e) {
val = DEFAULT_USE_METHODS_FORMAT;
val = PyDevCodeStylePreferences.DEFAULT_USE_METHODS_FORMAT;
}

updateLabelMethods(val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.python.pydev.builder.todo.PyTodoPrefPage;
import org.python.pydev.core.docstrings.DocstringPreferences;
import org.python.pydev.core.imports.ImportPreferences;
import org.python.pydev.core.preferences.PyDevCodeStylePreferences;
import org.python.pydev.editor.codefolding.PyDevCodeFoldingPrefPage;
import org.python.pydev.editor.commentblocks.CommentBlocksPreferences;
import org.python.pydev.editor.hover.PyHoverPreferencesPage;
Expand Down Expand Up @@ -220,10 +221,10 @@ public void initializeDefaultPreferences() {
//[[[end]]]

//coding style
node.putBoolean(PyCodeStylePreferencesPage.USE_LOCALS_AND_ATTRS_CAMELCASE,
PyCodeStylePreferencesPage.DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE);
node.putInt(PyCodeStylePreferencesPage.USE_METHODS_FORMAT,
PyCodeStylePreferencesPage.DEFAULT_USE_METHODS_FORMAT);
node.putBoolean(PyDevCodeStylePreferences.USE_LOCALS_AND_ATTRS_CAMELCASE,
PyDevCodeStylePreferences.DEFAULT_USE_LOCALS_AND_ATTRS_CAMELCASE);
node.putInt(PyDevCodeStylePreferences.USE_METHODS_FORMAT,
PyDevCodeStylePreferences.DEFAULT_USE_METHODS_FORMAT);

//Editor title
node.putBoolean(PyTitlePreferencesPage.TITLE_EDITOR_NAMES_UNIQUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.python.pydev.codingstd.ICodingStd;
import org.python.pydev.ast.assist_assign.AssistAssign;
import org.python.pydev.core.ICodingStd;
import org.python.pydev.core.docutils.PySelection;
import org.python.pydev.core.proposals.CompletionProposalFactory;
import org.python.pydev.editor.codecompletion.proposals.DefaultCompletionProposalFactory;
Expand Down

0 comments on commit 5306e23

Please sign in to comment.