Java Code Examples for org.eclipse.jdt.internal.corext.dom.Bindings#normalizeTypeBinding()

The following examples show how to use org.eclipse.jdt.internal.corext.dom.Bindings#normalizeTypeBinding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReturnTypeSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public ITypeBinding getTypeBinding(AST ast) {
	boolean couldBeObject= false;
	for (int i= 0; i < fResult.size(); i++) {
		ReturnStatement node= fResult.get(i);
		Expression expr= node.getExpression();
		if (expr != null) {
			ITypeBinding binding= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
			if (binding != null) {
				return binding;
			} else {
				couldBeObject= true;
			}
		} else {
			return ast.resolveWellKnownType("void"); //$NON-NLS-1$
		}
	}
	if (couldBeObject) {
		return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	}
	return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
 
Example 2
Source File: NewCUUsingWizardProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fill-in the "Super Class" and "Super Interfaces" fields.
 * @param page the wizard page.
 */
private void fillInWizardPageSuperTypes(NewTypeWizardPage page) {
	ITypeBinding type= getPossibleSuperTypeBinding(fNode);
	type= Bindings.normalizeTypeBinding(type);
	if (type != null) {
		if (type.isArray()) {
			type= type.getElementType();
		}
		if (type.isTopLevel() || type.isMember()) {
			if (type.isClass() && (fTypeKind == K_CLASS)) {
				page.setSuperClass(type.getQualifiedName(), true);
			} else if (type.isInterface()) {
				List<String> superInterfaces= new ArrayList<String>();
				superInterfaces.add(type.getQualifiedName());
				page.setSuperInterfaces(superInterfaces, true);
			}
		}
	}
}
 
Example 3
Source File: UnresolvedElementsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ITypeBinding[] getArgumentTypes(List<Expression> arguments) {
	ITypeBinding[] res= new ITypeBinding[arguments.size()];
	for (int i= 0; i < res.length; i++) {
		Expression expression= arguments.get(i);
		ITypeBinding curr= expression.resolveTypeBinding();
		if (curr == null) {
			return null;
		}
		if (!curr.isNullType()) {	// don't normalize null type
			curr= Bindings.normalizeTypeBinding(curr);
			if (curr == null) {
				curr= expression.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
			}
		}
		res[i]= curr;
	}
	return res;
}
 
Example 4
Source File: UnresolvedElementsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static ITypeBinding[] getArgumentTypes(List<Expression> arguments) {
	ITypeBinding[] res= new ITypeBinding[arguments.size()];
	for (int i= 0; i < res.length; i++) {
		Expression expression= arguments.get(i);
		ITypeBinding curr= expression.resolveTypeBinding();
		if (curr == null) {
			return null;
		}
		if (!curr.isNullType()) {	// don't normalize null type
			curr= Bindings.normalizeTypeBinding(curr);
			if (curr == null) {
				curr= expression.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
			}
		}
		res[i]= curr;
	}
	return res;
}
 
Example 5
Source File: ReturnTypeSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ITypeBinding getTypeBinding(AST ast) {
	boolean couldBeObject= false;
	for (int i= 0; i < fResult.size(); i++) {
		ReturnStatement node= fResult.get(i);
		Expression expr= node.getExpression();
		if (expr != null) {
			ITypeBinding binding= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
			if (binding != null) {
				return binding;
			} else {
				couldBeObject= true;
			}
		} else {
			return ast.resolveWellKnownType("void"); //$NON-NLS-1$
		}
	}
	if (couldBeObject) {
		return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	}
	return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
 
Example 6
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ITypeBinding guessBindingForTypeReference(ASTNode node) {
  	StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
  	if (locationInParent == QualifiedName.QUALIFIER_PROPERTY) {
  		return null; // can't guess type for X.A
  	}
if (locationInParent == SimpleType.NAME_PROPERTY ||
		locationInParent == NameQualifiedType.NAME_PROPERTY) {
  		node= node.getParent();
  	}
  	ITypeBinding binding= Bindings.normalizeTypeBinding(getPossibleTypeBinding(node));
  	if (binding != null) {
  		if (binding.isWildcardType()) {
  			return normalizeWildcardType(binding, true, node.getAST());
  		}
  	}
  	return binding;
  }
 
Example 7
Source File: RefactorProposalUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static CUCorrectionProposal getAssignFieldProposal(CodeActionParams params, IInvocationContext context, boolean problemsAtLocation, Map formatterOptions, boolean returnAsCommand,
		IProblemLocationCore[] locations) throws CoreException {
	ASTNode node = context.getCoveringNode();
	Statement statement = ASTResolving.findParentStatement(node);
	if (!(statement instanceof ExpressionStatement)) {
		return null;
	}
	ExpressionStatement expressionStatement = (ExpressionStatement) statement;
	Expression expression = expressionStatement.getExpression();
	if (expression.getNodeType() == ASTNode.ASSIGNMENT) {
		return null;
	}
	ITypeBinding typeBinding = expression.resolveTypeBinding();
	typeBinding = Bindings.normalizeTypeBinding(typeBinding);
	if (typeBinding == null) {
		return null;
	}
	if (containsMatchingProblem(locations, IProblem.UnusedObjectAllocation)) {
		return null;
	}
	final ICompilationUnit cu = context.getCompilationUnit();
	ASTNode type = ASTResolving.findParentType(expression);
	if (type != null) {
		int relevance;
		if (context.getSelectionLength() == 0) {
			relevance = IProposalRelevance.EXTRACT_LOCAL_ZERO_SELECTION;
		} else if (problemsAtLocation) {
			relevance = IProposalRelevance.EXTRACT_LOCAL_ERROR;
		} else {
			relevance = IProposalRelevance.EXTRACT_LOCAL;
		}
		if (returnAsCommand) {
			return new AssignToVariableAssistCommandProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_FIELD, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, relevance, APPLY_REFACTORING_COMMAND_ID,
					Arrays.asList(ASSIGN_FIELD_COMMAND, params));
		} else {
			return new AssignToVariableAssistProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_FIELD, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, relevance);
		}
	}
	return null;
}
 
Example 8
Source File: NewMethodCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Type evaluateParameterType(AST ast, Expression elem, String key, ImportRewriteContext context) {
	ITypeBinding binding= Bindings.normalizeTypeBinding(elem.resolveTypeBinding());
	if (binding != null && binding.isWildcardType()) {
		binding= ASTResolving.normalizeWildcardType(binding, true, ast);
	}
	if (binding != null) {
		ITypeBinding[] typeProposals= ASTResolving.getRelaxingTypes(ast, binding);
		for (int i= 0; i < typeProposals.length; i++) {
			addLinkedPositionProposal(key, typeProposals[i]);
		}
		return getImportRewrite().addImport(binding, ast, context);
	}
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
Example 9
Source File: UnresolvedElementsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ITypeBinding[] getParameterTypes(List<Expression> args) {
	ITypeBinding[] params= new ITypeBinding[args.size()];
	for (int i= 0; i < args.size(); i++) {
		Expression expr= args.get(i);
		ITypeBinding curr= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
		if (curr != null && curr.isWildcardType()) {
			curr= ASTResolving.normalizeWildcardType(curr, true, expr.getAST());
		}
		if (curr == null) {
			curr= expr.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
		}
		params[i]= curr;
	}
	return params;
}
 
Example 10
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean getAssignToVariableProposals(IInvocationContext context, ASTNode node, IProblemLocation[] locations, Collection<ICommandAccess> resultingCollections) {
	Statement statement= ASTResolving.findParentStatement(node);
	if (!(statement instanceof ExpressionStatement)) {
		return false;
	}
	ExpressionStatement expressionStatement= (ExpressionStatement) statement;

	Expression expression= expressionStatement.getExpression();
	if (expression.getNodeType() == ASTNode.ASSIGNMENT) {
		return false; // too confusing and not helpful
	}

	ITypeBinding typeBinding= expression.resolveTypeBinding();
	typeBinding= Bindings.normalizeTypeBinding(typeBinding);
	if (typeBinding == null) {
		return false;
	}
	if (resultingCollections == null) {
		return true;
	}

	// don't add if already added as quick fix
	if (containsMatchingProblem(locations, IProblem.UnusedObjectAllocation))
		return false;
	
	ICompilationUnit cu= context.getCompilationUnit();

	AssignToVariableAssistProposal localProposal= new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, IProposalRelevance.ASSIGN_TO_LOCAL);
	localProposal.setCommandId(ASSIGN_TO_LOCAL_ID);
	resultingCollections.add(localProposal);

	ASTNode type= ASTResolving.findParentType(expression);
	if (type != null) {
		AssignToVariableAssistProposal fieldProposal= new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, IProposalRelevance.ASSIGN_TO_FIELD);
		fieldProposal.setCommandId(ASSIGN_TO_FIELD_ID);
		resultingCollections.add(fieldProposal);
	}
	return true;

}
 
Example 11
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ITypeBinding guessVariableType(List<VariableDeclarationFragment> fragments) {
	for (Iterator<VariableDeclarationFragment> iter= fragments.iterator(); iter.hasNext();) {
		VariableDeclarationFragment frag= iter.next();
		if (frag.getInitializer() != null) {
			return Bindings.normalizeTypeBinding(frag.getInitializer().resolveTypeBinding());
		}
	}
	return null;
}
 
Example 12
Source File: StubUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, ITypeBinding expectedType, Expression assignedExpression, Collection<String> excluded) {
	LinkedHashSet<String> res= new LinkedHashSet<String>(); // avoid duplicates but keep order

	if (assignedExpression != null) {
		String nameFromExpression= getBaseNameFromExpression(project, assignedExpression, variableKind);
		if (nameFromExpression != null) {
			add(getVariableNameSuggestions(variableKind, project, nameFromExpression, 0, excluded, false), res); // pass 0 as dimension, base name already contains plural.
		}

		String nameFromParent= getBaseNameFromLocationInParent(assignedExpression);
		if (nameFromParent != null) {
			add(getVariableNameSuggestions(variableKind, project, nameFromParent, 0, excluded, false), res); // pass 0 as dimension, base name already contains plural.
		}
	}
	if (expectedType != null) {
		expectedType= Bindings.normalizeTypeBinding(expectedType);
		if (expectedType != null) {
			int dim= 0;
			if (expectedType.isArray()) {
				dim= expectedType.getDimensions();
				expectedType= expectedType.getElementType();
			}
			if (expectedType.isParameterizedType()) {
				expectedType= expectedType.getTypeDeclaration();
			}
			String typeName= expectedType.getName();
			if (typeName.length() > 0) {
				add(getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, false), res);
			}
		}
	}
	if (res.isEmpty()) {
		return getDefaultVariableNameSuggestions(variableKind, excluded);
	}
	return res.toArray(new String[res.size()]);
}
 
Example 13
Source File: NewMethodCorrectionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private Type evaluateParameterType(AST ast, Expression elem, String key, ImportRewriteContext context) {
	ITypeBinding binding= Bindings.normalizeTypeBinding(elem.resolveTypeBinding());
	if (binding != null && binding.isWildcardType()) {
		binding= ASTResolving.normalizeWildcardType(binding, true, ast);
	}
	if (binding != null) {
		return getImportRewrite().addImport(binding, ast, context, TypeLocation.PARAMETER);
	}
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
Example 14
Source File: UnresolvedElementsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static ITypeBinding[] getParameterTypes(List<Expression> args) {
	ITypeBinding[] params= new ITypeBinding[args.size()];
	for (int i= 0; i < args.size(); i++) {
		Expression expr= args.get(i);
		ITypeBinding curr= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
		if (curr != null && curr.isWildcardType()) {
			curr= ASTResolving.normalizeWildcardType(curr, true, expr.getAST());
		}
		if (curr == null) {
			curr= expr.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
		}
		params[i]= curr;
	}
	return params;
}
 
Example 15
Source File: RefactorProposalUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static CUCorrectionProposal getAssignVariableProposal(CodeActionParams params, IInvocationContext context, boolean problemsAtLocation, Map formatterOptions, boolean returnAsCommand,
		IProblemLocationCore[] locations)
		throws CoreException {
	ASTNode node = context.getCoveringNode();
	Statement statement = ASTResolving.findParentStatement(node);
	if (!(statement instanceof ExpressionStatement)) {
		return null;
	}
	ExpressionStatement expressionStatement = (ExpressionStatement) statement;
	Expression expression = expressionStatement.getExpression();
	if (expression.getNodeType() == ASTNode.ASSIGNMENT) {
		return null;
	}
	ITypeBinding typeBinding = expression.resolveTypeBinding();
	typeBinding = Bindings.normalizeTypeBinding(typeBinding);
	if (typeBinding == null) {
		return null;
	}
	if (containsMatchingProblem(locations, IProblem.UnusedObjectAllocation)) {
		return null;
	}
	final ICompilationUnit cu = context.getCompilationUnit();
	int relevance;
	if (context.getSelectionLength() == 0) {
		relevance = IProposalRelevance.EXTRACT_LOCAL_ZERO_SELECTION;
	} else if (problemsAtLocation) {
		relevance = IProposalRelevance.EXTRACT_LOCAL_ERROR;
	} else {
		relevance = IProposalRelevance.EXTRACT_LOCAL;
	}
	if (returnAsCommand) {
		return new AssignToVariableAssistCommandProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_VARIABLE, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, relevance, APPLY_REFACTORING_COMMAND_ID,
				Arrays.asList(ASSIGN_VARIABLE_COMMAND, params));
	} else {
		return new AssignToVariableAssistProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_VARIABLE, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, relevance);
	}
}
 
Example 16
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static ITypeBinding guessBindingForReference(ASTNode node) {
	return Bindings.normalizeTypeBinding(getPossibleReferenceBinding(node));
}
 
Example 17
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static ToStaticAccessOperation[] createToStaticAccessOperations(CompilationUnit astRoot, HashMap<ASTNode, Block> createdBlocks, IProblemLocation problem, boolean conservative) {
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (selectedNode == null) {
		return null;
	}

	Expression qualifier= null;
	IBinding accessBinding= null;

	if (selectedNode instanceof SimpleName) {
		selectedNode= selectedNode.getParent();
	}
	if (selectedNode instanceof QualifiedName) {
		QualifiedName name= (QualifiedName) selectedNode;
		qualifier= name.getQualifier();
		accessBinding= name.resolveBinding();
	} else if (selectedNode instanceof MethodInvocation) {
		MethodInvocation methodInvocation= (MethodInvocation) selectedNode;
		qualifier= methodInvocation.getExpression();
		accessBinding= methodInvocation.getName().resolveBinding();
	} else if (selectedNode instanceof FieldAccess) {
		FieldAccess fieldAccess= (FieldAccess) selectedNode;
		qualifier= fieldAccess.getExpression();
		accessBinding= fieldAccess.getName().resolveBinding();
	}

	if (accessBinding != null && qualifier != null) {
		if (conservative && ASTResolving.findParentStatement(qualifier) == null)
			return null;
		
		ToStaticAccessOperation declaring= null;
		ITypeBinding declaringTypeBinding= getDeclaringTypeBinding(accessBinding);
		if (declaringTypeBinding != null) {
			declaringTypeBinding= declaringTypeBinding.getTypeDeclaration(); // use generic to avoid any type arguments

			declaring= new ToStaticAccessOperation(declaringTypeBinding, qualifier, createdBlocks);
		}
		ToStaticAccessOperation instance= null;
		ITypeBinding instanceTypeBinding= Bindings.normalizeTypeBinding(qualifier.resolveTypeBinding());
		if (instanceTypeBinding != null) {
			instanceTypeBinding= instanceTypeBinding.getTypeDeclaration();  // use generic to avoid any type arguments
			if (instanceTypeBinding.getTypeDeclaration() != declaringTypeBinding) {
				instance= new ToStaticAccessOperation(instanceTypeBinding, qualifier, createdBlocks);
			}
		}
		if (declaring != null && instance != null) {
			return new ToStaticAccessOperation[] {declaring, instance};
		} else {
			return new ToStaticAccessOperation[] {declaring};
		}
	}
	return null;
}
 
Example 18
Source File: ReturnTypeSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static void addMissingReturnTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();

	CompilationUnit astRoot= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (selectedNode == null) {
		return;
	}
	BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
	if (decl instanceof MethodDeclaration) {
		MethodDeclaration methodDeclaration= (MethodDeclaration) decl;

		ReturnStatementCollector eval= new ReturnStatementCollector();
		decl.accept(eval);

		AST ast= astRoot.getAST();

		ITypeBinding typeBinding= eval.getTypeBinding(decl.getAST());
		typeBinding= Bindings.normalizeTypeBinding(typeBinding);
		if (typeBinding == null) {
			typeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$
		}
		if (typeBinding.isWildcardType()) {
			typeBinding= ASTResolving.normalizeWildcardType(typeBinding, true, ast);
		}

		ASTRewrite rewrite= ASTRewrite.create(ast);

		String label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_missingreturntype_description, BindingLabelProvider.getBindingLabel(typeBinding, BindingLabelProvider.DEFAULT_TEXTFLAGS));
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.MISSING_RETURN_TYPE, image);

		ImportRewrite imports= proposal.createImportRewrite(astRoot);
		ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
		Type type= imports.addImport(typeBinding, ast, importRewriteContext);

		rewrite.set(methodDeclaration, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null);
		rewrite.set(methodDeclaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.FALSE, null);

		Javadoc javadoc= methodDeclaration.getJavadoc();
		if (javadoc != null && typeBinding != null) {
			TagElement newTag= ast.newTagElement();
			newTag.setTagName(TagElement.TAG_RETURN);
			TextElement commentStart= ast.newTextElement();
			newTag.fragments().add(commentStart);

			JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
			proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$
		}

		String key= "return_type"; //$NON-NLS-1$
		proposal.addLinkedPosition(rewrite.track(type), true, key);
		if (typeBinding != null) {
			ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, typeBinding);
			for (int i= 0; i < bindings.length; i++) {
				proposal.addLinkedPositionProposal(key, bindings[i]);
			}
		}

		proposals.add(proposal);

		// change to constructor
		ASTNode parentType= ASTResolving.findParentType(decl);
		if (parentType instanceof AbstractTypeDeclaration) {
			boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
			if (!isInterface) {
				String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
				ASTNode nameNode= methodDeclaration.getName();
				label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName));
				proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, IProposalRelevance.CHANGE_TO_CONSTRUCTOR));
			}
		}
	}
}
 
Example 19
Source File: ReturnTypeSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static void addMissingReturnTypeProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();

	CompilationUnit astRoot= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (selectedNode == null) {
		return;
	}
	BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
	if (decl instanceof MethodDeclaration) {
		MethodDeclaration methodDeclaration= (MethodDeclaration) decl;

		ReturnStatementCollector eval= new ReturnStatementCollector();
		decl.accept(eval);

		AST ast= astRoot.getAST();

		ITypeBinding typeBinding= eval.getTypeBinding(decl.getAST());
		typeBinding= Bindings.normalizeTypeBinding(typeBinding);
		if (typeBinding == null) {
			typeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$
		}
		if (typeBinding.isWildcardType()) {
			typeBinding= ASTResolving.normalizeWildcardType(typeBinding, true, ast);
		}

		ASTRewrite rewrite= ASTRewrite.create(ast);

		String label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_missingreturntype_description, BindingLabelProviderCore.getBindingLabel(typeBinding, BindingLabelProviderCore.DEFAULT_TEXTFLAGS));
		LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, CodeActionKind.QuickFix, cu, rewrite, IProposalRelevance.MISSING_RETURN_TYPE);

		ImportRewrite imports= proposal.createImportRewrite(astRoot);
		ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
		Type type= imports.addImport(typeBinding, ast, importRewriteContext, TypeLocation.RETURN_TYPE);

		rewrite.set(methodDeclaration, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null);
		rewrite.set(methodDeclaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.FALSE, null);

		Javadoc javadoc= methodDeclaration.getJavadoc();
		if (javadoc != null && typeBinding != null) {
			TagElement newTag= ast.newTagElement();
			newTag.setTagName(TagElement.TAG_RETURN);
			TextElement commentStart= ast.newTextElement();
			newTag.fragments().add(commentStart);

			JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
			proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$
		}

		String key= "return_type"; //$NON-NLS-1$
		proposal.addLinkedPosition(rewrite.track(type), true, key);
		if (typeBinding != null) {
			ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, typeBinding);
			for (int i= 0; i < bindings.length; i++) {
				proposal.addLinkedPositionProposal(key, bindings[i]);
			}
		}

		proposals.add(proposal);

		// change to constructor
		ASTNode parentType= ASTResolving.findParentType(decl);
		if (parentType instanceof AbstractTypeDeclaration) {
			boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
			if (!isInterface) {
				String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
				ASTNode nameNode= methodDeclaration.getName();
				label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName));
				proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, IProposalRelevance.CHANGE_TO_CONSTRUCTOR));
			}
		}
	}
}