resolvedCreatedType.isInnerClass() && !resolvedCreatedType.isStatic() && isEnclosedBy(resolvedCreatedType, argumentType)) { if (isContextWithinTypeInstance(argumentType) && firstArgument instanceof ThisReferenceExpression) {
new RewriteLocalClassesTransform(context), new IntroduceOuterClassReferencesTransform(context), new RewriteInnerClassConstructorCalls(context), new RemoveRedundantInitializersTransform(context), new FlattenElseIfStatementsTransform(context),
isEnclosedBy(resolvedCreatedType, argumentType)) { if (isContextWithinTypeInstance(argumentType) && firstArgument instanceof ThisReferenceExpression) {
private static boolean isEnclosedBy(final TypeReference innerType, final TypeReference outerType) { if (innerType == null) { return false; } for (TypeReference current = innerType.getDeclaringType(); current != null; current = current.getDeclaringType()) { if (MetadataResolver.areEquivalent(current, outerType)) { return true; } } final TypeDefinition resolvedInnerType = innerType.resolve(); return resolvedInnerType != null && isEnclosedBy(resolvedInnerType.getBaseType(), outerType); }
new RewriteLocalClassesTransform(context), new IntroduceOuterClassReferencesTransform(context), new RewriteInnerClassConstructorCalls(context), new RemoveRedundantInitializersTransform(context), new FlattenElseIfStatementsTransform(context),
private static boolean isEnclosedBy(final TypeReference innerType, final TypeReference outerType) { if (innerType == null) { return false; } for (TypeReference current = innerType.getDeclaringType(); current != null; current = current.getDeclaringType()) { if (MetadataResolver.areEquivalent(current, outerType)) { return true; } } final TypeDefinition resolvedInnerType = innerType.resolve(); return resolvedInnerType != null && isEnclosedBy(resolvedInnerType.getBaseType(), outerType); }
resolvedCreatedType.isInnerClass() && !resolvedCreatedType.isStatic() && isEnclosedBy(resolvedCreatedType, argumentType)) { if (isContextWithinTypeInstance(argumentType) && firstArgument instanceof ThisReferenceExpression) {
new RewriteLocalClassesTransform(context), new IntroduceOuterClassReferencesTransform(context), new RewriteInnerClassConstructorCalls(context), new RemoveRedundantInitializersTransform(context), new FlattenElseIfStatementsTransform(context),
@Override @SuppressWarnings("ConstantConditions") public Void visitSuperReferenceExpression(final SuperReferenceExpression node, final Void data) { super.visitSuperReferenceExpression(node, data); if (node.getParent() instanceof InvocationExpression) { final InvocationExpression parent = (InvocationExpression) node.getParent(); if (!parent.getArguments().isEmpty()) { final Expression firstArgument = parent.getArguments().firstOrNullObject(); final ResolveResult resolvedArgument = _resolver.apply(firstArgument); if (resolvedArgument != null) { final TypeReference superType = node.getUserData(Keys.TYPE_REFERENCE); final TypeReference argumentType = resolvedArgument.getType(); if (superType != null && argumentType != null) { final TypeDefinition resolvedSuperType = superType.resolve(); if (resolvedSuperType != null && resolvedSuperType.isInnerClass() && !resolvedSuperType.isStatic() && isEnclosedBy(context.getCurrentType(), argumentType)) { firstArgument.remove(); if (!(firstArgument instanceof ThisReferenceExpression)) { node.setTarget(firstArgument); } } } } } } return null; }
@Override @SuppressWarnings("ConstantConditions") public Void visitSuperReferenceExpression(final SuperReferenceExpression node, final Void data) { super.visitSuperReferenceExpression(node, data); if (node.getParent() instanceof InvocationExpression) { final InvocationExpression parent = (InvocationExpression) node.getParent(); if (!parent.getArguments().isEmpty()) { final Expression firstArgument = parent.getArguments().firstOrNullObject(); final ResolveResult resolvedArgument = _resolver.apply(firstArgument); if (resolvedArgument != null) { final TypeReference superType = node.getUserData(Keys.TYPE_REFERENCE); final TypeReference argumentType = resolvedArgument.getType(); if (superType != null && argumentType != null) { final TypeDefinition resolvedSuperType = superType.resolve(); if (resolvedSuperType != null && resolvedSuperType.isInnerClass() && !resolvedSuperType.isStatic() && isEnclosedBy(context.getCurrentType(), argumentType)) { firstArgument.remove(); if (!(firstArgument instanceof ThisReferenceExpression)) { node.setTarget(firstArgument); } } } } } } return null; }