List of usage examples for org.apache.commons.lang ArrayUtils subarray
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
From source file:padl.creator.classfile.util.Utils.java
public static char[] computeSimpleName(final char[] aJVMClassName) { int index = ArrayUtils.lastIndexOf(aJVMClassName, '$'); if (index == -1) { index = ArrayUtils.lastIndexOf(aJVMClassName, '.'); if (index == -1) { return aJVMClassName; }//w w w . j ava 2s . c o m } return ArrayUtils.subarray(aJVMClassName, index + 1, aJVMClassName.length); }
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 {/* w w w . j av a 2 s. co 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;/* www .j a v a 2 s . c o 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 ww w . j a va 2 s .com } 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 {//from w ww . j av a2s.co m 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; }//from w ww .ja va 2s . co m 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
private static IFirstClassEntity searchForEnclosedEntity(final IAbstractLevelModel anAbstractModel, final IFirstClassEntity anEnclosingEntity, final char[] anEntityName) { final char[] nameFirstPart; if (Utils.isMemberEntity(anEntityName)) { nameFirstPart = ArrayUtils.subarray(anEntityName, 0, ArrayUtils.indexOf(anEntityName, '$')); } else {/*w w w . j a v a 2s . c o m*/ nameFirstPart = ArrayUtils.subarray(anEntityName, 0, anEntityName.length); } // Yann 2016/09/18: Member IDs! // Member entities have their fully-qualified names (with $) as IDs... final char[] id = ArrayUtils.addAll(ArrayUtils.add(anEnclosingEntity.getID(), '$'), nameFirstPart); IFirstClassEntity firstClassEntity = (IFirstClassEntity) anEnclosingEntity.getConstituentFromID(id); if (firstClassEntity == null) { firstClassEntity = Utils.createMemberGhost(anAbstractModel, anEnclosingEntity, id); } if (Utils.isMemberEntity(anEntityName)) { return Utils.searchForEnclosedEntity(anAbstractModel, firstClassEntity, ArrayUtils .subarray(anEntityName, ArrayUtils.indexOf(anEntityName, '$') + 1, anEntityName.length)); } else { return firstClassEntity; } }
From source file:padl.creator.classfile.util.Utils.java
public static IFirstClassEntity searchForEntity(final IAbstractLevelModel anAbstractModel, final char[] anEntityName) { final char[] nameFirstPart; if (Utils.isMemberEntity(anEntityName)) { nameFirstPart = ArrayUtils.subarray(anEntityName, 0, ArrayUtils.indexOf(anEntityName, '$')); } else {//from w ww .j a va 2 s . com nameFirstPart = ArrayUtils.subarray(anEntityName, 0, anEntityName.length); } IFirstClassEntity firstClassEntity = (IFirstClassEntity) anAbstractModel .getTopLevelEntityFromID(nameFirstPart); if (firstClassEntity == null) { firstClassEntity = Utils.createGhost(anAbstractModel, nameFirstPart); } if (Utils.isMemberEntity(anEntityName)) { return Utils.searchForEnclosedEntity(anAbstractModel, firstClassEntity, ArrayUtils .subarray(anEntityName, ArrayUtils.indexOf(anEntityName, '$') + 1, anEntityName.length)); } else { return firstClassEntity; } }
From source file:padl.creator.cppfile.eclipse.plugin.internal.Accumulator.java
IOperation getOperation(final ICPPFunction aCPPFunction) { final IOperation operation = this.mapCPPFunctionPADLOperations.get(aCPPFunction); if (operation != null) { return operation; }/* w ww. j a v a 2 s . c o m*/ // Eclipse is doing something phony in our backs... char[] functionSignature = Utils.computeSignature(aCPPFunction); // These weird PDOMCPP objects have at the end of their signature // some kind of tag that I must remove to make sense... because they // don't: no information on the Internet regarding these classes :-( functionSignature = ArrayUtils.subarray(functionSignature, 0, ArrayUtils.lastIndexOf(functionSignature, ')') + 1); final Iterator<Map.Entry<ICPPFunction, IOperation>> iterator = this.mapCPPFunctionPADLOperations.entrySet() .iterator(); while (iterator.hasNext()) { final Map.Entry<ICPPFunction, IOperation> entry = iterator.next(); final ICPPFunction candidateFunction = entry.getKey(); final char[] candidateFunctionSignature = Utils.computeSignature(candidateFunction); if (Arrays.equals(candidateFunctionSignature, functionSignature)) { final IOperation candidateOperation = (IOperation) entry.getValue(); this.mapCPPFunctionPADLOperations.put(aCPPFunction, candidateOperation); return candidateOperation; } } Utils.reportUnknownType(Accumulator.class, "operation", aCPPFunction.toString(), aCPPFunction.getClass()); return null; }
From source file:padl.creator.cppfile.eclipse.plugin.internal.SearchHelper.java
static String getExistingOperationOrCreateGhost(final ICodeLevelModel aCodeLevelModel, final Stack<IContainer> someContainers, final char[] aFunctionName) { final char[][] declaringEntityName = Utils.getQualifiedType(aFunctionName); final IContainer declaringEntity; final IOperation operation; if (declaringEntityName.length == 0) { declaringEntity = (IContainer) aCodeLevelModel.getConstituentFromID(Constants.DEFAULT_PACKAGE_ID); } else if (declaringEntityName.length == 1) { declaringEntity = (IContainer) SearchHelper.findContainerOrCreateGhostInModel(aCodeLevelModel, declaringEntityName[0], declaringEntityName[0], true, false); } else {// www. j a va 2s . c o m declaringEntity = (IContainer) SearchHelper.getExistingContainerOrCreateGhost(aCodeLevelModel, someContainers, declaringEntityName, false); } final char[] simpleName = Utils.getSimpleName(aFunctionName); final IConstituent constituent = declaringEntity.getConstituentFromID(simpleName); if (constituent instanceof IOperation) { operation = (IOperation) constituent; } else if (constituent instanceof IFirstClassEntity) { // Here, I must manage the case of a constructor: // it is possible that the constituent is not an // operation but an entity... in this case, I must // look into it for its constructor. final IOperation possibleOperation = (IOperation) ((IFirstClassEntity) constituent) .getConstituentFromID(aFunctionName); if (possibleOperation == null) { operation = CPPFactoryEclipse.getInstance().createConstructor(aFunctionName, simpleName); // Yann 2014/0417: Anti-patterns! // I need to set the lines of code of the methods // to allow the identification of some anti-patterns // like LongMethod and SpaghettiCode. This seems the // best place to do so :-) // In this case, I just add a null statement! Utils.addStatementsToFunction(operation); ((IFirstClassEntity) constituent).addConstituent(operation); } else { operation = possibleOperation; } } else { // Yann 2014/04/17: Parameter! // I don't forget that the ID contains the parameter list... // Important if I want to find the corresponding function // if it exists. BUT, it is not quite possible to build the // parameter because there is no bindings at this point. // So, it is rather the getExistingOperationOrCreateGhost() // method that must be smart: if it finds the method in the // declaring entity, then it should choose it; else if it // finds a method with the same name, but different parameters, // then it should choose it too, else it should look for // for (ghost) global functions. final Iterator<?> iterator = declaringEntity.getIteratorOnConstituents(IOperation.class); while (iterator.hasNext()) { final IOperation possibleOperation = (IOperation) iterator.next(); final char[] operationName = possibleOperation.getID(); final char[] operationNameWithoutParameters = ArrayUtils.subarray(operationName, 0, ArrayUtils.indexOf(operationName, '(')); final char[] simpleNameWithoutParameters = ArrayUtils.subarray(simpleName, 0, ArrayUtils.indexOf(simpleName, '(')); if (Arrays.equals(operationNameWithoutParameters, simpleNameWithoutParameters)) { return possibleOperation.getDisplayPath(); } } if (Arrays.equals(((IConstituent) declaringEntity).getName(), simpleName)) { operation = CPPFactoryEclipse.getInstance().createConstructor(aFunctionName, simpleName); } else { if (declaringEntity instanceof IPackage) { // Yann 2015/07/16: Weird... // Why does the simple name include parentheses??? final char[] simpleNameWithoutParameters = ArrayUtils.subarray(simpleName, 0, ArrayUtils.indexOf(simpleName, '(')); operation = ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance()) .createGlobalFunctionGhost(aFunctionName, simpleNameWithoutParameters); } else { operation = CPPFactoryEclipse.getInstance().createMethod(simpleName, simpleName); } } if (!declaringEntity.doesContainConstituentWithID(operation.getID())) { // Yann 2014/0417: Anti-patterns! // I need to set the lines of code of the methods // to allow the identification of some anti-patterns // like LongMethod and SpaghettiCode. This seems the // best place to do so :-) // In this case, I just add a null statement! Utils.addStatementsToFunction(operation); declaringEntity.addConstituent(operation); } else { // I must return the real constituent in the entity, // I cannot use the ones build above because they // don't belong to any model yet. return declaringEntity.getConstituentFromID(operation.getID()).getDisplayPath(); } } return operation.getDisplayPath(); }