Commit ef795f3c authored by Lionel Seinturier's avatar Lionel Seinturier

Move more utility methods to StringHelper.

Sort helper methods.
parent 48819537
...@@ -72,6 +72,7 @@ import org.objectweb.fractal.juliac.Juliac; ...@@ -72,6 +72,7 @@ import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.api.ADLParserSupportItf; import org.objectweb.fractal.juliac.api.ADLParserSupportItf;
import org.objectweb.fractal.juliac.api.FCSourceCodeGeneratorItf; import org.objectweb.fractal.juliac.api.FCSourceCodeGeneratorItf;
import org.objectweb.fractal.juliac.api.TypeGeneratorItf; import org.objectweb.fractal.juliac.api.TypeGeneratorItf;
import org.objectweb.fractal.juliac.commons.lang.StringHelper;
import org.objectweb.fractal.juliac.conf.JuliacConfig; import org.objectweb.fractal.juliac.conf.JuliacConfig;
import org.objectweb.fractal.juliac.desc.AttributeDesc; import org.objectweb.fractal.juliac.desc.AttributeDesc;
import org.objectweb.fractal.juliac.desc.BindingDesc; import org.objectweb.fractal.juliac.desc.BindingDesc;
...@@ -418,7 +419,16 @@ public class EMFParserSupportImpl implements ADLParserSupportItf { ...@@ -418,7 +419,16 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
String serviceName = service.getName(); String serviceName = service.getName();
String promote = service.getPromote(); String promote = service.getPromote();
String[] promotes = Util.splitAroundFirstSplash(promote);
/*
* I was previously using String#split("/"). Yet component-based
* membranes define interfaces such as //binding-controller. Referencing
* such component interfaces gives something like
* BC///binding-controller which makes String#split("/") no longer
* appropriate.
*/
String[] promotes = StringHelper.around(promote,'/');
if( promotes.length != 2 ) { if( promotes.length != 2 ) {
final String msg = final String msg =
"Illegal service promotion "+promote+" in composite "+ "Illegal service promotion "+promote+" in composite "+
...@@ -446,7 +456,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf { ...@@ -446,7 +456,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
String promote = reference.getPromote(); String promote = reference.getPromote();
String[] promotes = promote.split(" "); String[] promotes = promote.split(" ");
for (String pr : promotes) { for (String pr : promotes) {
String[] prs = Util.splitAroundFirstSplash(pr); String[] prs = StringHelper.around(pr,'/');
if( prs.length != 2 ) { if( prs.length != 2 ) {
final String msg = final String msg =
"Illegal reference promotion "+promote+" in composite "+ "Illegal reference promotion "+promote+" in composite "+
...@@ -472,7 +482,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf { ...@@ -472,7 +482,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
// Wire source // Wire source
String source = wire.getSource(); String source = wire.getSource();
String[] sources = Util.splitAroundFirstSplash(source); String[] sources = StringHelper.around(source,'/');
if( sources.length != 2 ) { if( sources.length != 2 ) {
final String msg = "Illegal source '"+source+"' in wire "+wire; final String msg = "Illegal source '"+source+"' in wire "+wire;
throw new IOException(msg); throw new IOException(msg);
...@@ -501,7 +511,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf { ...@@ -501,7 +511,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
// Wire target // Wire target
String target = wire.getTarget(); String target = wire.getTarget();
String[] targets = Util.splitAroundFirstSplash(target); String[] targets = StringHelper.around(target,'/');
if( targets.length != 2 ) { if( targets.length != 2 ) {
final String msg = "Illegal target '"+target+"' in wire "+wire; final String msg = "Illegal target '"+target+"' in wire "+wire;
throw new IOException(msg); throw new IOException(msg);
...@@ -576,7 +586,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf { ...@@ -576,7 +586,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
cltItfName += i; cltItfName += i;
} }
String[] targs = Util.splitAroundFirstSplash(targ); String[] targs = StringHelper.around(targ,'/');
if( targs.length != 2 ) { if( targs.length != 2 ) {
final String msg = final String msg =
"Illegal reference "+target+" in composite "+ "Illegal reference "+target+" in composite "+
......
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2011-2015 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi.emf;
/**
* Utility class.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.4.5
*/
public class Util {
/**
* Split the specified string using the first encountered slash character as
* a delimiter and return the substrings before and after in an array of
* size 2. If there is no such slash character, return an array of size 0.
*
* @param str the input string
* @return the array
*/
public static String[] splitAroundFirstSplash( String str ) {
/*
* I was previously using String#split("/"). Yet component-based
* membranes define interfaces such as //binding-controller. Referencing
* such component interfaces gives something like
* BC///binding-controller which makes String#split("/") no longer
* appropriate.
*/
int slash = str.indexOf('/');
if( slash == -1 ) {
return new String[0];
}
String[] ret = new String[2];
ret[0] = str.substring(0,slash);
ret[1] = str.substring(slash+1);
return ret;
}
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2011-2015 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi.emf;
import org.junit.Assert;
import org.junit.Test;
/**
* Class for testing the functionalities of the {@link Util} class.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.4.5
*/
public class UtilTestCase {
@Test
public void testSplitAroundFirstSplash() {
Assert.assertArrayEquals(
new String[0],
Util.splitAroundFirstSplash("noslash"));
Assert.assertArrayEquals(
new String[]{"before","after"},
Util.splitAroundFirstSplash("before/after"));
Assert.assertArrayEquals(
new String[]{"before","//after"},
Util.splitAroundFirstSplash("before///after"));
Assert.assertArrayEquals(
new String[]{"","//after"},
Util.splitAroundFirstSplash("///after"));
Assert.assertArrayEquals(
new String[]{"before",""},
Util.splitAroundFirstSplash("before/"));
}
}
...@@ -38,7 +38,7 @@ import org.objectweb.fractal.juliac.UClass; ...@@ -38,7 +38,7 @@ import org.objectweb.fractal.juliac.UClass;
import org.objectweb.fractal.juliac.api.TypeGeneratorItf; import org.objectweb.fractal.juliac.api.TypeGeneratorItf;
import org.objectweb.fractal.juliac.commons.lang.ClassHelper; import org.objectweb.fractal.juliac.commons.lang.ClassHelper;
import org.objectweb.fractal.juliac.commons.lang.annotation.AnnotationHelper; import org.objectweb.fractal.juliac.commons.lang.annotation.AnnotationHelper;
import org.objectweb.fractal.juliac.commons.lang.reflect.MethodHelper; import org.objectweb.fractal.juliac.commons.lang.reflect.AnnotatedElementHelper;
import org.objectweb.fractal.juliac.desc.MembraneDesc; import org.objectweb.fractal.juliac.desc.MembraneDesc;
import org.objectweb.fractal.juliac.helper.InterfaceTypeHelper; import org.objectweb.fractal.juliac.helper.InterfaceTypeHelper;
import org.objectweb.fractal.juliac.proxy.AbstractProxyClassGenerator; import org.objectweb.fractal.juliac.proxy.AbstractProxyClassGenerator;
...@@ -190,7 +190,7 @@ extends AbstractProxyClassGenerator { ...@@ -190,7 +190,7 @@ extends AbstractProxyClassGenerator {
conversationalItf = proxycl.getAnnotation(Conversational.class); conversationalItf = proxycl.getAnnotation(Conversational.class);
oneWayMeth = oneWayMeth =
MethodHelper.getAnnotation( AnnotatedElementHelper.getAnnotation(
proxym, proxym,
OneWay.class.getName(), OneWay.class.getName(),
"org.osoa.sca.annotations.OneWay"); "org.osoa.sca.annotations.OneWay");
......
...@@ -56,6 +56,7 @@ import org.objectweb.fractal.juliac.commons.lang.ClassHelper; ...@@ -56,6 +56,7 @@ import org.objectweb.fractal.juliac.commons.lang.ClassHelper;
import org.objectweb.fractal.juliac.commons.lang.annotation.AnnotationHelper; import org.objectweb.fractal.juliac.commons.lang.annotation.AnnotationHelper;
import org.objectweb.fractal.juliac.commons.lang.reflect.AccessibleObjectHelper; import org.objectweb.fractal.juliac.commons.lang.reflect.AccessibleObjectHelper;
import org.objectweb.fractal.juliac.commons.lang.reflect.AnnotatedElementFilter; import org.objectweb.fractal.juliac.commons.lang.reflect.AnnotatedElementFilter;
import org.objectweb.fractal.juliac.commons.lang.reflect.AnnotatedElementHelper;
import org.objectweb.fractal.juliac.commons.lang.reflect.MethodHelper; import org.objectweb.fractal.juliac.commons.lang.reflect.MethodHelper;
import org.objectweb.fractal.juliac.commons.util.function.CompositeOrFilter; import org.objectweb.fractal.juliac.commons.util.function.CompositeOrFilter;
import org.objectweb.fractal.juliac.commons.util.function.Filter; import org.objectweb.fractal.juliac.commons.util.function.Filter;
...@@ -342,7 +343,7 @@ public class ContentClassMetaData { ...@@ -342,7 +343,7 @@ public class ContentClassMetaData {
controllerAnnotatedElements = new InjectionPoint[ aos.length ]; controllerAnnotatedElements = new InjectionPoint[ aos.length ];
for (int i = 0; i < aos.length; i++) { for (int i = 0; i < aos.length; i++) {
Annotation annot = Annotation annot =
AccessibleObjectHelper.getAnnotation( aos[i], Controller.class.getName() ); AnnotatedElementHelper.getAnnotation( aos[i], Controller.class.getName() );
controllerAnnotatedElements[i] = controllerAnnotatedElements[i] =
InjectionPointImpl.getInjectionPoint(aos[i],annot); InjectionPointImpl.getInjectionPoint(aos[i],annot);
} }
...@@ -423,7 +424,7 @@ public class ContentClassMetaData { ...@@ -423,7 +424,7 @@ public class ContentClassMetaData {
callbacks = new InjectionPoint[ aos.length ]; callbacks = new InjectionPoint[ aos.length ];
for (int i = 0; i < aos.length; i++) { for (int i = 0; i < aos.length; i++) {
Annotation annot = Annotation annot =
AccessibleObjectHelper.getAnnotation( AnnotatedElementHelper.getAnnotation(
aos[i], aos[i],
Callback.class.getName(), Callback.class.getName(),
"org.osoa.sca.annotations.Callback"); "org.osoa.sca.annotations.Callback");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment