List of usage examples for org.eclipse.jdt.core.dom AST newAnnotationTypeDeclaration
public AnnotationTypeDeclaration newAnnotationTypeDeclaration()
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;//from ww w . java 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: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;/* ww w . j av a 2 s. c o 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;/*from w w w. ja v a2 s. c om*/ 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; }