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

The following examples show how to use org.eclipse.jdt.core.compiler.IProblem#UnusedTypeParameter . 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: JavadocTagsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static void getUnusedAndUndocumentedParameterOrExceptionProposals(IInvocationContext context,
		IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();
	IJavaProject project= cu.getJavaProject();

	if (!JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true))) {
		return;
	}

	int problemId= problem.getProblemId();
	boolean isUnusedTypeParam= problemId == IProblem.UnusedTypeParameter;
	boolean isUnusedParam= problemId == IProblem.ArgumentIsNeverUsed || isUnusedTypeParam;
	String key= isUnusedParam ? JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE : JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE;

	if (!JavaCore.ENABLED.equals(project.getOption(key, true))) {
		return;
	}

	ASTNode node= problem.getCoveringNode(context.getASTRoot());
	if (node == null) {
		return;
	}

	BodyDeclaration bodyDecl= ASTResolving.findParentBodyDeclaration(node);
	if (bodyDecl == null || ASTResolving.getParentMethodOrTypeBinding(bodyDecl) == null) {
		return;
	}

	String label;
	if (isUnusedTypeParam) {
		label= CorrectionMessages.JavadocTagsSubProcessor_document_type_parameter_description;
	} else if (isUnusedParam) {
		label= CorrectionMessages.JavadocTagsSubProcessor_document_parameter_description;
	} else {
		node= ASTNodes.getNormalizedNode(node);
		label= CorrectionMessages.JavadocTagsSubProcessor_document_exception_description;
	}
	ASTRewriteCorrectionProposal proposal= new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), bodyDecl, node, IProposalRelevance.DOCUMENT_UNUSED_ITEM);
	proposals.add(proposal);
}
 
Example 2
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static UnusedCodeFix createUnusedTypeParameterFix(CompilationUnit compilationUnit, IProblemLocation problemLoc) {
	if (problemLoc.getProblemId() == IProblem.UnusedTypeParameter) {
		SimpleName name= getUnusedName(compilationUnit, problemLoc);
		if (name != null) {
			IBinding binding= name.resolveBinding();
			if (binding != null) {
				String label= FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description;
				RemoveUnusedTypeParameterOperation operation= new RemoveUnusedTypeParameterOperation(name);
				return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, false));
			}
		}
	}
	return null;
}
 
Example 3
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void getUnusedAndUndocumentedParameterOrExceptionProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();
	IJavaProject project= cu.getJavaProject();

	if (!JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true))) {
		return;
	}

	int problemId= problem.getProblemId();
	boolean isUnusedTypeParam= problemId == IProblem.UnusedTypeParameter;
	boolean isUnusedParam= problemId == IProblem.ArgumentIsNeverUsed || isUnusedTypeParam;
	String key= isUnusedParam ? JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE : JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE;

	if (!JavaCore.ENABLED.equals(project.getOption(key, true))) {
		return;
	}

 	ASTNode node= problem.getCoveringNode(context.getASTRoot());
 	if (node == null) {
 		return;
 	}

	BodyDeclaration bodyDecl= ASTResolving.findParentBodyDeclaration(node);
	if (bodyDecl == null || ASTResolving.getParentMethodOrTypeBinding(bodyDecl) == null) {
		return;
	}

	String label;
	if (isUnusedTypeParam) {
		label= CorrectionMessages.JavadocTagsSubProcessor_document_type_parameter_description;
	} else if (isUnusedParam) {
		label= CorrectionMessages.JavadocTagsSubProcessor_document_parameter_description;
	} else {
		node= ASTNodes.getNormalizedNode(node);
		label= CorrectionMessages.JavadocTagsSubProcessor_document_exception_description;
	}
	ASTRewriteCorrectionProposal proposal= new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), bodyDecl, node, IProposalRelevance.DOCUMENT_UNUSED_ITEM);
	proposals.add(proposal);
}
 
Example 4
Source File: BaseDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static List<DiagnosticTag> getDiagnosticTag(int id) {
	switch (id) {
		case IProblem.UsingDeprecatedType:
		case IProblem.UsingDeprecatedField:
		case IProblem.UsingDeprecatedMethod:
		case IProblem.UsingDeprecatedConstructor:
		case IProblem.OverridingDeprecatedMethod:
		case IProblem.JavadocUsingDeprecatedField:
		case IProblem.JavadocUsingDeprecatedConstructor:
		case IProblem.JavadocUsingDeprecatedMethod:
		case IProblem.JavadocUsingDeprecatedType:
		case IProblem.UsingTerminallyDeprecatedType:
		case IProblem.UsingTerminallyDeprecatedMethod:
		case IProblem.UsingTerminallyDeprecatedConstructor:
		case IProblem.UsingTerminallyDeprecatedField:
		case IProblem.OverridingTerminallyDeprecatedMethod:
		case IProblem.UsingDeprecatedSinceVersionType:
		case IProblem.UsingDeprecatedSinceVersionMethod:
		case IProblem.UsingDeprecatedSinceVersionConstructor:
		case IProblem.UsingDeprecatedSinceVersionField:
		case IProblem.OverridingDeprecatedSinceVersionMethod:
		case IProblem.UsingTerminallyDeprecatedSinceVersionType:
		case IProblem.UsingTerminallyDeprecatedSinceVersionMethod:
		case IProblem.UsingTerminallyDeprecatedSinceVersionConstructor:
		case IProblem.UsingTerminallyDeprecatedSinceVersionField:
		case IProblem.OverridingTerminallyDeprecatedSinceVersionMethod:
		case IProblem.UsingDeprecatedPackage:
		case IProblem.UsingDeprecatedSinceVersionPackage:
		case IProblem.UsingTerminallyDeprecatedPackage:
		case IProblem.UsingTerminallyDeprecatedSinceVersionPackage:
		case IProblem.UsingDeprecatedModule:
		case IProblem.UsingDeprecatedSinceVersionModule:
		case IProblem.UsingTerminallyDeprecatedModule:
		case IProblem.UsingTerminallyDeprecatedSinceVersionModule:
			return Arrays.asList(DiagnosticTag.Deprecated);
		case IProblem.UnnecessaryCast:
		case IProblem.UnnecessaryInstanceof:
		case IProblem.UnnecessaryElse:
		case IProblem.UnnecessaryNLSTag:
		// Report *unused* cases as unnecessary
		case IProblem.UnusedPrivateType:
		case IProblem.UnusedPrivateField:
		case IProblem.UnusedPrivateMethod:
		case IProblem.UnusedPrivateConstructor:
		case IProblem.UnusedObjectAllocation:
		case IProblem.UnusedMethodDeclaredThrownException:
		case IProblem.UnusedConstructorDeclaredThrownException:
		case IProblem.UnusedLabel:
		case IProblem.UnusedImport:
		case IProblem.UnusedTypeArgumentsForMethodInvocation:
		case IProblem.UnusedWarningToken:
		case IProblem.UnusedTypeArgumentsForConstructorInvocation:
		case IProblem.UnusedTypeParameter:
		// Other unused cases
		case IProblem.LocalVariableIsNeverUsed:
		case IProblem.ArgumentIsNeverUsed:
		case IProblem.ExceptionParameterIsNeverUsed:
			return Arrays.asList(DiagnosticTag.Unnecessary);
	}

	return null;
}