public static List<String> getShortNames(Struct type) { String name = type.getTag().toString(); List<String> shortNames = new ArrayList<String>(); String base = name.startsWith("NS") ? name.substring(2) : name; Matcher matcher = shortNamesPattern.matcher(base); int i = 0; while (matcher.find(i)) { String n = matcher.group(1); shortNames.add(base.substring(matcher.start())); i = matcher.start() + n.length(); } return shortNames; }
public static List<String> getShortNames(Struct type) { String name = type.getTag().toString(); List<String> shortNames = new ArrayList<String>(); String base = name.startsWith("NS") ? name.substring(2) : name; Matcher matcher = shortNamesPattern.matcher(base); int i = 0; while (matcher.find(i)) { String n = matcher.group(1); shortNames.add(base.substring(matcher.start())); i = matcher.start() + n.length(); } return shortNames; }
@Override public void visitStruct(Struct struct) { path.push(ident(path.peek(), struct.getTag())); super.visitStruct(struct); path.pop(); }
@Override public void visitStruct(Struct struct) { path.push(ident(path.peek(), struct.getTag())); super.visitStruct(struct); path.pop(); }
public void printJavaClass(Identifier javaPackage, Struct javaClass, PrintWriter out) { if (javaPackage != null) { out.println("package " + javaPackage + ";"); } if (config.noAutoImports) { out.println(javaClass); } else { Printer.printJava(javaPackage, ident(javaPackage == null ? null : javaPackage.clone(), javaClass.getTag().clone()), javaClass, out); } // out.println("@SuppressWarnings(\"unused\")"); }
public void printJavaClass(Identifier javaPackage, Struct javaClass, PrintWriter out) { if (javaPackage != null) { out.println("package " + javaPackage + ";"); } if (config.noAutoImports) { out.println(javaClass); } else { Printer.printJava(javaPackage, ident(javaPackage == null ? null : javaPackage.clone(), javaClass.getTag().clone()), javaClass, out); } // out.println("@SuppressWarnings(\"unused\")"); }
public void generateObjectiveCClasses() throws IOException { for (Struct in : Result.getMap(result.classes, Type.ObjCClass).values()) { outputObjectiveCClass(in); } for (Struct protocol : Result.getMap(result.classes, Type.ObjCProtocol).values()) { for (String parent : getForcedProtocolParents(String.valueOf(protocol.getTag()))) { protocol.addParent(ident(parent)); } outputObjectiveCClass(protocol); } }
public void generateObjectiveCClasses() throws IOException { for (Struct in : Result.getMap(result.classes, Type.ObjCClass).values()) { outputObjectiveCClass(in); } for (Struct protocol : Result.getMap(result.classes, Type.ObjCProtocol).values()) { for (String parent : getForcedProtocolParents(String.valueOf(protocol.getTag()))) { protocol.addParent(ident(parent)); } outputObjectiveCClass(protocol); } }
private void addAllocIfMissing(Struct in, String allocName) { Identifier n = in.getTag(); if (n.equals("NSObject") || n.equals("NSClass")) { return; } boolean hasAlloc = false; for (Declaration d : in.getDeclarations()) { if (d instanceof Function) { Function f = (Function) d; if (f.getArgs().isEmpty() && allocName.equals(f.getName())) { hasAlloc = true; break; } } } if (!hasAlloc) { in.addDeclaration(new Function(Function.Type.ObjCMethod, ident(allocName), typeRef(in.getTag())).addModifiers(ModifierType.Static)); } }
public Identifier getFullClassName(Struct struct) { if (struct == null) { return null; } Identifier javaPackage = getPackageName(struct); Identifier tag = struct.getTag(); String categ = struct.getCategoryName(); Identifier fullName = ident(javaPackage, categ == null ? tag.clone() : ident(categ)); return fullName; }
public final void convertStructs(List<Struct> structs, Signatures signatures, DeclarationsHolder out, String library) throws IOException { if (structs != null) { for (Struct struct : structs) { if (struct.findParentOfType(Struct.class) != null) continue; if (!result.config.genCPlusPlus && struct.getType().isCpp()) continue; if (skip(struct.getTag() + "", result.config.skippedStructNames)) continue; outputConvertedStruct(struct, signatures, out, library, false); } } }
public Identifier getFullClassName(Struct struct) { if (struct == null) { return null; } Identifier javaPackage = getPackageName(struct); Identifier tag = struct.getTag(); String categ = struct.getCategoryName(); Identifier fullName = ident(javaPackage, categ == null ? tag.clone() : ident(categ)); return fullName; }
public final void convertStructs(List<Struct> structs, Signatures signatures, DeclarationsHolder out, String library) throws IOException { if (structs != null) { for (Struct struct : structs) { if (struct.findParentOfType(Struct.class) != null) continue; if (!result.config.genCPlusPlus && struct.getType().isCpp()) continue; if (skip(struct.getTag() + "", result.config.skippedStructNames)) continue; outputConvertedStruct(struct, signatures, out, library, false); } } }
@Override public void visitStruct(Struct struct) { super.visitStruct(struct); if (struct.isForwardDeclaration() && struct.getTag() != null) { Element parent = struct.getParentElement(); if (!(parent instanceof TaggedTypeRefDeclaration)) { TypeRef tr = new TypeRef.SimpleTypeRef(struct.getTag()); for (Modifier mod : struct.getModifiers()) { if (mod.isA(ModifierKind.StorageClassSpecifier)) { tr.addModifiers(mod); } } struct.replaceBy(tr); tr.accept(this); } } }
@Override public Struct convertCallback(FunctionSignature functionSignature, Signatures signatures, Identifier callerLibraryName) { Struct decl = super.convertCallback(functionSignature, signatures, callerLibraryName); if (decl != null) { decl.setParents(Arrays.asList((SimpleTypeRef) (FunctionSignature.Type.ObjCBlock.equals(functionSignature.getType()) ? result.config.runtime.typeRef(JNAeratorConfig.Runtime.Ann.ObjCBlock) : (SimpleTypeRef) typeRef(ident(result.config.runtime.callbackClass, expr(typeRef(decl.getTag().clone()))))))); //addCallingConventionAnnotation(functionSignature.getFunction(), decl); } return decl; }
@Override public Struct convertCallback(FunctionSignature functionSignature, Signatures signatures, Identifier callerLibraryName) { Struct decl = super.convertCallback(functionSignature, signatures, callerLibraryName); if (decl != null) { decl.setParents(Arrays.asList((SimpleTypeRef) (FunctionSignature.Type.ObjCBlock.equals(functionSignature.getType()) ? result.config.runtime.typeRef(JNAeratorConfig.Runtime.Ann.ObjCBlock) : (SimpleTypeRef) typeRef(ident(result.config.runtime.callbackClass, expr(typeRef(decl.getTag().clone()))))))); //addCallingConventionAnnotation(functionSignature.getFunction(), decl); } return decl; }
protected Function createNewStructArrayMethod(Struct struct, boolean isUnion) { if (result.config.runtime == JNAeratorConfig.Runtime.JNA) { return null; } TypeRef tr = typeRef(struct.getTag().clone()); TypeRef ar = new TypeRef.ArrayRef(tr); String varName = "arrayLength"; Function f = new Function(Function.Type.JavaMethod, ident("newArray"), ar, new Arg(varName, typeRef(Integer.TYPE))); f.addModifiers(ModifierType.Public, ModifierType.Static); f.setBody(block( new Statement.Return( methodCall( expr(typeRef(isUnion ? result.config.runtime.unionClass : result.config.runtime.structClass)), MemberRefStyle.Dot, "newArray", result.typeConverter.typeLiteral(tr), varRef(varName))))); return f; }
protected Function createNewStructMethod(String name, Struct byRef) { TypeRef tr = typeRef(byRef.getTag().clone()); Function f = new Function(Function.Type.JavaMethod, ident(name), tr); String varName = "s"; f.addModifiers(ModifierType.Protected); if (result.config.runtime != JNAeratorConfig.Runtime.JNA) { f.setBody(block( //new Statement.Return(methodCall("setupClone", new Expression.New(tr.clone(), methodCall(null)))) new Statement.Return(new Expression.New(tr.clone(), methodCall((String) null)))).setCompact(true)); } else { f.setBody(block( stat(tr.clone(), varName, new Expression.New(tr.clone(), methodCall((String) null))), stat(methodCall(varRef(varName), MemberRefStyle.Dot, "useMemory", methodCall("getPointer"))), stat(methodCall("write")), stat(methodCall(varRef(varName), MemberRefStyle.Dot, "read")), new Statement.Return(varRef(varName)))); } return f; }