Java Code Examples for org.eclipse.jdt.core.compiler.IProblem#UseEnumAsAnIdentifier

The following examples show how to use org.eclipse.jdt.core.compiler.IProblem#UseEnumAsAnIdentifier . 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: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static void addInvalidVariableNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	// hiding, redefined or future keyword

	CompilationUnit root= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(root);
	if (selectedNode instanceof MethodDeclaration) {
		selectedNode= ((MethodDeclaration) selectedNode).getName();
	}
	if (!(selectedNode instanceof SimpleName)) {
		return;
	}
	SimpleName nameNode= (SimpleName) selectedNode;
	String valueSuggestion= null;

	String name;
	switch (problem.getProblemId()) {
		case IProblem.LocalVariableHidingLocalVariable:
		case IProblem.LocalVariableHidingField:
			name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_hiding_local_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
			break;
		case IProblem.FieldHidingLocalVariable:
		case IProblem.FieldHidingField:
		case IProblem.DuplicateField:
			name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_hiding_field_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
			break;
		case IProblem.ArgumentHidingLocalVariable:
		case IProblem.ArgumentHidingField:
			name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_hiding_argument_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
			break;
		case IProblem.DuplicateMethod:
			name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_renaming_duplicate_method, BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
			break;

		default:
			name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_rename_var_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
	}

	if (problem.getProblemId() == IProblem.UseEnumAsAnIdentifier) {
		valueSuggestion= "enumeration"; //$NON-NLS-1$
	} else {
		valueSuggestion= nameNode.getIdentifier() + '1';
	}

	LinkedNamesAssistProposal proposal= new LinkedNamesAssistProposal(name, context, nameNode, valueSuggestion);
	proposals.add(proposal);
}