private static void removeStaticFieldsAndInitialisers(ClassOrInterfaceDeclaration node) { // Remove all the static initialisers for (InitializerDeclaration child : node.getChildNodesByType(InitializerDeclaration.class)) { child.remove(); } // Remove all static fields for (FieldDeclaration field : node.getFields()) { if (field.getModifiers().contains(Modifier.STATIC)) { field.remove(); continue; } } }
private JavaMethod createMethod (MethodDeclaration method) { String className = classStack.peek().getName(); String name = method.getName(); boolean isStatic = ModifierSet.hasModifier(method.getModifiers(), ModifierSet.STATIC); String returnType = method.getType().toString(); ArrayList<Argument> arguments = new ArrayList<Argument>(); if (method.getParameters() != null) { for (Parameter parameter : method.getParameters()) { arguments.add(new Argument(getArgumentType(parameter), parameter.getId().getName())); } } return new JavaMethod(className, name, isStatic, returnType, null, arguments, method.getBeginLine(), method.getEndLine()); }
private void getJavaMethods (ArrayList<JavaMethod> methods, TypeDeclaration type) { classStack.push(type); if (type.getMembers() != null) { for (BodyDeclaration member : type.getMembers()) { if (member instanceof ClassOrInterfaceDeclaration || member instanceof EnumDeclaration) { getJavaMethods(methods, (TypeDeclaration)member); } else { if (member instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration)member; if (!ModifierSet.hasModifier(((MethodDeclaration)member).getModifiers(), ModifierSet.NATIVE)) continue; methods.add(createMethod(method)); } } } } classStack.pop(); }
/** * Generates something like * <code>private static final AtomicLongFieldUpdater<MpmcAtomicArrayQueueProducerIndexField> P_INDEX_UPDATER = AtomicLongFieldUpdater.newUpdater(MpmcAtomicArrayQueueProducerIndexField.class, "producerIndex");</code> * * @param type * @param name * @param initializer * @param modifiers * @return */ private static FieldDeclaration fieldDeclarationWithInitialiser(Type type, String name, Expression initializer, Modifier... modifiers) { FieldDeclaration fieldDeclaration = new FieldDeclaration(); VariableDeclarator variable = new VariableDeclarator(type, name, initializer); fieldDeclaration.getVariables().add(variable); EnumSet<Modifier> modifierSet = EnumSet.copyOf(Arrays.asList(modifiers)); fieldDeclaration.setModifiers(modifierSet); return fieldDeclaration; }
/** * Searches all extended or implemented super classes or interfaces for * special classes that differ with the atomics version and replaces them * with the appropriate class. * * @param n */ private static void replaceParentClassesForAtomics(ClassOrInterfaceDeclaration n) { replaceParentClassesForAtomics(n.getExtendedTypes()); replaceParentClassesForAtomics(n.getImplementedTypes()); }
private ArgumentType getArgumentType (Parameter parameter) { String[] typeTokens = parameter.getType().toString().split("\\."); String type = typeTokens[typeTokens.length - 1]; int arrayDim = 0; for (int i = 0; i < type.length(); i++) { if (type.charAt(i) == '[') arrayDim++; } type = type.replace("[", "").replace("]", ""); if (arrayDim >= 1) { if (arrayDim > 1) return ArgumentType.ObjectArray; ArgumentType arrayType = arrayTypes.get(type); if (arrayType == null) { return ArgumentType.ObjectArray; } return arrayType; } if (plainOldDataTypes.containsKey(type)) return plainOldDataTypes.get(type); if (bufferTypes.containsKey(type)) return bufferTypes.get(type); if (otherTypes.containsKey(type)) return otherTypes.get(type); return ArgumentType.Object; }
private static void processSpecialNodeTypes(MethodDeclaration node) { processSpecialNodeTypes(node, node.getNameAsString()); }
@Override public void visit(ClassOrInterfaceDeclaration n, Void arg) { out.println("ClassOrInterfaceDeclaration: " + (extended ? n : n.getNameAsString())); super.visit(n, arg); }
private static void processSpecialNodeTypes(VariableDeclarator node) { processSpecialNodeTypes(node, node.getNameAsString()); }
private static void processSpecialNodeTypes(Parameter node) { processSpecialNodeTypes(node, node.getNameAsString()); }
@Override public void visit(MethodDeclaration n, Void arg) { out.println("MethodDeclaration: " + (extended ? n : n.getDeclarationAsString())); super.visit(n, arg); }
@Override public void visit(ConstructorDeclaration n, Void arg) { super.visit(n, arg); // Update the ctor to match the class name n.setName(translateQueueName(n.getNameAsString())); }
@Override public void visit(ConstructorDeclaration n, Void arg) { out.println("ConstructorDeclaration: " + (extended ? n : n.getDeclarationAsString())); super.visit(n, arg); }
private JavaMethod createMethod (MethodDeclaration method) { String className = classStack.peek().getName(); String name = method.getName(); boolean isStatic = ModifierSet.hasModifier(method.getModifiers(), ModifierSet.STATIC); String returnType = method.getType().toString(); ArrayList<Argument> arguments = new ArrayList<Argument>(); if (method.getParameters() != null) { for (Parameter parameter : method.getParameters()) { arguments.add(new Argument(getArgumentType(parameter), parameter.getId().getName())); } } return new JavaMethod(className, name, isStatic, returnType, null, arguments, method.getBeginLine(), method.getEndLine()); }
private void getJavaMethods (ArrayList<JavaMethod> methods, TypeDeclaration type) { classStack.push(type); if (type.getMembers() != null) { for (BodyDeclaration member : type.getMembers()) { if (member instanceof ClassOrInterfaceDeclaration || member instanceof EnumDeclaration) { getJavaMethods(methods, (TypeDeclaration)member); } else { if (member instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration)member; if (!ModifierSet.hasModifier(((MethodDeclaration)member).getModifiers(), ModifierSet.NATIVE)) continue; methods.add(createMethod(method)); } } } } classStack.pop(); }
/** * Generates something like * <code>private static final AtomicLongFieldUpdater<MpmcAtomicArrayQueueProducerIndexField> P_INDEX_UPDATER = AtomicLongFieldUpdater.newUpdater(MpmcAtomicArrayQueueProducerIndexField.class, "producerIndex");</code> * * @param type * @param name * @param initializer * @param modifiers * @return */ private static FieldDeclaration fieldDeclarationWithInitialiser(Type type, String name, Expression initializer, Modifier... modifiers) { FieldDeclaration fieldDeclaration = new FieldDeclaration(); VariableDeclarator variable = new VariableDeclarator(type, name, initializer); fieldDeclaration.getVariables().add(variable); EnumSet<Modifier> modifierSet = EnumSet.copyOf(Arrays.asList(modifiers)); fieldDeclaration.setModifiers(modifierSet); return fieldDeclaration; }
private static void removeStaticFieldsAndInitialisers(ClassOrInterfaceDeclaration node) { // Remove all the static initialisers for (InitializerDeclaration child : node.getChildNodesByType(InitializerDeclaration.class)) { child.remove(); } // Remove all static fields for (FieldDeclaration field : node.getFields()) { if (field.getModifiers().contains(Modifier.STATIC)) { field.remove(); continue; } } }
private ArgumentType getArgumentType (Parameter parameter) { String[] typeTokens = parameter.getType().toString().split("\\."); String type = typeTokens[typeTokens.length - 1]; int arrayDim = 0; for (int i = 0; i < type.length(); i++) { if (type.charAt(i) == '[') arrayDim++; } type = type.replace("[", "").replace("]", ""); if (arrayDim >= 1) { if (arrayDim > 1) return ArgumentType.ObjectArray; ArgumentType arrayType = arrayTypes.get(type); if (arrayType == null) { return ArgumentType.ObjectArray; } return arrayType; } if (plainOldDataTypes.containsKey(type)) return plainOldDataTypes.get(type); if (bufferTypes.containsKey(type)) return bufferTypes.get(type); if (otherTypes.containsKey(type)) return otherTypes.get(type); return ArgumentType.Object; }
private static void processSpecialNodeTypes(VariableDeclarator node) { processSpecialNodeTypes(node, node.getNameAsString()); }
private static void processSpecialNodeTypes(Parameter node) { processSpecialNodeTypes(node, node.getNameAsString()); }