Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

86 personalized vs project config #100

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ formatString: aString class: aClass noPattern: aBoolean notifying: anObject
class: aClass
noPattern: aBoolean
notifying: anObject
with: PPFormatterConfig default
with: PPFormatterConfig preferenceConfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"formatMethod:" : "tobe 3/10/2021 13:32",
"formatPackage:" : "tobe 3/10/2021 14:59",
"formatString:class:noPattern:" : "tobe 3/10/2021 15:47",
"formatString:class:noPattern:notifying:" : "KD 6/15/2022 16:11",
"formatString:class:noPattern:notifying:with:" : "KD 7/21/2022 18:03",
"formatString:class:noPattern:notifying:" : "JW 7/24/2022 19:43",
"formatString:class:noPattern:notifying:with:" : "KD 6/15/2022 16:11",
"formatString:class:noPattern:with:" : "Alexander Ungefug 6/1/2022 16:06",
"stripMethodPattern:" : "tobe 3/19/2021 18:51" },
"instance" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
config
default
"Default is lazy initialized"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
helpers
getClassMethodsWithPragma: aSymbol inClasses: aClassList

^ (aClassList gather: [:methodClass | Pragma allNamed: aSymbol in: methodClass class])
collect: [:pragma | pragma method]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config
packageConfigForClass: aClass

^ self packageConfigForPackage: aClass packageInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config
packageConfigForMethod: aCompiledMethod

^ self packageConfigForMethod: aCompiledMethod in: aCompiledMethod methodClass packageInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
config
packageConfigForMethod: aCompiledMethod in: aPackage

| classesInPackage ppConfigMethods config |
classesInPackage := aPackage classes.
ppConfigMethods := self getClassMethodsWithPragma: #ppProjectConfig inClasses: classesInPackage.
ppConfigMethods size = 0 ifTrue: [^ self default].
ppConfigMethods size = 1 ifFalse: [self error: 'More than one Config found in Package: ', aPackage asString].
config := ppConfigMethods first methodClass soleInstance perform: ppConfigMethods first selector with: aCompiledMethod.
config class = PPFormatterConfig ifFalse: [self error: 'Config returned by ', ppConfigMethods first selector asString,' is not of Type PPFormatterConfig.'].
^ config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config
packageConfigForPackage: aPackage

^ self packageConfigForMethod: nil in: aPackage
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config
preferenceConfig

self shouldUseDefaultAsPreferenceConfig ifTrue: [^ PPFormatterConfig default].
"The Personalized Config is the Default Config for now. In later Issues we want this Method to return the Config specified in the Prefrence Browser."
^ PPFormatterConfig default
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
shouldUseDefaultAsPreferenceConfig: aBoolean

ShouldUseDefaultAsPreferenceConfig := aBoolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
shouldUseDefaultAsPreferenceConfig

^ ShouldUseDefaultAsPreferenceConfig ifNil: [ShouldUseDefaultAsPreferenceConfig := false]
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"class" : {
"default" : "KD 6/15/2022 16:11" },
"default" : "KD 6/15/2022 16:11",
"getClassMethodsWithPragma:inClasses:" : "JW 7/25/2022 13:43",
"packageConfigForClass:" : "JW 7/25/2022 00:08",
"packageConfigForMethod:" : "JW 7/27/2022 11:07",
"packageConfigForMethod:in:" : "JW 7/27/2022 11:07",
"packageConfigForPackage:" : "JW 7/27/2022 11:08",
"preferenceConfig" : "JW 7/24/2022 19:51",
"shouldUseDefaultAsPreferenceConfig" : "JW 7/24/2022 19:48",
"shouldUseDefaultAsPreferenceConfig:" : "JW 7/24/2022 19:49" },
"instance" : {
"spaceBeforeComma" : "KD 6/15/2022 16:07",
"spaceBeforeComma" : "JW 7/21/2022 17:40",
"spaceBeforeComma:" : "YH 6/2/2022 14:16",
"spaceBeforePointInArray" : "Alexander Ungefug 6/1/2022 15:59",
"spaceBeforePointInArray:" : "YH 6/2/2022 14:17" } }
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"classinstvars" : [
],
"classvars" : [
],
"ShouldUseDefaultAsPreferenceConfig" ],
"commentStamp" : "",
"instvars" : [
"spaceBeforeComma",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
*PoppyPrint-Core-override
acceptTextInModel

| text |
self okToStyle ifFalse:[^super acceptTextInModel].
"#correctFrom:to:with: is sent when the method source is
manipulated during compilation (removing unused temps,
changing selectors etc). But #correctFrom:to:with: operates
on the textMorph's text, and we may be saving an unstyled
copy of the text. This means that these corrections will be lost
unless we also apply the corrections to the unstyled copy that we are saving.
So remember the unstyled copy in unstyledAcceptText, so
that when #correctFrom:to:with: is received we can also apply
the correction to it"
text := textMorph asText.
((model respondsTo: #contentsSymbol) and: [model respondsTo: #editSelection]) ifTrue: [
(model contentsSymbol = #prettyPrint and: [model editSelection = #newMessage or: [model editSelection = #editMessage]]) ifTrue: [
text := PPFormatter
formatString: text asString
class: model selectedClass
noPattern: false
with: self getProjectConfig]].
unstyledAcceptText := styler unstyledTextFrom: text asText.
[^setTextSelector isNil or:
[setTextSelector numArgs = 2
ifTrue: [model perform: setTextSelector with: unstyledAcceptText with: self]
ifFalse: [model perform: setTextSelector with: unstyledAcceptText]]
] ensure:[unstyledAcceptText := nil]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*PoppyPrint-Core-override
getProjectConfig

(model respondsTo: #editSelection) ifFalse: [^ PPFormatterConfig default].
model editSelection = #newMessage ifTrue: [^ PPFormatterConfig packageConfigForClass: model selectedClass].
model editSelection = #editMessage ifTrue: [^ PPFormatterConfig packageConfigForMethod: model selectedClassOrMetaClass >> model selectedMessageName].
^ PPFormatterConfig default.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"class" : {
},
"instance" : {
"acceptTextInModel" : "JW 7/25/2022 14:53",
"getProjectConfig" : "JW 7/25/2022 14:53" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "PluggableTextMorphPlus" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests - projectConfig
testGetProjectConfigOfMethod

self
assert: (PPSimulationExample poppyConfig: PPSimulationExample >> #example) instanceVariableValues
equals: (PPFormatterConfig packageConfigForMethod: PPSimulationExample >> #example) instanceVariableValues
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"testEmptyLineInCaseOf" : "tobe 3/11/2021 10:54",
"testEmptyLinesBetweenComments" : "tobe 3/11/2021 11:35",
"testEmptyMethod" : "tobe 3/10/2021 14:58",
"testGetProjectConfigOfMethod" : "JW 7/24/2022 22:27",
"testGithubIssue7" : "tobe 3/11/2021 11:15",
"testInlineCommentWithNewline" : "KD 6/15/2022 16:11",
"testKeepEmptyLines" : "tobe 3/10/2021 14:58",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config
poppyConfig: aMethod
<ppProjectConfig>

^ PPFormatterConfig default
spaceBeforePointInArray: true;
spaceBeforeComma: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
examples
example

"This Method will be rewritten in PPSimulationTest"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"class" : {
"poppyConfig:" : "JW 7/24/2022 18:47" },
"instance" : {
"example" : "JW 7/25/2022 18:24" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "PoppyPrint-Tests",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "PPSimulationExample",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
helper
accepting: aString expectingSource: aSourceString andPretty: aPrettyString

| browser source pretty |
browser := self getBrowser.
self setMethodContentsTo: aString of: browser using: #prettyPrint.
source := self getSourceContentOf: browser.
pretty := self getPrettyContentOf: browser.
self close: browser.
self assert: aSourceString equals: source.
self assert: aPrettyString equals: pretty
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
helper
close: aBrowser

self setMethodContentsTo: 'example

"This Method will be rewritten in PPSimulationTest"'
of: aBrowser
using: #source.
(aBrowser dependents at: 1) delete
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
helper
getBrowser

| browser |
browser := SystemBrowser default open.
browser selectClass: PPSimulationExample.
browser selectMessageNamed: #example.
^ browser
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
helper
getPrettyContentOf: aBrowser

aBrowser contentsSymbol: #prettyPrint.
aBrowser contents: nil.
^ aBrowser contents asString
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
helper
getSourceContentOf: aBrowser

aBrowser contentsSymbol: #source.
aBrowser contents: nil.
^ aBrowser contents asString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
helper
setMethodContentsTo: aString of: aBrowser using: aSymbol

aBrowser contentsSymbol: aSymbol.
(aBrowser dependents at: 18) textMorph contents: aString.
(aBrowser dependents at: 18) hasUnacceptedEdits: true.
(aBrowser dependents at: 18) accept
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
setUp-tearDown
setUp

super setUp.
PPFormatterConfig shouldUseDefaultAsPreferenceConfig: true.
prettyPrinterClassSource := (Behavior >> #prettyPrinterClass) getSourceFromFile string.
Behavior compile: 'prettyPrinterClass ^ PPFormatter'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setUp-tearDown
tearDown

[PPFormatterConfig shouldUseDefaultAsPreferenceConfig: false.
Behavior compile: prettyPrinterClassSource] ensure: [super tearDown]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests
testProjectVsPersonalizedConfig1

self accepting: 'example

{#a.#b.#c}' expectingSource: 'example

{#a . #b . #c}' andPretty: 'example

{#a. #b. #c}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests
testProjectVsPersonalizedConfig2

self accepting: 'example

''a'',''b'',''c''' expectingSource: 'example

''a'' , ''b'' , ''c''' andPretty: 'example

''a'', ''b'', ''c'''
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"class" : {
},
"instance" : {
"accepting:expectingSource:andPretty:" : "JW 7/25/2022 18:24",
"close:" : "JW 7/24/2022 19:57",
"getBrowser" : "JW 7/24/2022 19:00",
"getPrettyContentOf:" : "JW 7/24/2022 19:31",
"getSourceContentOf:" : "JW 7/24/2022 19:31",
"setMethodContentsTo:of:using:" : "JW 7/24/2022 19:33",
"setUp" : "JW 7/25/2022 18:23",
"tearDown" : "JW 7/25/2022 18:24",
"testProjectVsPersonalizedConfig1" : "JW 7/25/2022 13:40",
"testProjectVsPersonalizedConfig2" : "JW 7/25/2022 13:40" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "PoppyPrint-Tests",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"prettyPrinterClassSource" ],
"name" : "PPSimulationTest",
"pools" : [
],
"super" : "TestCase",
"type" : "normal" }