var YesNo = new Enum(['NO', 'YES']); var Color = new Enum(['RED', 'GREEN', 'BLUE']);
@Override public void convertEnum(Enum e, Signatures signatures, DeclarationsHolder out, Identifier libraryClassName) { if (e.isForwardDeclaration()) { return; Enum en = new Enum(); if (result.config.forceNames || !rawEnumName.equals(enumName)) annotateActualName(en, rawEnumName); addParentNamespaceAnnotation(en, e.getParentNamespace()); if (!result.config.noComments) { en.importComments(e, "enum values", getFileCommentContent(e)); en.setType(Enum.Type.Java); en.setTag(enumName.clone()); en.addModifiers(ModifierType.Public); out.addDeclaration(new TaggedTypeRefDeclaration(en)); Struct body = new Struct(); en.setBody(body); boolean hasValidItem = false; for (EnumItemResult er : results.values()) { en.addItem(item); hasValidItem = true; if (!result.config.noComments) { en.addInterface(ident(IntValuedEnum.class, expr(typeRef(enumName.clone())))); String valueArgName = "value"; body.addDeclaration(new Function(Type.JavaMethod, enumName.clone(), null, new Arg(valueArgName, typeRef(Long.TYPE))).setBody(block(
e.setForwardDeclaration(false); e.setForwardDeclaration(false); e = new Enum(); e.setType(Enum.Type.C); e.setForwardDeclaration(true); e.setTag(tag); e.addModifiers(modifiers); defineTypeIdentifierInParentScope(e.getTag());
@Override public void visitEnum(Enum e) { super.visitEnum(e); if (e.getTag() == null) { Element nextDeclaration = e.getNextSibling(); if (nextDeclaration != null && (nextDeclaration instanceof TypeDef)) { TypeDef typeDef = (TypeDef) nextDeclaration; String name = bestPlainStorage.resolveName(); System.err.println("Automatic struct name matching : " + name); e.setTag(ident(name)); Identifier name = e.getTag(); String lib = getLibrary(e); if (name == null) { e.setResolvedJavaIdentifier(typeConverter.computeTaggedTypeIdentifierInJava(e)); if (!currentNamespace.isEmpty()) e.setParentNamespace(currentNamespace.peek().clone()); Identifier originalName = e.getOriginalTag(); if (originalName != null) { enumsByName.put(originalName, e);
e = new Enum(); e.setType(Enum.Type.C); e.setForwardDeclaration(false); e.addItem((i1!=null?i1.item:null)); e.addItem((ix!=null?ix.item:null));
if (!e.getAnnotations().isEmpty()) { implode(e.getAnnotations(), "\n" + indent).append("\n", indent); append("enum ", e.getTag()); if (e.getTag() != null) { append(" "); if (!e.getInterfaces().isEmpty()) { append("implements ").implode(e.getInterfaces(), ", ").append(" "); List<EnumItem> items = e.getItems(); for (int i = 0, len = items.size(); i < len; i++) { EnumItem item = items.get(i); append(indent, item, i < len - 1 ? "," : (e.getBody() == null ? "" : ";"), "\n"); if (e.getBody() != null) { append(indent); implode(e.getBody().getDeclarations(), "\n" + indent); append("\n");
@Override public void visitEnum(Enum e) { Element parent = e.getParentElement(); if (e.getTag() == null && !(parent instanceof TypeDef)) { // Hack to infer the enum name from the next typedef NSUInteger NSSomethingThatLooksLikeTheEnumsIdentifiers Element base = parent instanceof Declaration ? e.getParentElement() : e; Element next = base.getNextSibling(); if (!handleAppleEnumTypeDef(next, e)) { Element previous = base.getPreviousSibling(); Element beforePrevious = previous == null ? null : previous.getPreviousSibling(); if (previous != null && !(beforePrevious instanceof TaggedTypeRefDeclaration && ((TaggedTypeRefDeclaration) beforePrevious).getTaggedTypeRef() instanceof Enum)) { handleAppleEnumTypeDef(previous, e); } } } String comment = e.getCommentBefore(); if (comment != null) { // TODO parse cocoa comments here } super.visitEnum(e); }
@Override public boolean replaceChild(Element child, Element by) { if (super.replaceChild(child, by)) return true; if (replaceChild(items, EnumItem.class, this, child, by)) return true; if (replaceChild(interfaces, Identifier.class, this, child, by)) return true; if (child == getBody()) { setBody((Struct) by); return true; } return super.replaceChild(child, by); } }
public void visitEnum(Enum enum1) { visitTaggedTypeRef(enum1); visit(enum1.getItems()); visit(enum1.getInterfaces()); visit(enum1.getBody()); }
public void convertEnums(List<Enum> enums, Signatures signatures, DeclarationsHolder out) { Identifier libraryClassName = out.getResolvedJavaIdentifier(); if (enums != null) { //out.println("public static class ENUMS {"); for (com.ochafik.lang.jnaerator.parser.Enum e : enums) { if (e.findParentOfType(Struct.class) != null) { continue; } if (skip(e.getTag() + "", result.config.skippedEnumNames)) continue; convertEnum(e, signatures, out, libraryClassName); } //out.println("}"); } } Map<String, Pair<Function, List<Function>>> functionAlternativesByNativeSignature = new LinkedHashMap<String, Pair<Function, List<Function>>>();
if (e.getTag() != null && !StringUtils.trimUnderscores(e.getTag().toString()).equals(name)) { return false; Element ep = e.getParentElement(); ep.addToCommentBefore(typeDef.getCommentBefore()); ep.addToCommentBefore(typeDef.getCommentAfter());
@Override public Expression getEnumItemValue(Enum.EnumItem enumItem, boolean forceConstants) { Enum e = (Enum) enumItem.getParentElement(); if (forceConstants) { Map<String, EnumItemResult> values = getEnumValuesAndCommentsByName(e, null); EnumItemResult enumResult = values.get(enumItem.getName()); if (enumResult != null) { return enumResult.constantValue; } } Expression enumValue = findEnumItem(enumItem); if (e.getTag() != null) { enumValue = methodCall(enumValue, "value"); } return cast(typeRef(int.class), enumValue.setParenthesis(true)); }
boolean failedOnceForThisEnum = false; Map<String, Pair<Expression, TypeRef>> mappings = new LinkedHashMap<String, Pair<Expression, TypeRef>>(); for (com.ochafik.lang.jnaerator.parser.Enum.EnumItem item : e.getItems()) { EnumItemResult res = new EnumItemResult(); res.originalItem = item; res.unconvertedValue = expr(lastAdditiveValue); } else { if (item == e.getItems().get(0)) { lastAdditiveValue = 0; res.unconvertedValue = expr(lastAdditiveValue);
@Override public Element getNextChild(Element child) { Element e = super.getNextChild(child); if (e != null) return e; e = getNextSibling(items, child); if (e != null) return e; e = getNextSibling(interfaces, child); if (e != null) return e; return super.getNextChild(child); }
@Override public void convertEnum(Enum e, Signatures signatures, DeclarationsHolder out, Identifier libraryClassName) { if (e.isForwardDeclaration()) { return; Enum en = new Enum(); if (result.config.forceNames || !rawEnumName.equals(enumName)) annotateActualName(en, rawEnumName); addParentNamespaceAnnotation(en, e.getParentNamespace()); if (!result.config.noComments) { en.importComments(e, "enum values", getFileCommentContent(e)); en.setType(Enum.Type.Java); en.setTag(enumName.clone()); en.addModifiers(ModifierType.Public); out.addDeclaration(new TaggedTypeRefDeclaration(en)); Struct body = new Struct(); en.setBody(body); boolean hasValidItem = false; for (EnumItemResult er : results.values()) { en.addItem(item); hasValidItem = true; if (!result.config.noComments) { en.addInterface(ident(IntValuedEnum.class, expr(typeRef(enumName.clone())))); String valueArgName = "value"; body.addDeclaration(new Function(Type.JavaMethod, enumName.clone(), null, new Arg(valueArgName, typeRef(Long.TYPE))).setBody(block(
@Override public void visitEnum(Enum e) { super.visitEnum(e); if (e.getTag() == null) { Element nextDeclaration = e.getNextSibling(); if (nextDeclaration != null && (nextDeclaration instanceof TypeDef)) { TypeDef typeDef = (TypeDef) nextDeclaration; String name = bestPlainStorage.resolveName(); System.err.println("Automatic struct name matching : " + name); e.setTag(ident(name)); Identifier name = e.getTag(); String lib = getLibrary(e); if (name == null) { e.setResolvedJavaIdentifier(typeConverter.computeTaggedTypeIdentifierInJava(e)); if (!currentNamespace.isEmpty()) e.setParentNamespace(currentNamespace.peek().clone()); Identifier originalName = e.getOriginalTag(); if (originalName != null) { enumsByName.put(originalName, e);
@Override public void visitEnum(Enum e) { Element parent = e.getParentElement(); if (e.getTag() == null && !(parent instanceof TypeDef)) { // Hack to infer the enum name from the next typedef NSUInteger NSSomethingThatLooksLikeTheEnumsIdentifiers Element base = parent instanceof Declaration ? e.getParentElement() : e; Element next = base.getNextSibling(); if (!handleAppleEnumTypeDef(next, e)) { Element previous = base.getPreviousSibling(); Element beforePrevious = previous == null ? null : previous.getPreviousSibling(); if (previous != null && !(beforePrevious instanceof TaggedTypeRefDeclaration && ((TaggedTypeRefDeclaration) beforePrevious).getTaggedTypeRef() instanceof Enum)) { handleAppleEnumTypeDef(previous, e); } } } String comment = e.getCommentBefore(); if (comment != null) { // TODO parse cocoa comments here } super.visitEnum(e); }
public void convertEnums(List<Enum> enums, Signatures signatures, DeclarationsHolder out) { Identifier libraryClassName = out.getResolvedJavaIdentifier(); if (enums != null) { //out.println("public static class ENUMS {"); for (com.ochafik.lang.jnaerator.parser.Enum e : enums) { if (e.findParentOfType(Struct.class) != null) { continue; } if (skip(e.getTag() + "", result.config.skippedEnumNames)) continue; convertEnum(e, signatures, out, libraryClassName); } //out.println("}"); } } Map<String, Pair<Function, List<Function>>> functionAlternativesByNativeSignature = new LinkedHashMap<String, Pair<Function, List<Function>>>();
if (e.getTag() != null && !StringUtils.trimUnderscores(e.getTag().toString()).equals(name)) { return false; Element ep = e.getParentElement(); ep.addToCommentBefore(typeDef.getCommentBefore()); ep.addToCommentBefore(typeDef.getCommentAfter());
@Override public Expression getEnumItemValue(Enum.EnumItem enumItem, boolean forceConstants) { Enum e = (Enum) enumItem.getParentElement(); if (forceConstants) { Map<String, EnumItemResult> values = getEnumValuesAndCommentsByName(e, null); EnumItemResult enumResult = values.get(enumItem.getName()); if (enumResult != null) { return enumResult.constantValue; } } Expression enumValue = findEnumItem(enumItem); if (e.getTag() != null) { enumValue = methodCall(enumValue, "value"); } return cast(typeRef(int.class), enumValue.setParenthesis(true)); }