List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration setReceiverType
public void setReceiverType(Type receiverType)
From source file:org.decojer.cavaj.transformers.TrOutline.java
License:Open Source License
/** * Decompile method parameters (parameter types, return type, exception types, annotations, * names)./*from w w w .java2s. 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)); } } }