List of usage examples for org.eclipse.jdt.core.dom AST apiLevel
int apiLevel
To view the source code for org.eclipse.jdt.core.dom AST apiLevel.
Click Source Link
From source file:astview.SettingsProperty.java
License:Open Source License
@Override public Object[] getChildren() { AST ast = fRoot.getAST(); Object[] res = { new GeneralAttribute(this, "apiLevel", String.valueOf(ast.apiLevel())), new GeneralAttribute(this, "hasResolvedBindings", String.valueOf(ast.hasResolvedBindings())), new GeneralAttribute(this, "hasStatementsRecovery", String.valueOf(ast.hasStatementsRecovery())), new GeneralAttribute(this, "hasBindingsRecovery", String.valueOf(ast.hasBindingsRecovery())), }; return res;//from ww w . ja v a2 s . c o m }
From source file:cideplus.ui.astview.SettingsProperty.java
License:Open Source License
public Object[] getChildren() { AST ast = fRoot.getAST(); Object[] res = { new GeneralAttribute(this, "apiLevel", String.valueOf(ast.apiLevel())), new GeneralAttribute(this, "hasResolvedBindings", String.valueOf(ast.hasResolvedBindings())), new GeneralAttribute(this, "hasStatementsRecovery", String.valueOf(ast.hasStatementsRecovery())), new GeneralAttribute(this, "hasBindingsRecovery", String.valueOf(ast.hasBindingsRecovery())), }; return res;//from w w w . j a v a2 s. c om }
From source file:org.decojer.cavaj.transformers.TrOutline.java
License:Open Source License
/** * Decompile method parameters (parameter types, return type, exception types, annotations, * names)./* w ww.ja v a 2s. co m*/ * * @param m * method declaration */ @SuppressWarnings("deprecation") private static void decompileMethodParams(final M m) { // method type parameters (full signature only): // <T:Ljava/lang/Integer;U:Ljava/lang/Long;>(TT;TU;)V // <U:TT;>(TT;TU;)V final Object astNode = m.getAstNode(); if (!(astNode instanceof MethodDeclaration)) { assert false; return; } final MethodDeclaration methodDeclaration = (MethodDeclaration) astNode; final T t = m.getT(); assert t != null : "decompile method cannot be dynamic"; final AST ast = t.getCu().getAst(); final T[] paramTs = m.getParamTs(); final T receiverT = m.getReceiverT(); if (receiverT != null) { methodDeclaration.setReceiverType(newType(receiverT, t)); } final A[][] paramAss = m.getParamAss(); for (int i = 0; i < paramTs.length; ++i) { if (m.isConstructor()) { if (i <= 1 && t.isEnum() && !t.getCu().check(DFlag.IGNORE_ENUM)) { // enum constructors have two leading synthetic parameters, // enum classes are static and can not be anonymous or inner method if (i == 0 && m.getParamTs()[0].is(String.class)) { continue; } if (i == 1 && m.getParamTs()[1] == T.INT) { continue; } } if (i == 0 && t.isInner() && !t.getCu().check(DFlag.IGNORE_CONSTRUCTOR_THIS)) { // inner class constructor has synthetic this reference as first argument: skip if (m.getParamTs()[0].is(t.getEnclosingT())) { continue; } log.warn(m + ": Inner class constructor has no synthetic this reference as first argument!"); } // anonymous inner classes cannot have visible Java constructors, don't handle // here but ignore in merge all // method inner classes have extra trailing parameters for visible outer finals, // that are used in other methods // static inner classes can only have top-level or static outer, // anonymous inner classes are static if context is static, // enums are static and can not be anonymous or inner method } methodDeclaration.parameters().add(newSingleVariableDeclaration(m, paramTs, paramAss, i, t)); } // decompile return type methodDeclaration.setReturnType2(newType(m.getReturnT(), t)); // decompile exceptions for (final T throwT : m.getThrowsTs()) { assert throwT != null; // Eclipse AST expects a List<Name> for thrownExceptions, not a List<Type>: // is OK - thrownExceptions cannot be generic if (ast.apiLevel() <= AST.JLS4) { methodDeclaration.thrownExceptions().add(newTypeName(throwT, t)); } else { methodDeclaration.thrownExceptionTypes().add(newType(throwT, t)); } } }
From source file:org.decojer.cavaj.utils.Expressions.java
License:Open Source License
/** * New single variable declaration.//www. j a va 2s .c o m * * @param m * method declaration * @param paramTs * parameter types * @param paramAss * parameter annotations * @param i * index * @param contextT * type declaration (context) * @return single variable declaration */ @SuppressWarnings("deprecation") public static SingleVariableDeclaration newSingleVariableDeclaration(final M m, final T[] paramTs, final A[][] paramAss, final int i, final T contextT) { final AST ast = contextT.getCu().getAst(); final SingleVariableDeclaration singleVariableDeclaration = ast.newSingleVariableDeclaration(); if (paramAss != null && i < paramAss.length) { final List<IExtendedModifier> modifiers = singleVariableDeclaration.modifiers(); assert modifiers != null; Annotations.decompileAnnotations(paramAss[i], modifiers, contextT); } final T paramT = paramTs[i]; assert paramT != null; final Type methodParameterType = newType(paramT, contextT); // decompile varargs (flag set, ArrayType and last method param) if (i == paramTs.length - 1 && m.isVarargs()) { if (methodParameterType instanceof ArrayType) { singleVariableDeclaration.setVarargs(true); // must copy because we cannot delete mandatory ArrayType.componentType if (ast.apiLevel() <= AST.JLS4) { singleVariableDeclaration.setType( (Type) ASTNode.copySubtree(ast, ((ArrayType) methodParameterType).getComponentType())); } else { singleVariableDeclaration.setType( (Type) ASTNode.copySubtree(ast, ((ArrayType) methodParameterType).getElementType())); } } else { log.warn("Last method parameter is no ArrayType, but method '" + m.getName() + "' has vararg attribute!"); // try handling as normal type singleVariableDeclaration.setType(methodParameterType); } } else { singleVariableDeclaration.setType(methodParameterType); } singleVariableDeclaration.setName(newSimpleName(m.getParamName(i), ast)); return singleVariableDeclaration; }
From source file:org.decojer.cavaj.utils.Expressions.java
License:Open Source License
/** * New type.//w w w . j a v a 2s. c om * * @param t * type * @param context * context * @return AST type */ @SuppressWarnings("deprecation") public static Type newType(@Nonnull final T t, @Nonnull final Element context) { final AST ast = context.getCu().getAst(); // handle array first because annot(array()) is special if (t.isArray()) { if (ast.apiLevel() <= AST.JLS4) { final T componentT = t.getComponentT(); assert componentT != null; return ast.newArrayType(newType(componentT, context)); } final T elementT = t.getElementT(); assert elementT != null; for (T checkT = t; checkT != null && checkT.isArray(); checkT = checkT.getComponentT()) { if (checkT.isAnnotated()) { final ArrayType arrayType = ast.newArrayType(newType(elementT, context)); final List<Dimension> dimensions = arrayType.dimensions(); dimensions.clear(); for (T componentT = t; componentT != null && componentT.isArray(); componentT = componentT.getComponentT()) { final Dimension dimension = ast.newDimension(); final List<IExtendedModifier> annotations = dimension.annotations(); assert annotations != null; if (componentT.isAnnotated()) { Annotations.decompileAnnotations(componentT, annotations, context); } dimensions.add(dimension); } return arrayType; } } return ast.newArrayType(newType(elementT, context), t.getDimensions()); } if (t.isAnnotated()) { Type type = newType(t.getRawT(), context); if (ast.apiLevel() <= AST.JLS4) { log.warn("Cannot decompile type annotations for type '" + t + "' in Eclipse AST JLS4!"); return type; } // parameterized type is not directly annotateable in Eclipse; but DecoJer thinks the // whole type is meant, not just the generic type, hence translate here AnnotatableType annotatableType = (AnnotatableType) (type instanceof ParameterizedType ? ((ParameterizedType) type).getType() : type); qualified: if (annotatableType instanceof SimpleType) { // direct annotation of qualified types adds the annotations as first element, // strange Java spec doesn't allow "@A package.Name" but wants "package.@A Name" final Name typeName = ((SimpleType) annotatableType).getName(); if (!(typeName instanceof QualifiedName)) { break qualified; } final Name qualifier = ((QualifiedName) typeName).getQualifier(); final SimpleName name = ((QualifiedName) typeName).getName(); // cannot delete mandory childs, copy them annotatableType = ast.newNameQualifiedType((Name) ASTNode.copySubtree(ast, qualifier), (SimpleName) ASTNode.copySubtree(ast, name)); if (type instanceof ParameterizedType) { ((ParameterizedType) type).setType(annotatableType); } else { type = annotatableType; } } final List<IExtendedModifier> annotations = annotatableType.annotations(); assert annotations != null; Annotations.decompileAnnotations(t, annotations, context); return type; } // doesn't work, now with Dimension (see above): if (t.isArray()) { return // ast.newArrayType(newType(t.getComponentT(), contextT)); } if (t.isParameterized()) { final T genericT = t.getGenericT(); assert genericT != null; final ParameterizedType parameterizedType = ast.newParameterizedType(newType(genericT, context)); for (final T typeArg : t.getTypeArgs()) { assert typeArg != null; parameterizedType.typeArguments().add(newType(typeArg, context)); } return parameterizedType; } if (t.isWildcard()) { final T boundT = t.getBoundT(); if (boundT == null) { return ast.newWildcardType(); } if (t.isSubclassOf()) { final WildcardType wildcardType = ast.newWildcardType(); // default...newWildcardType.setUpperBound(true); wildcardType.setBound(newType(boundT, context)); return wildcardType; } final WildcardType wildcardType = ast.newWildcardType(); wildcardType.setUpperBound(false); wildcardType.setBound(newType(boundT, context)); return wildcardType; } if (t.isMulti()) { log.warn("Convert type for multi-type '" + t + "'!"); // prefer boolean for multi-type with 0 or 1, synchronous to newLiteral()! // prefer byte before char if no explicit char type given } if (t.is(T.BOOLEAN)) { return ast.newPrimitiveType(PrimitiveType.BOOLEAN); } if (t.is(T.BYTE)) { return ast.newPrimitiveType(PrimitiveType.BYTE); } if (t.is(T.CHAR)) { return ast.newPrimitiveType(PrimitiveType.CHAR); } if (t.is(T.SHORT)) { return ast.newPrimitiveType(PrimitiveType.SHORT); } if (t.is(T.INT)) { return ast.newPrimitiveType(PrimitiveType.INT); } if (t.is(T.FLOAT)) { return ast.newPrimitiveType(PrimitiveType.FLOAT); } if (t.is(T.LONG)) { return ast.newPrimitiveType(PrimitiveType.LONG); } if (t.is(T.DOUBLE)) { return ast.newPrimitiveType(PrimitiveType.DOUBLE); } if (t.is(T.VOID)) { return ast.newPrimitiveType(PrimitiveType.VOID); } if (t.isQualified()) { final T qualifierT = t.getQualifierT(); assert qualifierT != null : "cannot be null for qualified"; // could be ParamT etc., not decompileable with name as target; // restrict qualifications to really necessary enclosings: // t = Outer.Inner.InnerInner, t = Outer.Inner ==> Inner final T contextT = context.getT(); assert contextT != null; if (contextT.getFullName().startsWith(qualifierT.getFullName())) { // TODO full name has too much info yet (like annotations) return ast.newSimpleType(newSimpleName(t.getSimpleIdentifier(), ast)); } return ast.newQualifiedType(newType(qualifierT, context), newSimpleName(t.getSimpleIdentifier(), ast)); } // else fall through... return ast.newSimpleType(newTypeName(t, context)); }