Java Code Examples for org.eclipse.jdt.ui.text.java.IInvocationContext#getCoveringNode()

The following examples show how to use org.eclipse.jdt.ui.text.java.IInvocationContext#getCoveringNode() . 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: CorrectionCommandHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ICompletionProposal getLocalRenameProposal(IInvocationContext context) {
	ASTNode node= context.getCoveringNode();
	if (node instanceof SimpleName) {
		return new LinkedNamesAssistProposal(context, (SimpleName) node);
	}
	return null;
}
 
Example 2
Source File: SuppressWarningsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds a proposal to correct the name of the SuppressWarning annotation
 * @param context the context
 * @param problem the problem
 * @param proposals the resulting proposals
 */
public static void addUnknownSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

	ASTNode coveringNode= context.getCoveringNode();
	if (!(coveringNode instanceof StringLiteral))
		return;

	AST ast= coveringNode.getAST();
	StringLiteral literal= (StringLiteral) coveringNode;

	String literalValue= literal.getLiteralValue();
	String[] allWarningTokens= CorrectionEngine.getAllWarningTokens();
	for (int i= 0; i < allWarningTokens.length; i++) {
		String curr= allWarningTokens[i];
		if (NameMatcher.isSimilarName(literalValue, curr)) {
			StringLiteral newLiteral= ast.newStringLiteral();
			newLiteral.setLiteralValue(curr);
			ASTRewrite rewrite= ASTRewrite.create(ast);
			rewrite.replace(literal, newLiteral, null);
			String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label, new String[] { curr });
			Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
			ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.FIX_SUPPRESS_TOKEN, image);
			proposals.add(proposal);
		}
	}
	addRemoveUnusedSuppressWarningProposals(context, problem, proposals);
}
 
Example 3
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean hasAssists(IInvocationContext context) throws CoreException {
	ASTNode coveringNode= context.getCoveringNode();
	if (coveringNode != null) {
		ArrayList<ASTNode> coveredNodes= getFullyCoveredNodes(context, coveringNode);
		return getConvertToIfReturnProposals(context, coveringNode, null)
				|| getInverseIfProposals(context, coveringNode, null)
				|| getIfReturnIntoIfElseAtEndOfVoidMethodProposals(context, coveringNode, null)
				|| getInverseIfContinueIntoIfThenInLoopsProposals(context, coveringNode, null)
				|| getInverseIfIntoContinueInLoopsProposals(context, coveringNode, null)
				|| getInverseConditionProposals(context, coveringNode, coveredNodes, null)
				|| getRemoveExtraParenthesesProposals(context, coveringNode, coveredNodes, null)
				|| getAddParanoidalParenthesesProposals(context, coveredNodes, null)
				|| getAddParenthesesForExpressionProposals(context, coveringNode, null)
				|| getJoinAndIfStatementsProposals(context, coveringNode, null)
				|| getSplitAndConditionProposals(context, coveringNode, null)
				|| getJoinOrIfStatementsProposals(context, coveringNode, coveredNodes, null)
				|| getSplitOrConditionProposals(context, coveringNode, null)
				|| getInverseConditionalExpressionProposals(context, coveringNode, null)
				|| getExchangeInnerAndOuterIfConditionsProposals(context, coveringNode, null)
				|| getExchangeOperandsProposals(context, coveringNode, null)
				|| getCastAndAssignIfStatementProposals(context, coveringNode, null)
				|| getCombineStringProposals(context, coveringNode, null)
				|| getPickOutStringProposals(context, coveringNode, null)
				|| getReplaceIfElseWithConditionalProposals(context, coveringNode, null)
				|| getReplaceConditionalWithIfElseProposals(context, coveringNode, null)
				|| getInverseLocalVariableProposals(context, coveringNode, null)
				|| getPushNegationDownProposals(context, coveringNode, null)
				|| getPullNegationUpProposals(context, coveredNodes, null)
				|| getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, null)
				|| getConvertSwitchToIfProposals(context, coveringNode, null)
				|| getConvertIfElseToSwitchProposals(context, coveringNode, null)
				|| GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, null, null);
	}
	return false;
}
 
Example 4
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean hasAssists(IInvocationContext context) throws CoreException {
	ASTNode coveringNode= context.getCoveringNode();
	if (coveringNode != null) {
		ArrayList<ASTNode> coveredNodes= AdvancedQuickAssistProcessor.getFullyCoveredNodes(context, coveringNode);
		return getCatchClauseToThrowsProposals(context, coveringNode, null)
			|| getPickoutTypeFromMulticatchProposals(context, coveringNode, coveredNodes, null)
			|| getConvertToMultiCatchProposals(context, coveringNode, null)
			|| getUnrollMultiCatchProposals(context, coveringNode, null)
			|| getRenameLocalProposals(context, coveringNode, null, null)
			|| getRenameRefactoringProposal(context, coveringNode, null, null)
			|| getAssignToVariableProposals(context, coveringNode, null, null)
			|| getUnWrapProposals(context, coveringNode, null)
			|| getAssignParamToFieldProposals(context, coveringNode, null)
			|| getJoinVariableProposals(context, coveringNode, null)
			|| getAddFinallyProposals(context, coveringNode, null)
			|| getAddElseProposals(context, coveringNode, null)
			|| getSplitVariableProposals(context, coveringNode, null)
			|| getAddBlockProposals(context, coveringNode, null)
			|| getArrayInitializerToArrayCreation(context, coveringNode, null)
			|| getCreateInSuperClassProposals(context, coveringNode, null)
			|| getInvertEqualsProposal(context, coveringNode, null)
			|| getConvertForLoopProposal(context, coveringNode, null)
			|| getConvertIterableLoopProposal(context, coveringNode, null)
			|| getConvertEnhancedForLoopProposal(context, coveringNode, null)
			|| getGenerateForLoopProposals(context, coveringNode, null, null)
			|| getExtractVariableProposal(context, false, null)
			|| getExtractMethodProposal(context, coveringNode, false, null)
			|| getInlineLocalProposal(context, coveringNode, null)
			|| getConvertLocalToFieldProposal(context, coveringNode, null)
			|| getConvertAnonymousToNestedProposal(context, coveringNode, null)
			|| getConvertAnonymousClassCreationsToLambdaProposals(context, coveringNode, null)
			|| getConvertLambdaToAnonymousClassCreationsProposals(context, coveringNode, null)
			|| getChangeLambdaBodyToBlockProposal(context, coveringNode, null)
			|| getChangeLambdaBodyToExpressionProposal(context, coveringNode, null)
			|| getRemoveBlockProposals(context, coveringNode, null)
			|| getMakeVariableDeclarationFinalProposals(context, null)
			|| getMissingCaseStatementProposals(context, coveringNode, null)
			|| getConvertStringConcatenationProposals(context, null)
			|| getInferDiamondArgumentsProposal(context, coveringNode, null, null);
	}
	return false;
}
 
Example 5
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
	ASTNode coveringNode= context.getCoveringNode();
	if (coveringNode != null) {
		ArrayList<ASTNode> coveredNodes= AdvancedQuickAssistProcessor.getFullyCoveredNodes(context, coveringNode);
		ArrayList<ICommandAccess> resultingCollections= new ArrayList<ICommandAccess>();
		boolean noErrorsAtLocation= noErrorsAtLocation(locations);

		// quick assists that show up also if there is an error/warning
		getRenameLocalProposals(context, coveringNode, locations, resultingCollections);
		getRenameRefactoringProposal(context, coveringNode, locations, resultingCollections);
		getAssignToVariableProposals(context, coveringNode, locations, resultingCollections);
		getAssignParamToFieldProposals(context, coveringNode, resultingCollections);
		getInferDiamondArgumentsProposal(context, coveringNode, locations, resultingCollections);
		getGenerateForLoopProposals(context, coveringNode, locations, resultingCollections);

		if (noErrorsAtLocation) {
			boolean problemsAtLocation= locations.length != 0;
			getCatchClauseToThrowsProposals(context, coveringNode, resultingCollections);
			getPickoutTypeFromMulticatchProposals(context, coveringNode, coveredNodes, resultingCollections);
			getConvertToMultiCatchProposals(context, coveringNode, resultingCollections);
			getUnrollMultiCatchProposals(context, coveringNode, resultingCollections);
			getUnWrapProposals(context, coveringNode, resultingCollections);
			getJoinVariableProposals(context, coveringNode, resultingCollections);
			getSplitVariableProposals(context, coveringNode, resultingCollections);
			getAddFinallyProposals(context, coveringNode, resultingCollections);
			getAddElseProposals(context, coveringNode, resultingCollections);
			getAddBlockProposals(context, coveringNode, resultingCollections);
			getInvertEqualsProposal(context, coveringNode, resultingCollections);
			getArrayInitializerToArrayCreation(context, coveringNode, resultingCollections);
			getCreateInSuperClassProposals(context, coveringNode, resultingCollections);
			getExtractVariableProposal(context, problemsAtLocation, resultingCollections);
			getExtractMethodProposal(context, coveringNode, problemsAtLocation, resultingCollections);
			getInlineLocalProposal(context, coveringNode, resultingCollections);
			getConvertLocalToFieldProposal(context, coveringNode, resultingCollections);
			getConvertAnonymousToNestedProposal(context, coveringNode, resultingCollections);
			getConvertAnonymousClassCreationsToLambdaProposals(context, coveringNode, resultingCollections);
			getConvertLambdaToAnonymousClassCreationsProposals(context, coveringNode, resultingCollections);
			getChangeLambdaBodyToBlockProposal(context, coveringNode, resultingCollections);
			getChangeLambdaBodyToExpressionProposal(context, coveringNode, resultingCollections);
			if (!getConvertForLoopProposal(context, coveringNode, resultingCollections))
				getConvertIterableLoopProposal(context, coveringNode, resultingCollections);
			getConvertEnhancedForLoopProposal(context, coveringNode, resultingCollections);
			getRemoveBlockProposals(context, coveringNode, resultingCollections);
			getMakeVariableDeclarationFinalProposals(context, resultingCollections);
			getConvertStringConcatenationProposals(context, resultingCollections);
			getMissingCaseStatementProposals(context, coveringNode, resultingCollections);
		}
		return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
	}
	return null;
}
 
Example 6
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean getConvertStringConcatenationProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) {
	ASTNode node= context.getCoveringNode();
	BodyDeclaration parentDecl= ASTResolving.findParentBodyDeclaration(node);
	if (!(parentDecl instanceof MethodDeclaration || parentDecl instanceof Initializer))
		return false;

	AST ast= node.getAST();
	ITypeBinding stringBinding= ast.resolveWellKnownType("java.lang.String"); //$NON-NLS-1$

	if (node instanceof Expression && !(node instanceof InfixExpression)) {
		node= node.getParent();
	}
	if (node instanceof VariableDeclarationFragment) {
		node= ((VariableDeclarationFragment) node).getInitializer();
	} else if (node instanceof Assignment) {
		node= ((Assignment) node).getRightHandSide();
	}

	InfixExpression oldInfixExpression= null;
	while (node instanceof InfixExpression) {
		InfixExpression curr= (InfixExpression) node;
		if (curr.resolveTypeBinding() == stringBinding && curr.getOperator() == InfixExpression.Operator.PLUS) {
			oldInfixExpression= curr; // is a infix expression we can use
		} else {
			break;
		}
		node= node.getParent();
	}
	if (oldInfixExpression == null)
		return false;

	if (resultingCollections == null) {
		return true;
	}

	LinkedCorrectionProposal stringBufferProposal= getConvertToStringBufferProposal(context, ast, oldInfixExpression);
	resultingCollections.add(stringBufferProposal);

	ASTRewriteCorrectionProposal messageFormatProposal= getConvertToMessageFormatProposal(context, ast, oldInfixExpression);
	if (messageFormatProposal != null)
		resultingCollections.add(messageFormatProposal);

	return true;
}
 
Example 7
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
	ASTNode coveringNode= context.getCoveringNode();
	if (coveringNode != null) {
		ArrayList<ASTNode> coveredNodes= getFullyCoveredNodes(context, coveringNode);
		ArrayList<ICommandAccess> resultingCollections= new ArrayList<ICommandAccess>();

		//quick assists that show up also if there is an error/warning
		getReplaceConditionalWithIfElseProposals(context, coveringNode, resultingCollections);

		if (QuickAssistProcessor.noErrorsAtLocation(locations)) {
			getConvertToIfReturnProposals(context, coveringNode, resultingCollections);
			getInverseIfProposals(context, coveringNode, resultingCollections);
			getIfReturnIntoIfElseAtEndOfVoidMethodProposals(context, coveringNode, resultingCollections);
			getInverseIfContinueIntoIfThenInLoopsProposals(context, coveringNode, resultingCollections);
			getInverseIfIntoContinueInLoopsProposals(context, coveringNode, resultingCollections);
			getInverseConditionProposals(context, coveringNode, coveredNodes, resultingCollections);
			getRemoveExtraParenthesesProposals(context, coveringNode, coveredNodes, resultingCollections);
			getAddParanoidalParenthesesProposals(context, coveredNodes, resultingCollections);
			getAddParenthesesForExpressionProposals(context, coveringNode, resultingCollections);
			getJoinAndIfStatementsProposals(context, coveringNode, resultingCollections);
			getSplitAndConditionProposals(context, coveringNode, resultingCollections);
			getJoinOrIfStatementsProposals(context, coveringNode, coveredNodes, resultingCollections);
			getSplitOrConditionProposals(context, coveringNode, resultingCollections);
			getInverseConditionalExpressionProposals(context, coveringNode, resultingCollections);
			getExchangeInnerAndOuterIfConditionsProposals(context, coveringNode, resultingCollections);
			getExchangeOperandsProposals(context, coveringNode, resultingCollections);
			getCastAndAssignIfStatementProposals(context, coveringNode, resultingCollections);
			getCombineStringProposals(context, coveringNode, resultingCollections);
			getPickOutStringProposals(context, coveringNode, resultingCollections);
			getReplaceIfElseWithConditionalProposals(context, coveringNode, resultingCollections);
			getInverseLocalVariableProposals(context, coveringNode, resultingCollections);
			getPushNegationDownProposals(context, coveringNode, resultingCollections);
			getPullNegationUpProposals(context, coveredNodes, resultingCollections);
			getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, resultingCollections);
			getConvertSwitchToIfProposals(context, coveringNode, resultingCollections);
			getConvertIfElseToSwitchProposals(context, coveringNode, resultingCollections);
			GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, locations, resultingCollections);
		}

		return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
	}
	return null;
}