@SuppressWarnings("unchecked") void enter(CtElement e, ASTNode node) { stack.push(new ASTPair(e, node)); if (!(e instanceof CtPackage) || (compilationUnitSpoon.getFile() != null && compilationUnitSpoon.getFile().getName().equals(DefaultJavaPrettyPrinter.JAVA_PACKAGE_DECLARATION))) { if (compilationunitdeclaration != null && !e.isImplicit()) { e.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPositionCtElement(e, node)); } } ASTPair pair = stack.peek(); CtElement current = pair.element; if (current instanceof CtExpression) { while (!casts.isEmpty()) { ((CtExpression<?>) current).addTypeCast(casts.remove(0).typeRef); } } try { if (e instanceof CtTypedElement && !(e instanceof CtConstructorCall) && !(e instanceof CtCatchVariable) && node instanceof Expression) { if (((CtTypedElement<?>) e).getType() == null) { ((CtTypedElement<Object>) e).setType(this.jdtTreeBuilder.getReferencesBuilder().getTypeReference(((Expression) node).resolvedType)); } } } catch (UnsupportedOperationException ignore) { // For some element, we throw an UnsupportedOperationException when we call setType(). } }
private static void addTypeCastIfNeeded(CtExpression<?> variableRead, Object value) { if (value instanceof Short) { variableRead.addTypeCast(variableRead.getFactory().Type().shortPrimitiveType()); } else if (value instanceof Integer) { variableRead.addTypeCast(variableRead.getFactory().Type().integerPrimitiveType()); } else if (value instanceof Long) { variableRead.addTypeCast(variableRead.getFactory().Type().longPrimitiveType()); } else if (value instanceof Byte) { variableRead.addTypeCast(variableRead.getFactory().Type().bytePrimitiveType()); } else if (value instanceof Float) { variableRead.addTypeCast(variableRead.getFactory().Type().floatPrimitiveType()); } else if (value instanceof Double) { variableRead.addTypeCast(variableRead.getFactory().Type().doublePrimitiveType()); } else if (value instanceof Character) { variableRead.addTypeCast(variableRead.getFactory().Type().characterPrimitiveType()); } }
((CtExpression<?>) current).addTypeCast(casts.remove(0));
invocation.getTarget().addTypeCast(reference); final CtExecutableReference<?> referenceToGetter = factory.createExecutableReference(); referenceToGetter.setSimpleName(executableName);