[MDSAL-52] Binding Java API Generator -> doesn't handle non-alphabetic signs in names of enum constants, allowed by rfc6020 though Created: 06/Nov/14  Updated: 09/Mar/18  Resolved: 26/Apr/17

Status: Resolved
Project: mdsal
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Martin Ciglan Assignee: Jakub Toth
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Issue Links:
Blocks
is blocked by MDSAL-40 Milestone: Implement Binding Specific... Resolved
Duplicate
is duplicated by YANGTOOLS-599 Yangtools produces non-compilable cod... Resolved
External issue ID: 2332

 Description   

Binding Java API Generator doesn't handle non-alphabetic signs in names of enum constants, allowed by rfc6020 though.

As an output of this issue, we're not able to compile generated code.



 Comments   
Comment by Martin Ciglan [ 11/Nov/14 ]

I am adding some kind of proposal how should we handle this issue.

public class NonAlphabeticHandler {

//give occurence enum constants meanings
private static final String ASTERISK_PATTERN = "
*";
private static final String ASTERISK_REPLACEMENT = "_OccurenceZeroOrMultipleTimes";

private static final String PLUS_PATTERN = "
+";
private static final String PLUS_REPLACEMENT = "_OccurenceAtLeastOnce";

private static final String ONE_PATTERN = "1";
private static final String ONE_REPLACEMENT = "_OccurenceExactlyOnce";

private static final String QUESTIONMARK_PATTERN = "
?";
private static final String QUESTIONMARK_REPLACEMENT = "_OccurenceZeroOrOneTime";

//might get deleted and be part of generic one, detected it in name of protocol
private static final String COLON_PATTERN = ":";
private static final String COLON_REPLACEMENT = "_Colon";

private static final String GENERIC_PATTERN = "[^A-Za-z0-9]";
private static final String GENERIC_REPLACEMENT = "_GenericNonAlpha";

/**

  • This static method takes className as an input argument and looks for non-alphabetic signs in it.
  • It aims to replace them in order to get valid Java class names and be able to compile them.
  • Indicate by underscore sign ('_') that replacement has been made up.
  • I propose to give meaning to replacements to mimic occurence enum constants names like '*', '?', '+', etc...
  • Test implementation with various inputs to see coverage area and performance.
  • @param className
  • @return className
    */
    public static String getValidClassName(String className) { String backup = className; className = className.replaceAll(ASTERISK_PATTERN, ASTERISK_REPLACEMENT); if (!className.equals(backup)) return className; className = className.replaceAll(COLON_PATTERN, COLON_REPLACEMENT); if (!className.equals(backup)) return className; className = className.replaceAll(PLUS_PATTERN, PLUS_REPLACEMENT); if (!className.equals(backup)) return className; className = className.replaceAll(ONE_PATTERN, ONE_REPLACEMENT); if (!className.equals(backup)) return className; className = className.replaceAll(QUESTIONMARK_PATTERN, QUESTIONMARK_REPLACEMENT); if (!className.equals(backup)) return className; className = className.replaceAll(GENERIC_PATTERN, GENERIC_REPLACEMENT); if (!className.equals(backup)) return className; return className; }

public static void main(String[] args) {
String className = "+";

System.out.public class NonAlphabeticHandler {println(System.currentTimeMillis());
System.out.println(className + " -> " + NonAlphabeticHandler.getValidClassName(className));
System.out.println(System.currentTimeMillis() + "\n");

className = "Tdp:";

System.out.println(System.currentTimeMillis());
System.out.println(className + " -> " + NonAlphabeticHandler.getValidClassName(className));
System.out.println(System.currentTimeMillis() + "\n")
.

.
.
.
}

Note: Not sure about nonalphabetic signs, which are part of words like device names, perhaps Device+ -> Device_Plus would be more reasonable. Of course, it's matter of discussion in team.

Comment by Martin Ciglan [ 20/Jan/15 ]

in very first draft phase

Comment by Ryan Goulding [ 06/Apr/16 ]

Hi Martin,

I see that you actively have "taken" this one... is that still applicable? If not, please let me know so that I can take a look.

Thanks,
Ryan

Comment by Martin Ciglan [ 06/Apr/16 ]

Hi Ryan

This is one of several bugs, which we have identified during work with binding specification version 1. This issue depends on implementation of binding specification version 2, please see
https://bugs.opendaylight.org/show_bug.cgi?id=1411

So, once 1411 is resolved, this should get resolved too. I hope that helps.

Martin

Comment by Vratko Polak [ 04/Jul/16 ]

Java binding v2 will not be ported to Beryllium, as far as I know.

In the meantime, it is possible to somewhat reduce severity of this Bug.
https://git.opendaylight.org/gerrit/41280

Comment by Vratko Polak [ 22/Aug/16 ]

> it is possible to somewhat reduce severity

Merged to master (Boron and Carbon): https://git.opendaylight.org/gerrit/41280

Waiting for review for Beryllium: https://git.opendaylight.org/gerrit/44481

Comment by Vratko Polak [ 26/Sep/16 ]

> Beryllium: https://git.opendaylight.org/gerrit/44481

The workaround is now merged. Other characters aside slash have to be handled separately (possibly only in Java binding v2).

Comment by Jakub Toth [ 30/Jan/17 ]

https://git.opendaylight.org/gerrit/#/c/51132/

Generated at Wed Feb 07 20:08:31 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.