List of usage examples for org.eclipse.jdt.core.dom AST newEnumDeclaration
public EnumDeclaration newEnumDeclaration()
From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaTypeModelAdapter.java
License:Open Source License
public static Object createCorrespondingModelElement(AST ast, CodeSyncElement cse) { ASTNode child = null;/*w w w . j a va 2 s. c o m*/ if (JavaAttributeModelAdapter.ATTRIBUTE.equals(cse.getType())) { VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment(); FieldDeclaration field = ast.newFieldDeclaration(fragment); child = field; } if (JavaOperationModelAdapter.OPERATION.equals(cse.getType())) { child = ast.newMethodDeclaration(); } if (CLASS.equals(cse.getType())) { child = ast.newTypeDeclaration(); } if (INTERFACE.equals(cse.getType())) { TypeDeclaration type = ast.newTypeDeclaration(); type.setInterface(true); child = type; } if (ENUM.equals(cse.getType())) { child = ast.newEnumDeclaration(); } if (ANNOTATION.equals(cse.getType())) { child = ast.newAnnotationTypeDeclaration(); } return child; }
From source file:de.crowdcode.kissmda.cartridges.simplejava.EnumGenerator.java
License:Apache License
/** * Generate the Enum from UML.// w w w . j a v a 2 s . c o m * * @param clazz * the UML class * @param ast * the JDT Java AST * @param cu * the generated Java compilation unit * @return EnumDeclaration */ @SuppressWarnings("unchecked") public EnumDeclaration generateEnum(Classifier clazz, AST ast, CompilationUnit cu) { String className = getClassName(clazz); EnumDeclaration ed = ast.newEnumDeclaration(); ed.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); ed.setName(ast.newSimpleName(className)); cu.types().add(ed); return ed; }
From source file:de.dentrassi.varlink.generator.JdtGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") private void createEnum(final TypeDeclaration td, final String name, final EList<String> literals) { final AST ast = td.getAST(); final EnumDeclaration ed = ast.newEnumDeclaration(); td.bodyDeclarations().add(ed);//from w ww .j a v a 2s .c om ed.setName(ast.newSimpleName(name)); make(ed, PUBLIC_KEYWORD, STATIC_KEYWORD); for (final String literal : literals) { final EnumConstantDeclaration ecd = ast.newEnumConstantDeclaration(); ecd.setName(ast.newSimpleName(literal)); ed.enumConstants().add(ecd); } }
From source file:org.asup.dk.compiler.rpj.writer.JDTMessageFileWriter.java
License:Open Source License
@SuppressWarnings("unchecked") private EnumDeclaration buildEnumDeclaration(AST ast, String name, List<QMessageDescription> messageDescriptions) { // write AST//from w ww.j a va2 s. co m EnumDeclaration enumDeclaration = ast.newEnumDeclaration(); enumDeclaration.setName(ast.newSimpleName(name)); enumDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); for (QMessageDescription messageDescription : messageDescriptions) { EnumConstantDeclaration constantDeclaration = ast.newEnumConstantDeclaration(); constantDeclaration.setName(ast.newSimpleName(messageDescription.getName())); enumDeclaration.enumConstants().add(constantDeclaration); /* * Javadoc javadoc = ast.newJavadoc(); TagElement tag = * javadoc.getAST().newTagElement(); TextElement textElement = * javadoc.getAST().newTextElement(); * textElement.setText(messageDescription.getMessageText()); * tag.fragments().add(textElement); javadoc.tags().add(tag); * * constantDeclaration.setJavadoc(javadoc); */ } return enumDeclaration; }
From source file:org.decojer.cavaj.transformers.TrOutline.java
License:Open Source License
private static void decompileType(@Nonnull final T t, @Nonnull final CU cu) { if (checkTypeIgnore(t, cu)) { return;/* w ww .j ava2 s . co m*/ } final AST ast = cu.getAst(); // AF.STRICTFP is no valid inner modifier for bytecode, strictfp modifier at class generates // strictfp modifier for all method in class -> check here and oppress then in methods boolean strictFp = false; for (final Element declaration : t.getDeclarations()) { if (!(declaration instanceof M)) { continue; } if (!((M) declaration).getAf(AF.STRICTFP)) { break; } strictFp = true; } if (t.getAstNode() == null) { AbstractTypeDeclaration typeDeclaration = null; // annotation type declaration if (t.getAf(AF.ANNOTATION)) { final T superT = t.getSuperT(); if (superT == null || !superT.isObject()) { log.warn("Classfile with AccessFlag.ANNOTATION has no super class Object but has '" + superT + "'!"); } if (t.getInterfaceTs().length != 1 || !t.getInterfaceTs()[0].is(Annotation.class)) { log.warn("Classfile with AccessFlag.ANNOTATION has no interface '" + Annotation.class.getName() + "' but has '" + t.getInterfaceTs()[0] + "'!"); } typeDeclaration = ast.newAnnotationTypeDeclaration(); } // enum declaration if (t.isEnum() && !t.getCu().check(DFlag.IGNORE_ENUM)) { if (typeDeclaration != null) { log.warn("Enum declaration cannot be an annotation type declaration! Ignoring."); } else { final T superT = t.getSuperT(); if (superT == null || !superT.isParameterized() || !superT.is(Enum.class)) { log.warn("Enum type '" + t + "' has no super class '" + Enum.class.getName() + "' but has '" + superT + "'!"); } typeDeclaration = ast.newEnumDeclaration(); // enums cannot extend other classes than Enum.class, but can have interfaces if (t.getInterfaceTs() != null) { for (final T interfaceT : t.getInterfaceTs()) { assert interfaceT != null; ((EnumDeclaration) typeDeclaration).superInterfaceTypes().add(newType(interfaceT, t)); } } } } // no annotation type declaration or enum declaration => normal class or interface type // declaration if (typeDeclaration == null) { typeDeclaration = ast.newTypeDeclaration(); decompileTypeParams(t.getTypeParams(), ((TypeDeclaration) typeDeclaration).typeParameters(), t); final T superT = t.getSuperT(); if (superT != null && !superT.isObject()) { ((TypeDeclaration) typeDeclaration).setSuperclassType(newType(superT, t)); } for (final T interfaceT : t.getInterfaceTs()) { assert interfaceT != null; ((TypeDeclaration) typeDeclaration).superInterfaceTypes().add(newType(interfaceT, t)); } } t.setAstNode(typeDeclaration); final List<IExtendedModifier> modifiers = typeDeclaration.modifiers(); assert modifiers != null; // add annotation modifiers before other modifiers, order preserved in source code // generation through eclipse.jdt if (t.getAs() != null) { Annotations.decompileAnnotations(t.getAs(), modifiers, t); } // decompile remaining modifier flags if (t.getAf(AF.PUBLIC)) { modifiers.add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD)); } // for inner classes if (t.getAf(AF.PRIVATE)) { modifiers.add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD)); } // for inner classes if (t.getAf(AF.PROTECTED)) { modifiers.add(ast.newModifier(ModifierKeyword.PROTECTED_KEYWORD)); } // for inner classes if (t.isStatic() && !t.isInterface()) { modifiers.add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD)); } if (t.getAf(AF.FINAL) && !(typeDeclaration instanceof EnumDeclaration)) { // enum declaration is final by default modifiers.add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD)); } if (t.isInterface()) { if (typeDeclaration instanceof TypeDeclaration) { ((TypeDeclaration) typeDeclaration).setInterface(true); } } else if (!t.getAf(AF.SUPER) && !t.isDalvik()) { // modern invokesuper syntax, is always set in current JVM, but not in Dalvik or // inner classes info flags log.warn("Modern invokesuper syntax flag not set in type '" + t + "'!"); } if (t.getAf(AF.ABSTRACT) && !(typeDeclaration instanceof AnnotationTypeDeclaration) && !(typeDeclaration instanceof EnumDeclaration) && !(typeDeclaration instanceof TypeDeclaration && ((TypeDeclaration) typeDeclaration).isInterface())) { modifiers.add(ast.newModifier(ModifierKeyword.ABSTRACT_KEYWORD)); } if (strictFp) { modifiers.add(ast.newModifier(ModifierKeyword.STRICTFP_KEYWORD)); } final String simpleName = t.getSimpleName(); typeDeclaration.setName(newSimpleName(simpleName.length() > 0 ? simpleName : t.getPName(), ast)); // decompile synthetic Javadoc-comment if no annotation set if (t.isSynthetic()) { final Javadoc javadoc = ast.newJavadoc(); final TagElement tagElement = ast.newTagElement(); tagElement.setTagName("is synthetic"); javadoc.tags().add(tagElement); typeDeclaration.setJavadoc(javadoc); } if (t.getAf(AF.DEPRECATED) && !Annotations.isDeprecatedAnnotation(t.getAs())) { final Javadoc javadoc = ast.newJavadoc(); final TagElement tagElement = ast.newTagElement(); tagElement.setTagName("@deprecated"); javadoc.tags().add(tagElement); typeDeclaration.setJavadoc(javadoc); } } for (final Element bd : t.getDeclarations()) { if (bd instanceof F) { decompileField((F) bd, cu); } if (bd instanceof M) { decompileMethod((M) bd, cu, strictFp); } } }
From source file:org.flowerplatform.codesync.code.java.adapter.JavaTypeDeclarationModelAdapter.java
License:Open Source License
public static Object createCorrespondingModelElement(AST ast, Node node) { ASTNode child = null;//w ww .j a v a2 s . co m if (CodeSyncCodeJavaConstants.ATTRIBUTE.equals(node.getType())) { VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment(); FieldDeclaration field = ast.newFieldDeclaration(fragment); child = field; } else if (CodeSyncCodeJavaConstants.OPERATION.equals(node.getType())) { child = ast.newMethodDeclaration(); } else if (CodeSyncCodeJavaConstants.ENUM_CONSTANT.equals(node.getType())) { child = ast.newEnumConstantDeclaration(); } else if (CodeSyncCodeJavaConstants.CLASS.equals(node.getType())) { child = ast.newTypeDeclaration(); } else if (CodeSyncCodeJavaConstants.INTERFACE.equals(node.getType())) { TypeDeclaration type = ast.newTypeDeclaration(); type.setInterface(true); child = type; } else if (CodeSyncCodeJavaConstants.ENUM.equals(node.getType())) { child = ast.newEnumDeclaration(); } else if (CodeSyncCodeJavaConstants.ANNOTATION_TYPE.equals(node.getType())) { child = ast.newAnnotationTypeDeclaration(); } return child; }