blob: 57dcb2f419d3cd6a3f60184d8dce8d10c7fde875 [file] [log] [blame]
[comment encoding = UTF-8 /]
[comment
/*******************************************************************************
* Copyright (c) 2014 Jad El-khoury.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Jad El-khoury - initial implementation of code generator (https://bugs.eclipse.org/bugs/show_bug.cgi?id=422448)
*
*******************************************************************************/
/]
[module services('http://org.eclipse.lyo/oslc4j/adaptorInterface')/]
[query private javaKeywords(traceabilityContext : OclAny) : Set(String) =
Set{'abstract', 'continue', 'for', 'new', 'switch', 'assert', 'default', 'goto', 'package', 'synchronized', 'boolean', 'do',
'if', 'private', 'this', 'break', 'double', 'implements', 'protected', 'throw', 'byte', 'else', 'import', 'public', 'throws',
'case', 'enum', 'instanceof', 'return', 'transient', 'catch', 'extends', 'int', 'short', 'try', 'char', 'final', 'interface',
'static', 'void', 'class', 'finally', 'long', 'strictfp', 'volatile', 'const', 'float', 'native', 'super', 'while'}
/]
[query private javaLangWords(traceabilityContext : OclAny) : Set(String) =
Set{'appendable', 'autocloseable', 'charsequence', 'cloneable', 'comparable', 'iterable', 'readable', 'runnable', 'thread',
'boolean', 'byte', 'character', 'class', 'classloader', 'classvalue', 'compiler', 'double', 'enum', 'float',
'inheritablethreadlocal', 'integer', 'long', 'math', 'number', 'object', 'package', 'process', 'processbuilder',
'runtime', 'runtimepermission', 'securitymanager', 'short', 'stacktraceelement', 'strictmath', 'string', 'stringbuffer',
'stringbuilder', 'system', 'thread', 'threadgroup', 'threadlocal', 'throwable', 'void'}
/]
[query private isJavaSpecialWord(aString : String) : Boolean =
((javaKeywords(aString)->union(javaLangWords(aString)))->includes(aString.toLower()))
/]
[query public javaClassBaseNamespace(anAdaptorInterface : AdaptorInterface) : String =
anAdaptorInterface.javaClassBaseNamespace
/]
[query public javaFilesBasePath(anAdaptorInterface : AdaptorInterface) : String =
anAdaptorInterface.javaFilesBasePath
/]
[query public jspFilesBasePath(anAdaptorInterface : AdaptorInterface) : String =
anAdaptorInterface.jspFilesBasePath
/]
[query public javascriptFilesBasePath(anAdaptorInterface : AdaptorInterface) : String =
anAdaptorInterface.javascriptFilesBasePath
/]
[query public jspFilesWebappPath(anAdaptorInterface : AdaptorInterface) : String =
'/'.concat(javaClassBaseNamespace(anAdaptorInterface)).substituteAll('.', '/')
/]
[query public methodSignature(parameters: Sequence(String), forJAXRSMethod : Boolean) : String =
concatenate(
parameters->collect(aParameter: String |
(if (forJAXRSMethod) then
'@PathParam("'.concat(aParameter).concat('") final String ').concat(aParameter)
else
'final String '.concat(aParameter)
endif)
)->sep(', ').oclAsType(String))
/]
[query public methodParameterList(parameters: Sequence(String)) : String =
concatenate(parameters->sep(', ').oclAsType(String))
/]
[query public JAXRSPathAnnotation(pathAnnotation : String) : String =
(if (pathAnnotation.size() >= 1) then
'@Path("'.concat(pathAnnotation).concat('")')
else
''
endif)
/]
[query public JAXRSPathParameters(uriSegment : String) : Sequence(String) =
uriSegment.tokenize('}')
->select(token : String | token.index('{') <> -1)
->collect(token : String | token.substring(token.index('{')+1))
/]
[query private stripURISegmentEnd(URISegment : String) : String =
(if (URISegment.size() = 0) then
URISegment
else
(if (URISegment.size() = 1) then
(if (URISegment.endsWith('/')) then '' else URISegment endif)
else
URISegment.substring(1, URISegment.size()-(if (URISegment.endsWith('/')) then 1 else 0 endif))
endif)
endif)
/]
[query private stripURISegmentStart(URISegment : String) : String =
(if (URISegment.size() = 0) then
URISegment
else
(if (URISegment.size() = 1) then
(if (URISegment.startsWith('/')) then '' else URISegment endif)
else
URISegment.substring((if (URISegment.startsWith('/')) then 2 else 1 endif), URISegment.size())
endif)
endif)
/]
[query public JAXRSConcatURISegments(leftURISegment : String, rightURISegment : String) : String =
concatenatePaths(leftURISegment, rightURISegment)
/]
[query public concatenatePaths (leftSegment : String, rightSegment : String) : String =
(if (stripURISegmentEnd(leftSegment).size() = 0) then
stripURISegmentStart(rightSegment)
else
(if (stripURISegmentStart(rightSegment).size() = 0) then
stripURISegmentEnd(leftSegment)
else
stripURISegmentEnd(leftSegment).concat('/').concat(stripURISegmentStart(rightSegment))
endif)
endif)
/]
[query public commaSeparate(commaSeparatedString : String, prependIfNotEmpty : Boolean, appendIfNotEmpty : Boolean) : String =
(if prependIfNotEmpty._and(commaSeparatedString.size() > 0) then ', ' else ''endif)
.concat(commaSeparatedString)
.concat(
(if appendIfNotEmpty._and(commaSeparatedString.size() > 0) then ' ,' else ''endif)
)
/]
[query public javaSimpleStringFromUri(uriString: String, toUpperFirst : Boolean) : String =
javaString(uriString.tokenize('/\\#')->last(), '', toUpperFirst)
/]
[query public javaConstantString (aString : String) : String =
concatenate(
aString.replaceAll('\\W+', '_').tokenize('_')->sep('_').oclAsType(String)
).toUpperCase()
/]
[query private javaString (aString : String) : String =
concatenate(
aString.replaceAll('\\W+', ' ').tokenize(' ')->collect(s : String | s.toUpperFirst())
)
/]
[query public javaString (aString : String, prefixIfNecessary : String, toUpperFirst : Boolean) : String =
let base : String = (if (isJavaSpecialWord(aString)) then prefixIfNecessary.concat(javaString(aString).toUpperFirst()) else javaString(aString) endif)
in
if (toUpperFirst) then base.toUpperFirst() else base.toLowerFirst() endif
/]
[query public concatenate (aStringSequence : Sequence(String)) : String =
(if (aStringSequence->size() = 0) then
''
else
(if (aStringSequence->size() = 1) then
aStringSequence->at(1)
else
(if (aStringSequence->size() = 2) then
aStringSequence->at(1).concat(aStringSequence->at(2))
else
aStringSequence->at(1).concat(aStringSequence->at(2)).concat(concatenate(aStringSequence->subSequence(3, aStringSequence->size())))
endif)
endif)
endif)
/]
[query public concatenate (aStringSequence : Sequence(String), separatorString : String) : String =
concatenate(aStringSequence->sep(separatorString).oclAsType(String))
/]
[query public isNullOrEmpty (aString : String) : Boolean =
(aString.oclIsUndefined())._or(aString.trim().equalsIgnoreCase(''))
/]