if (n != null && n.equals("NSObject"))// || n.equals("NSClass"))
if (n != null && n.equals("NSObject"))// || n.equals("NSClass"))
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)); } }
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 Struct notifyBeforeWritingClass(Identifier fullClassName, Struct interf, Signatures signatures, String currentLibrary) { for (Class<?> c : overwrittenClassesThatNeedToKeepAllTheirMethods) { if (fullClassName.equals(c.getName())) { declarationsConverter.addMissingMethods(c, signatures, interf); break; } } if (fullClassName.resolveLastSimpleIdentifier().equals("char")) { return null; } String runtimeSpecificHelp = config.runtime == JNAeratorConfig.Runtime.BridJ ? "or <a href=\"http://bridj.googlecode.com/\">BridJ</a> " : ", <a href=\"http://rococoa.dev.java.net/\">Rococoa</a>, " + "or <a href=\"http://jna.dev.java.net/\">JNA</a>"; interf.addToCommentBefore( "This file was autogenerated by <a href=\"http://jnaerator.googlecode.com/\">JNAerator</a>, ", "a tool written by <a href=\"http://ochafik.com/\">Olivier Chafik</a> that <a href=\"http://code.google.com/p/jnaerator/wiki/CreditsAndLicense\">uses a few opensource projects.</a>.", "For help, please visit <a href=\"http://nativelibs4java.googlecode.com/\">NativeLibs4Java</a> " + runtimeSpecificHelp + "."); for (ClassWritingNotifiable n : classWritingNotifiables) { interf = n.writingClass(fullClassName, interf, signatures, currentLibrary); if (interf == null) { return null; } } return interf; } public List<ClassWritingNotifiable> classWritingNotifiables = new ArrayList<ClassWritingNotifiable>();
public Struct notifyBeforeWritingClass(Identifier fullClassName, Struct interf, Signatures signatures, String currentLibrary) { for (Class<?> c : overwrittenClassesThatNeedToKeepAllTheirMethods) { if (fullClassName.equals(c.getName())) { declarationsConverter.addMissingMethods(c, signatures, interf); break; } } if (fullClassName.resolveLastSimpleIdentifier().equals("char")) { return null; } String runtimeSpecificHelp = config.runtime == JNAeratorConfig.Runtime.BridJ ? "or <a href=\"http://bridj.googlecode.com/\">BridJ</a> " : ", <a href=\"http://rococoa.dev.java.net/\">Rococoa</a>, " + "or <a href=\"http://jna.dev.java.net/\">JNA</a>"; interf.addToCommentBefore( "This file was autogenerated by <a href=\"http://jnaerator.googlecode.com/\">JNAerator</a>, ", "a tool written by <a href=\"http://ochafik.com/\">Olivier Chafik</a> that <a href=\"http://code.google.com/p/jnaerator/wiki/CreditsAndLicense\">uses a few opensource projects.</a>.", "For help, please visit <a href=\"http://nativelibs4java.googlecode.com/\">NativeLibs4Java</a> " + runtimeSpecificHelp + "."); for (ClassWritingNotifiable n : classWritingNotifiables) { interf = n.writingClass(fullClassName, interf, signatures, currentLibrary); if (interf == null) { return null; } } return interf; } public List<ClassWritingNotifiable> classWritingNotifiables = new ArrayList<ClassWritingNotifiable>();
@Override public void visitPrimitive(Primitive primitive) { super.visitPrimitive(primitive); if (ModifierType.Long.isContainedBy(primitive.getModifiers())) { Identifier name = primitive.getName(); if (name == null || name.equals("int") || name.equals("long")) { primitive.setName(ident("long")); if (name == null) { primitive.removeModifiers(ModifierType.Long); } } } else if (ModifierType.Short.isContainedBy(primitive.getModifiers())) { Identifier name = primitive.getName(); if (name == null || name.equals("int")) { primitive.setName(ident("short")); primitive.removeModifiers(ModifierType.Short); } } }
@Override public void visitPrimitive(Primitive primitive) { super.visitPrimitive(primitive); if (ModifierType.Long.isContainedBy(primitive.getModifiers())) { Identifier name = primitive.getName(); if (name == null || name.equals("int") || name.equals("long")) { primitive.setName(ident("long")); if (name == null) { primitive.removeModifiers(ModifierType.Long); } } } else if (ModifierType.Short.isContainedBy(primitive.getModifiers())) { Identifier name = primitive.getName(); if (name == null || name.equals("int")) { primitive.setName(ident("short")); primitive.removeModifiers(ModifierType.Short); } } }
protected void valueTypeAndStorageSuffix(StoredDeclarations e) { if (e.getValueType() instanceof FunctionSignature) { FunctionSignature sig = (FunctionSignature) e.getValueType(); if (sig.getFunction() != null) { Identifier name = sig.getFunction().getName(); if (name != null && e.declarators.size() == 1) { String stoName = e.declarators.get(0).resolveName(); if (name.equals(stoName) || stoName == null) { append(sig); return; } } } } append(e.getValueType()).space(!e.getDeclarators().isEmpty()).implode(e.getDeclarators(), ", "); }
private void fillIn(Signatures signatures, Identifier functionName, Function nativeMethod, NL4JConversion returnType, List<NL4JConversion> paramTypes, List<String> paramNames, Identifier varArgType, String varArgName, boolean isCallback, boolean useRawTypes) { for (int i = 0, n = paramTypes.size(); i < n; i++) { NL4JConversion paramType = paramTypes.get(i); String paramName = paramNames.get(i); nativeMethod.addArg(paramType.annotateTypedType(new Arg(paramName, paramType.getTypeRef(useRawTypes)), useRawTypes));//.getTypedTypeRef()))); } if (varArgType != null) { nativeMethod.addArg(new Arg(varArgName, typeRef(varArgType.clone()))).setVarArg(true); } if (returnType != null) { returnType.annotateTypedType(nativeMethod, useRawTypes); nativeMethod.setValueType(returnType.getTypeRef(useRawTypes)); } String natSig = nativeMethod.computeSignature(SignatureType.JavaStyle); Identifier javaMethodName = signatures == null ? functionName : signatures.findNextMethodName(natSig, functionName); if (!javaMethodName.equals(functionName)) { nativeMethod.setName(javaMethodName); } }
private void fillIn(Signatures signatures, Identifier functionName, Function nativeMethod, NL4JConversion returnType, List<NL4JConversion> paramTypes, List<String> paramNames, Identifier varArgType, String varArgName, boolean isCallback, boolean useRawTypes) { for (int i = 0, n = paramTypes.size(); i < n; i++) { NL4JConversion paramType = paramTypes.get(i); String paramName = paramNames.get(i); nativeMethod.addArg(paramType.annotateTypedType(new Arg(paramName, paramType.getTypeRef(useRawTypes)), useRawTypes));//.getTypedTypeRef()))); } if (varArgType != null) { nativeMethod.addArg(new Arg(varArgName, typeRef(varArgType.clone()))).setVarArg(true); } if (returnType != null) { returnType.annotateTypedType(nativeMethod, useRawTypes); nativeMethod.setValueType(returnType.getTypeRef(useRawTypes)); } String natSig = nativeMethod.computeSignature(SignatureType.JavaStyle); Identifier javaMethodName = signatures == null ? functionName : signatures.findNextMethodName(natSig, functionName); if (!javaMethodName.equals(functionName)) { nativeMethod.setName(javaMethodName); } }
public Identifier getActualTaggedTypeName(TaggedTypeRef struct) { Identifier structName = null; Identifier tag = struct.getTag(); if (tag == null || tag.isPlain() && tag.toString().startsWith("_")) { TypeDef parentDef = as(struct.getParentElement(), TypeDef.class); if (parentDef != null) { structName = new Identifier.SimpleIdentifier(JNAeratorUtils.findBestPlainStorageName(parentDef)); } else if (tag != null) { String better = tag.toString().substring(1); Pair<TypeDef, Declarator> pair = result.typeDefs.get(better); if (pair != null && pair.getFirst().getValueType() != null && pair.getSecond() instanceof DirectDeclarator) { TypeRef tr = pair.getFirst().getValueType(); DirectDeclarator dd = (DirectDeclarator) pair.getSecond(); if (tr instanceof SimpleTypeRef) { if (tag.equals(((SimpleTypeRef) tr).getName())) { structName = ident(dd.resolveName()); } } else if (tr instanceof TaggedTypeRef) { if (tag.equals(((TaggedTypeRef) tr).getTag())) { structName = ident(dd.resolveName()); } } } } } if (structName == null || structName.toString().equals("")) { structName = tag; } return structName == null ? null : structName.clone(); }
public Identifier getActualTaggedTypeName(TaggedTypeRef struct) { Identifier structName = null; Identifier tag = struct.getTag(); if (tag == null || tag.isPlain() && tag.toString().startsWith("_")) { TypeDef parentDef = as(struct.getParentElement(), TypeDef.class); if (parentDef != null) { structName = new Identifier.SimpleIdentifier(JNAeratorUtils.findBestPlainStorageName(parentDef)); } else if (tag != null) { String better = tag.toString().substring(1); Pair<TypeDef, Declarator> pair = result.typeDefs.get(better); if (pair != null && pair.getFirst().getValueType() != null && pair.getSecond() instanceof DirectDeclarator) { TypeRef tr = pair.getFirst().getValueType(); DirectDeclarator dd = (DirectDeclarator) pair.getSecond(); if (tr instanceof SimpleTypeRef) { if (tag.equals(((SimpleTypeRef) tr).getName())) { structName = ident(dd.resolveName()); } } else if (tr instanceof TaggedTypeRef) { if (tag.equals(((TaggedTypeRef) tr).getTag())) { structName = ident(dd.resolveName()); } } } } } if (structName == null || structName.toString().equals("")) { structName = tag; } return structName == null ? null : structName.clone(); }
case CPPClass: case CStruct: if (!function.getName().equals(parentStruct.getTag())) { returnsInt = true;
case CPPClass: case CStruct: if (!function.getName().equals(parentStruct.getTag())) { returnsInt = true;
case CppMethod: case JavaMethod: if (name != null && name.equals("operator") && e.getType() == Function.Type.CppMethod) { append(name); space();
if (result.config.forceNames || !rawEnumName.equals(enumName)) annotateActualName(en, rawEnumName); addParentNamespaceAnnotation(en, e.getParentNamespace());
if (result.config.forceNames || !rawEnumName.equals(enumName)) annotateActualName(en, rawEnumName); addParentNamespaceAnnotation(en, e.getParentNamespace());