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

Add Properties PBXFileElement #244

Merged
merged 11 commits into from
Mar 15, 2018
Merged

Add Properties PBXFileElement #244

merged 11 commits into from
Mar 15, 2018

Conversation

briantkelley
Copy link
Contributor

@briantkelley briantkelley commented Mar 7, 2018

Short description 📝

PBXFileReference and PBXGroup share many properties. Consolidate them in PBXFileElement and add additional unique properties to PBXFileReference.

Solution 📦

Refactor the PBXFileReference.includeInIndex, PBXGroup.usesTabs, PBXGroup.indentWidth, PBXGroup.tabWidth properties so they're implemented in PBXFileReference so they can be shared by both subclasses. Add PBXFileElement.wrapsLines, PBXFileReference.languageSpecificationIdentifier, and PBXFileReference.plistStructureDefinitionIdentifier.

Implementation 👩‍💻👨‍💻

  • Add PBXFileElement.wrapsLines property and parameters to the PBXFileElement, PBXFileReference, and PBXGroup initializers.
  • Move includeInIndex from PBXFileReference to PBXFileElement and add parameters to the PBXFileElement and PBXGroup initializers.
  • Move usesTabs from PBXGroup to PBXFileElement and add parameters to the PBXFileElement and PBXFileReference initializers.
  • Move indentWidth from PBXGroup to PBXFileElement and add parameters to the PBXFileElement and PBXFileReference initializers.
  • Move tabWidth from PBXGroup to PBXFileElement and add parameters to the PBXFileElement and PBXFileReference initializers.
  • Add languageSpecificationIdentifier and plistStructureDefinitionIdentifier to PBXFileReference and parameters to its initializer.
  • Simplify PBXFileReference.isEqual(to:) and PBXGroup.isEqual(to:) only compare properties the class implements.

This change does not remove any properties or initializer parameters on PBXGroup or PBXFileElement, so source compatibility should be maintained.


This change is Reviewable

// MARK: - Init

/// Initializes the file element with its properties.
///
/// - Parameters:
/// - sourceTree: file source tree.
/// - name: file name.
/// - usesTabs: group uses tabs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation comments doesn't seem to match the parameters the constructor takes.

@@ -25,19 +16,26 @@ final public class PBXGroup: PBXFileElement {
/// - sourceTree: group source tree.
/// - name: group name.
/// - path: group path.
/// - wrapsLines: should the IDE wrap lines for files in the group?
/// - usesTabs: group uses tabs.
public init(children: [String],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Would you mind adding them? 😬
I'll go through all the files on the project and make sure they are properly documented.

Copy link
Contributor

@pepicrft pepicrft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments. Good idea to abstract those properties into the PBXFileElement class. There's something that I keep noticing and is the need of automating the equatable conformance and the constructors using something like Sourcery. As the models grow, it's very easy to introduce a bug in there (and you already found some in the code base).

@yonaskolb
Copy link
Collaborator

Are these new properties in PBXFileElement also applicable to the other subclasses? I can’t look them up right now, but I believe variant group is one

@briantkelley
Copy link
Contributor Author

Good point @yonaskolb. I forgot to consider other subclasses. It seems Xcode implements the following properties in PBXReference:

  • path
  • name
  • includeInIndex
  • usesTabs
  • indentWidth
  • tabWidth
  • wrapsLines

PBXReference is the super class of both PBXFileReference and PBXGroup.

PBXGroup is the super class of both PBXVariantGroup and XCVersionGroup.

Those are the four classes in xcproj that directly or indirectly inherit from PBXFileElement so the change seems to be the correct behavior for all affected classes. But, given the new information, I'll also refactor PBXVariantGroup and XCVersionGroup to inherit from PBXGroup, which will simplify both.

@briantkelley briantkelley force-pushed the pbxfileelement-props branch from b9adf41 to 58c5a8d Compare March 8, 2018 22:33
@yonaskolb
Copy link
Collaborator

It seems PBXReference also inherrits from PBXContainerItem

@yonaskolb
Copy link
Collaborator

Though I’m not sure what it gets for that. A comment property? Where is that set?

@briantkelley briantkelley force-pushed the pbxfileelement-props branch from 58c5a8d to cffad76 Compare March 9, 2018 01:06
@briantkelley
Copy link
Contributor Author

We didn't have any instances of comments for these family of elements in our codebase, and I'm sure the UI for it has been removed if it ever existed. I can rebase this on top of #243 to set PBXContainerItem as the super class of PBXFileElement if you'd like.

Both PBXGroup and PBXFileReference support a wrapsLines property. Add support for unarchiving and archiving it from Xcode projects to prevent data loss.
Both PBXFileReference and PBXGroup may have the includeInIndex property, so move it from PBXFileReference to PBXFileElement so it can be shared by both classes.
Both PBXFileReference and PBXGroup implemented the usesTabs property. Extract it to the base class so both can share the same implementation.
PBXGroup implemented the indentWidth property. Extract it to the base class so it can be shared with PBXFileReference, which also supports the property.
PBXGroup implemented the tabWidth property. Extract it to the base class so it can be shared with PBXFileReference, which also supports the property.
Remove equality checks from the isEqual(to:) implementation that’s performed by the superclass. Now PBXFileReference and PBXGroup only check their unique properties.
Add some additional properties discovered while round tripping some Xcode projects through xcproj. There’s languageSpecificationIdentifier, which is different than xcLanguageSpecificationIdentifier, and plistStructureDefinitionIdentifier.
Refactor PBXVariantGroup so it’s a subclass of PBXGroup instead of PBXFileElement, better modeling the way Xcode handles this type.
Refactor XCVersionGroup so it’s a subclass of PBXGroup instead of PBXFileElement, better modeling the way Xcode handles this type.
Update PBXFileElement to be a subclass of PBXContainerItem to better reflect Xcode’s model, which also adds support for the comments property.
@briantkelley
Copy link
Contributor Author

Thanks everyone!

@briantkelley briantkelley merged commit 2d80b77 into master Mar 15, 2018
@pepicrft pepicrft deleted the pbxfileelement-props branch March 16, 2018 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants