Skip to content

Commit

Permalink
Fixed issue with property & group names. Now hiphens & underscores in…
Browse files Browse the repository at this point in the history
… the names will be retained correctly
  • Loading branch information
thekalinga committed Feb 23, 2018
1 parent efa6afd commit ea70a54
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Since 0.8.0 (23 Feb 2017):

- Fixed issue with property & group names. Now hiphens & underscores in the names will be retained correctly

### Since 0.7.0 (13 Feb 2017):

- Fixed issue in per group dependency section. Deleting a selected now retains the previously selected group
Expand Down
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.vladsch.flexmark.ast.Document
import com.vladsch.flexmark.html.HtmlRenderer
import com.vladsch.flexmark.parser.Parser

version '0.7.0'
version '0.8.0'

buildscript {
apply plugin: 'groovy'
Expand All @@ -15,9 +15,12 @@ buildscript {
maven {
url 'http://dl.bintray.com/jetbrains/intellij-plugin-service'
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.3.0-SNAPSHOT"
classpath "gradle.plugin.org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.2.18"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1'
classpath 'org.codehaus.groovy:groovy-all:2.4.13'
classpath group: 'com.vladsch.flexmark', name: 'flexmark', version: '0.28.12'
Expand Down
2 changes: 1 addition & 1 deletion samples/gradle/single-project/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
springBootVersion = '2.0.0.M6'
springBootVersion = '2.0.0.RC2'
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,25 @@ public List<SuggestionNode> findDeepestSuggestionNode(Module module,
}

public void addChildren(Module module, SpringConfigurationMetadataGroup group,
String[] pathSegments, int startIndex, String belongsTo) {
String[] rawPathSegments, int startIndex, String belongsTo) {
MetadataNonPropertySuggestionNode groupNode =
addChildren(pathSegments, startIndex, pathSegments.length - 1, belongsTo);
addChildren(rawPathSegments, startIndex, rawPathSegments.length - 1, belongsTo);
groupNode.setGroup(module, group);
}

public void addChildren(SpringConfigurationMetadataProperty property, String[] pathSegments,
public void addChildren(SpringConfigurationMetadataProperty property, String[] rawPathSegments,
int startIndex, String belongsTo) {
MetadataNonPropertySuggestionNode parentNode;
// since last property is the actual property, lets only add children only till last but one
int endIndexIncl = pathSegments.length - 2;
int endIndexIncl = rawPathSegments.length - 2;
if (startIndex <= endIndexIncl) {
parentNode = addChildren(pathSegments, startIndex, endIndexIncl, belongsTo);
parentNode = addChildren(rawPathSegments, startIndex, endIndexIncl, belongsTo);
} else {
parentNode = this;
addRefCascadeTillRoot(belongsTo);
}

parentNode.addProperty(property, pathSegments[pathSegments.length - 1], belongsTo);
parentNode.addProperty(property, rawPathSegments[rawPathSegments.length - 1], belongsTo);
}

@Override
Expand Down Expand Up @@ -437,7 +437,7 @@ public void refreshClassProxy(Module module) {
}
}

private void addProperty(SpringConfigurationMetadataProperty property, String pathSegment,
private void addProperty(SpringConfigurationMetadataProperty property, String originalName,
String belongsTo) {
addRefCascadeTillRoot(belongsTo);
if (!hasChildren()) {
Expand All @@ -448,13 +448,14 @@ private void addProperty(SpringConfigurationMetadataProperty property, String pa
assert childLookup != null;
assert childrenTrie != null;
MetadataSuggestionNode childNode =
MetadataPropertySuggestionNode.newInstance(pathSegment, property, this, belongsTo);
MetadataPropertySuggestionNode.newInstance(originalName, property, this, belongsTo);

childLookup.put(pathSegment, childNode);
childrenTrie.put(pathSegment, childNode);
String name = SuggestionNode.sanitise(originalName);
childLookup.put(name, childNode);
childrenTrie.put(name, childNode);
}

private MetadataNonPropertySuggestionNode addChildren(String[] pathSegments, int startIndex,
private MetadataNonPropertySuggestionNode addChildren(String[] rawPathSegments, int startIndex,
int endIndexIncl, String belongsTo) {
addRefCascadeTillRoot(belongsTo);
if (!hasChildren()) {
Expand All @@ -465,11 +466,12 @@ private MetadataNonPropertySuggestionNode addChildren(String[] pathSegments, int
assert childLookup != null;
assert childrenTrie != null;

String pathSegment = pathSegments[startIndex];
String rawPathSegment = rawPathSegments[startIndex];
String pathSegment = SuggestionNode.sanitise(rawPathSegment);
MetadataNonPropertySuggestionNode childNode =
MetadataNonPropertySuggestionNode.class.cast(childLookup.get(pathSegment));
if (childNode == null) {
childNode = MetadataNonPropertySuggestionNode.newInstance(pathSegment, this, belongsTo);
childNode = MetadataNonPropertySuggestionNode.newInstance(rawPathSegment, this, belongsTo);
childNode.setParent(this);

childLookup.put(pathSegment, childNode);
Expand All @@ -480,7 +482,7 @@ private MetadataNonPropertySuggestionNode addChildren(String[] pathSegments, int
if (startIndex >= endIndexIncl) {
return childNode;
} else {
return childNode.addChildren(pathSegments, startIndex + 1, endIndexIncl, belongsTo);
return childNode.addChildren(rawPathSegments, startIndex + 1, endIndexIncl, belongsTo);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,19 @@ private void addPropertiesToIndex(Module module,
properties.sort(comparing(SpringConfigurationMetadataProperty::getName));
for (SpringConfigurationMetadataProperty property : properties) {
String[] pathSegments = toSanitizedPathSegments(property.getName());
String[] rawPathSegments = toRawPathSegments(property.getName());
MetadataSuggestionNode closestMetadata =
findDeepestMetadataMatch(rootSearchIndex, pathSegments, false);

int startIndex;
if (closestMetadata == null) { // path does not have a corresponding root element
String unsanitisedRootSegment = firstPathSegment(property.getName());
boolean onlyRootSegmentExists = pathSegments.length == 1;
if (onlyRootSegmentExists) {
closestMetadata = MetadataPropertySuggestionNode
.newInstance(unsanitisedRootSegment, property, null, containerArchiveOrFileRef);
.newInstance(rawPathSegments[0], property, null, containerArchiveOrFileRef);
} else {
closestMetadata = MetadataNonPropertySuggestionNode
.newInstance(unsanitisedRootSegment, null, containerArchiveOrFileRef);
.newInstance(rawPathSegments[0], null, containerArchiveOrFileRef);
}
rootSearchIndex.put(pathSegments[0], closestMetadata);

Expand All @@ -523,12 +523,12 @@ private void addPropertiesToIndex(Module module,
startIndex = closestMetadata.numOfHopesToRoot() + 1;
}

boolean haveMoreSegmentsLeft = startIndex < pathSegments.length;
boolean haveMoreSegmentsLeft = startIndex < rawPathSegments.length;

if (haveMoreSegmentsLeft) {
if (!closestMetadata.isProperty()) {
MetadataNonPropertySuggestionNode.class.cast(closestMetadata)
.addChildren(property, pathSegments, startIndex, containerArchiveOrFileRef);
.addChildren(property, rawPathSegments, startIndex, containerArchiveOrFileRef);
} else {
log.warn("Detected conflict between a new group & existing property for suggestion path "
+ closestMetadata.getPathFromRoot(module)
Expand Down Expand Up @@ -562,17 +562,18 @@ private void addGroupsToIndex(Module module, Trie<String, MetadataSuggestionNode
groups.sort(comparing(SpringConfigurationMetadataGroup::getName));
for (SpringConfigurationMetadataGroup group : groups) {
String[] pathSegments = toSanitizedPathSegments(group.getName());
String[] rawPathSegments = toRawPathSegments(group.getName());

MetadataSuggestionNode closestMetadata = MetadataSuggestionNode.class
.cast(findDeepestMetadataMatch(rootSearchIndex, pathSegments, false));

int startIndex;
if (closestMetadata == null) { // path does not have a corresponding root element
// lets build just the root element. Rest of the path segments will be taken care of by the addChildren method
String unsanitisedRootSegment = firstPathSegment(group.getName());
boolean onlyRootSegmentExists = pathSegments.length == 1;
MetadataNonPropertySuggestionNode newGroupSuggestionNode =
MetadataNonPropertySuggestionNode
.newInstance(unsanitisedRootSegment, null, containerArchiveOrFileRef);
.newInstance(rawPathSegments[0], null, containerArchiveOrFileRef);
if (onlyRootSegmentExists) {
newGroupSuggestionNode.setGroup(module, group);
}
Expand All @@ -598,10 +599,10 @@ private void addGroupsToIndex(Module module, Trie<String, MetadataSuggestionNode
MetadataNonPropertySuggestionNode.class.cast(closestMetadata);
groupSuggestionNode.addRefCascadeTillRoot(containerArchiveOrFileRef);

boolean haveMoreSegmentsLeft = startIndex < pathSegments.length;
boolean haveMoreSegmentsLeft = startIndex < rawPathSegments.length;
if (haveMoreSegmentsLeft) {
groupSuggestionNode
.addChildren(module, group, pathSegments, startIndex, containerArchiveOrFileRef);
.addChildren(module, group, rawPathSegments, startIndex, containerArchiveOrFileRef);
} else {
// Node is an intermediate node that has neither group nor property assigned to it, lets assign this group to it
// Can happen when `a.b.c` is already added to the metadata tree from an earlier metadata source & now we are trying to add a group for `a.b`
Expand Down

0 comments on commit ea70a54

Please sign in to comment.