List of usage examples for org.apache.commons.lang ArrayUtils indexOf
public static int indexOf(boolean[] array, boolean valueToFind)
Finds the index of the given value in the array.
From source file:padl.creator.classfile.AbstractClassFileCreator.java
public List recognizeConstructor(final List aListOfSubmittedConstituents, final ICodeLevelModel aCodeLevelModel) { final List notRecognized = new ArrayList(); final Iterator iterator = aListOfSubmittedConstituents.iterator(); while (iterator.hasNext()) { final Object element = iterator.next(); if (element instanceof ExtendedMethodInfo) { ExtendedMethodInfo currentExtendedMethod = (ExtendedMethodInfo) element; // Yann 2004/03/28: Constructors. // If the method is a constructor, I take care // of giving it the proper name and return type. final char[] name = currentExtendedMethod.getName(); // Yann 2005/08/15: Inner classes! // I now manage inner and anonymous classes... // if (Utils.isSpecialMethod(name) // && !Misc.isAnonymousClass( // currentExtendedMethod.getDeclaringClassName())) { if (Utils.isSpecialMethod(name)) { final IConstructor currentConstructor = aCodeLevelModel.getFactory().createConstructor( Utils.computeSignature(currentExtendedMethod), Util.computeSimpleName(currentExtendedMethod.getDeclaringClassName())); currentConstructor.setVisibility(currentExtendedMethod.getVisibility()); final char[][] detectedParameters = currentExtendedMethod.getParameters(); for (int i = 0; i < detectedParameters.length; i++) { // Yann 2004/01/25: Arrays and primitive types! // I must be careful with arrays (remove the // brackets) and primitive types (do not attempt // to create a Ghost from them). // Yann 2009/05/02: No String anymore! // Cool, eh? char[] paramType = detectedParameters[i]; int cardinality = 1; final int bracketIndex = ArrayUtils.indexOf(paramType, '['); if (bracketIndex > -1) { cardinality = (paramType.length - bracketIndex) / 2 + 1; paramType = ArrayUtils.subarray(paramType, 0, bracketIndex); }//from ww w.j a va2s . c o m final IParameter parameter = this.createParameter(aCodeLevelModel, paramType, cardinality); currentConstructor.addConstituent(parameter); } // Yann 2005/12/29: Duplicate... // Actually, the RelationshipAnalyser might already have created // a method in an entity if this method was called from another // entity. Thus, there would be an attempt to add a "duplicate" // element, which is legitimate but taken care of by the new condition. final IFirstClassEntity firstClassEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel, currentExtendedMethod.getDeclaringClassName(), this.mapOfIDsEntities); if (!firstClassEntity.doesContainConstituentWithID(currentConstructor.getID())) { firstClassEntity.addConstituent(currentConstructor); } } } else { notRecognized.add(element); // This is not a method, next... } } return notRecognized; }
From source file:padl.creator.classfile.AbstractClassFileCreator.java
public List recognizeField(final List aListOfSubmittedConstituents, final ICodeLevelModel aCodeLevelModel) { final List notRecognized = new ArrayList(); final Iterator enumarator = aListOfSubmittedConstituents.iterator(); while (enumarator.hasNext()) { final Object element = enumarator.next(); if (element instanceof ExtendedFieldInfo) { final ExtendedFieldInfo currentField = (ExtendedFieldInfo) element; char[] fieldType = currentField.getType(); final int cardinality = Util.isArrayOrCollection(fieldType) ? Constants.CARDINALITY_MANY : Constants.CARDINALITY_ONE; // Yann 2003/11/29: Array! // I must take care of removing brackets for array. int index; if ((index = ArrayUtils.indexOf(fieldType, '[')) == -1) { index = fieldType.length; }/* w w w .j a va 2s .c o m*/ fieldType = ArrayUtils.subarray(fieldType, 0, index); // Yann 2002/08/01: Ghost! // From now on, if an entity cannot be found in the // list of entities, I create a ghost for it... // Yann 2003/11/29: Primitive type. // I must take care not to add primitive type. final IField field; if (Util.isPrimtiveType(fieldType)) { field = aCodeLevelModel.getFactory().createField(currentField.getName(), currentField.getName(), fieldType, cardinality); } else { final IFirstClassEntity targetEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel, fieldType, this.mapOfIDsEntities); // Yann 2006/02/08: Members! // The getConstituentFromID() method takes care of members and ghosts... // if (targetEntity == null // && !Utils.isAnonymousEntity(fieldType)) { // // targetEntity = // aCodeLevelModel.getFactory().createGhost( // fieldType); // aCodeLevelModel.addConstituent(targetEntity); // } field = aCodeLevelModel.getFactory().createField(currentField.getName(), currentField.getName(), targetEntity.getID(), cardinality); } field.setVisibility(currentField.getVisibility()); final IFirstClassEntity firstClassEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel, currentField.getDeclaringClassName(), this.mapOfIDsEntities); firstClassEntity.addConstituent(field); } else { // this is not a field, next ... notRecognized.add(element); } } return notRecognized; }
From source file:padl.creator.classfile.AbstractClassFileCreator.java
public List recognizeMethod(final List aListOfSubmittedConstituents, final ICodeLevelModel aCodeLevelModel) { final List notRecognized = new ArrayList(); final Iterator iterator = aListOfSubmittedConstituents.iterator(); while (iterator.hasNext()) { final Object element = iterator.next(); if (element instanceof ExtendedMethodInfo) { ExtendedMethodInfo currentExtendedMethod = (ExtendedMethodInfo) element; // Yann 2004/03/28: Constructors. // If the method is a constructor, I take care // of giving it the proper name and return type. final char[] name = currentExtendedMethod.getName(); if (!Utils.isSpecialMethod(name)) { final IMethod currentMethod = aCodeLevelModel.getFactory() .createMethod(Utils.computeSignature(currentExtendedMethod), name); // Farouk 2004/02/19: Constituent ID. // The method makeSignature is the new way to give an // actor ID to a method, instead of using toString() // from MethodInfo. currentMethod.setReturnType(currentExtendedMethod.getReturnType()); currentMethod.setVisibility(currentExtendedMethod.getVisibility()); final char[][] detectedParameters = currentExtendedMethod.getParameters(); for (int i = 0; i < detectedParameters.length; i++) { // Yann 2004/01/25: Arrays and primitive types! // I must be careful with arrays (remove the // brackets) and primitive types (do not attempt // to create a Ghost from them). // Yann 2006/02/08: Members! // The searchForEntity() method takes care of members and ghosts... // if (anEntity == null // && !padl.util.Util.isPrimtiveType(paramType) // && !Utils.isAnonymousEntity(paramType)) { // // anEntity = // aCodeLevelModel.getFactory().createGhost( // paramType); // aCodeLevelModel.addConstituent(anEntity); // } // // Yann 2004/08/07: Parameters! // Parameters now take care of their // cardinlity by themselves... // Yann 2007/08/31: Member... // I should not replace the $ sign by // a . because then I cannot know that // the type is a member type anymore... // this would not happen if IEntity // was used instead of String! // // Yann 2009/05/02: No String anymore! // Cool, eh? char[] paramType = detectedParameters[i]; int cardinality = 1; final int bracketIndex = ArrayUtils.indexOf(paramType, '['); if (bracketIndex > -1) { cardinality = (paramType.length - bracketIndex) / 2 + 1; paramType = ArrayUtils.subarray(paramType, 0, bracketIndex); }/*from w w w .j ava2 s .c o m*/ final IParameter parameter = this.createParameter(aCodeLevelModel, paramType, cardinality); currentMethod.addConstituent(parameter); } // Yann 2005/12/29: Duplicate... // Actually, the RelationshipAnalyser might already have created // a method in an entity if this method was called from another // entity. Thus, there would be an attempt to add a "duplicate" // element, which is legitimate but taken care of by the new condition. final IFirstClassEntity firstClassEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel, currentExtendedMethod.getDeclaringClassName(), this.mapOfIDsEntities); if (!firstClassEntity.doesContainConstituentWithID(currentMethod.getID())) { firstClassEntity.addConstituent(currentMethod); } } } else { notRecognized.add(element); // This is not a method, next... } } return notRecognized; }
From source file:padl.creator.classfile.relationship.RelationshipAnalyzer.java
private IOperation searchForMethod(final char[] usedMethodName, final char[] returnType, final IFirstClassEntity entityDeclaringMethod) { IOperation calledMethod = null;/*from w w w. j av a 2s . co m*/ // Yann 2006/07/29: Compatiblity! // There is a compatibility issue between classfiles v1.1- // and v1.2+, i.e., compiled with a 1.3- compiler and with // a 1.4+ compiler: the methodref pointed by the index in // a invokevirtual bytecode has changed. In the case of two // classes A and B such as A -<|- B, A defines foo(), B // defines bar() that calls this.foo(), the 1.1- bytcode // looks like this (from BCEL): // // [Code(max_stack = 1, max_locals = 1, code_length = 5) // 0: aload_0 // 1: invokevirtual padl.test.method.A.foo ()V (17) // 4: return // // Attribute(s) = // LineNumber(0, 5), LineNumber(4, 6) // LocalVariable(start_pc = 0, length = 5, index = 0:padl.test.method.B this) // ] // // while the 1.2+ looks like that: // [Code(max_stack = 1, max_locals = 1, code_length = 5) // 0: aload_0 // 1: invokevirtual padl.test.method.B.foo ()V (17) // 4: return // // Attribute(s) = // LineNumber(0, 5), LineNumber(4, 6) // LocalVariable(start_pc = 0, length = 5, index = 0:padl.test.method.B this) // ] // // Note the change in the methodref: with 1.1- it is: // padl.test.method.A.foo // while with 1.2+ it is: // padl.test.method.B.foo // and that actually makes a hell of a difference, because we // were assuming that if the method did not exist we should add // it, regardless if this was to a IGhost or a IClass. // // Thus, with 1.2+ bytecode, class B would define an additional // method foo() because of "padl.test.method.B.foo": indeed, // method foo() does not exist in B and thus it would be added! // I modified the test below to add the "instanceof", which // fixes nicely the problem. if (!entityDeclaringMethod.doesContainConstituentWithID(usedMethodName) && entityDeclaringMethod instanceof IGhost) { // Yann 2004/04/03: Constituent ID! // When creating a new method, we give it a unique actorID. // We must also give it a name without extra parentheses. // TODO: Refactor to remove the call to substring(). // Yann 2004/04/09: Modifiers! // When creating a new method, we must also set its modifier: // Test case padl.test.example.Composite1 fails because the // print() method built should be set abstract. // Yann 2004/05/20: Constructors. // If the method is a constructor, its name is // its declaring class name. final char[] name = ArrayUtils.subarray(usedMethodName, 0, ArrayUtils.indexOf(usedMethodName, '(')); if (Utils.isSpecialMethod(name)) { // Creates a new constructor that will be added to the ghost calledMethod = this.createConstructor(entityDeclaringMethod, usedMethodName); } else { // Creates a new method that will be added to the ghost calledMethod = this.createMethod(entityDeclaringMethod, usedMethodName, returnType, name); } entityDeclaringMethod.addConstituent(calledMethod); } else { calledMethod = (IOperation) entityDeclaringMethod.getConstituentFromID(usedMethodName); } // Yann 2006/08/03: Compatibility! // Now that I don't add a method in silly cases, I must // look for this method in the hierarchy of the current // entity, because it can be defined higher up in the // hierarchy... // We are in Java, only one super-class is allowed. // Yann 2007/03/16: Interfaces... // But we could be dealing with an interface, // with no super-interfaces... // TODO: Anyhow, it is strange to deal with interfaces here... Iterator iterator = entityDeclaringMethod.getIteratorOnInheritedEntities(); if (calledMethod == null && iterator.hasNext()) { /* * Alban : 2008/09/30 * Iterate on all parents to find method */ while (iterator.hasNext() && calledMethod == null) { calledMethod = this.searchForMethod(usedMethodName, returnType, (IFirstClassEntity) iterator.next()); } } if (entityDeclaringMethod instanceof IClass) { iterator = ((IClass) entityDeclaringMethod).getIteratorOnImplementedInterfaces(); if (calledMethod == null && iterator.hasNext()) { /* * Aminata & Venera : 2011/08/19 * Iterate on all interfaces to find method */ while (iterator.hasNext() && calledMethod == null) { calledMethod = this.searchForMethod(usedMethodName, returnType, (IFirstClassEntity) iterator.next()); } } } return calledMethod; }
From source file:padl.creator.classfile.util.Utils.java
public static char[] extractPackageName(final char[] aJVMClassName) { if (ArrayUtils.indexOf(aJVMClassName, '.') == -1) { return Utils.DEFAULT_PACKAGE_NAME; } else {/*from ww w.j ava 2 s.c o m*/ return ArrayUtils.subarray(aJVMClassName, 0, ArrayUtils.lastIndexOf(aJVMClassName, '.')); } }
From source file:padl.creator.classfile.util.Utils.java
public static IFirstClassEntity getEntityOrCreateGhost(final IAbstractLevelModel anAbstractLevelModel, final char[] anEntityName, final Map aMapOfIDsEntities) { IFirstClassEntity firstClassEntity;/* w ww . j a va 2 s.co m*/ // Yann 2010/06/30: Arrays... // For some reason, when analysing Xercesv2.7.0.jar, // the DeepRelationshipAnalyser attemps to add the // array java.lang.String[]... Don't know why! if (Util.isArray(anEntityName)) { firstClassEntity = (IFirstClassEntity) anAbstractLevelModel.getTopLevelEntityFromID( ArrayUtils.subarray(anEntityName, 0, ArrayUtils.indexOf(anEntityName, '['))); } else { // IFirstClassEntity firstClassEntity = // (IFirstClassEntity) aMapOfIDsEntities.get(String // .valueOf(anEntityName)); firstClassEntity = (IFirstClassEntity) anAbstractLevelModel.getTopLevelEntityFromID(anEntityName); } if (firstClassEntity == null) { if (ArrayUtils.indexOf(anEntityName, '$') == -1) { firstClassEntity = Utils.createGhost(anAbstractLevelModel, anEntityName); } else { firstClassEntity = Utils.searchForEntity(anAbstractLevelModel, anEntityName); } aMapOfIDsEntities.put(String.valueOf(anEntityName), firstClassEntity); } return firstClassEntity; }
From source file:padl.creator.classfile.util.Utils.java
public static boolean isAnonymousOrLocalEntity(final char[] anEntityName) { final int first = ArrayUtils.indexOf(anEntityName, '$'); int last = ArrayUtils.lastIndexOf(anEntityName, '$'); if (first > -1) { if (first == last) { last = anEntityName.length;/*from w w w.j a va 2 s . c o m*/ } try { Integer.parseInt(String.valueOf(ArrayUtils.subarray(anEntityName, first + 1, last))); } catch (final NumberFormatException nfe) { return false; } return true; } return false; }
From source file:padl.creator.classfile.util.Utils.java
public static boolean isLocalOrLocalMemberEntity(final char[] anEntityName) { final int first = ArrayUtils.indexOf(anEntityName, '$'); int next = ArrayUtils.indexOf(anEntityName, '$', first + 1); if (first > -1 && next > -1) { try {//w w w. j a v a 2s .c om Integer.parseInt(String.valueOf(ArrayUtils.subarray(anEntityName, first + 1, next))); } catch (final NumberFormatException nfe) { return false; } return true; } return false; }
From source file:padl.creator.classfile.util.Utils.java
public static boolean isMemberEntity(final char[] anEntityName) { int first = ArrayUtils.indexOf(anEntityName, '$') + 1; if (first > 0) { final int second = ArrayUtils.indexOf(anEntityName, '$', first); if (second == -1) { return true; }// w ww . j a v a 2s . c om try { Integer.parseInt(String.valueOf(ArrayUtils.subarray(anEntityName, first, second))); } catch (final NumberFormatException nfe) { return true; } } return false; }
From source file:padl.creator.classfile.util.Utils.java
public static boolean isSpecialMethod(final char[] aMethodName) { return ArrayUtils.indexOf(aMethodName, '<') > -1; }