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

The following examples show how to use org.eclipse.jdt.core.compiler.IProblem#UnusedPrivateField . 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 6 votes vote down vote up
public static void addUnusedMemberProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	int problemId = problem.getProblemId();
	UnusedCodeFix fix= UnusedCodeFix.createUnusedMemberFix(context.getASTRoot(), problem, false);
	if (fix != null) {
		addProposal(context, proposals, fix);
	}

	if (problemId==IProblem.LocalVariableIsNeverUsed){
		fix= UnusedCodeFix.createUnusedMemberFix(context.getASTRoot(), problem, true);
		addProposal(context, proposals, fix);
	}

	if (problemId == IProblem.ArgumentIsNeverUsed) {
		JavadocTagsSubProcessor.getUnusedAndUndocumentedParameterOrExceptionProposals(context, problem, proposals);
	}

	if (problemId == IProblem.UnusedPrivateField) {
		GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, problem, proposals, IProposalRelevance.GETTER_SETTER_UNUSED_PRIVATE_FIELD);
	}

}
 
Example 2
Source File: GetterSetterCorrectionSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Used by quick assist
 *
 * @param context
 *            the invocation context
 * @param coveringNode
 *            the covering node
 * @param locations
 *            the problems at the corrent location
 * @param resultingCollections
 *            the resulting proposals
 * @return <code>true</code> if the quick assist is applicable at this offset
 */
public static boolean addGetterSetterProposal(IInvocationContext context, ASTNode coveringNode, IProblemLocationCore[] locations, ArrayList<ChangeCorrectionProposal> resultingCollections) {
	if (locations != null) {
		for (int i = 0; i < locations.length; i++) {
			int problemId = locations[i].getProblemId();
			if (problemId == IProblem.UnusedPrivateField) {
				return false;
			}
			if (problemId == IProblem.UnqualifiedFieldAccess) {
				return false;
			}
		}
	}
	return addGetterSetterProposal(context, coveringNode, resultingCollections, IProposalRelevance.GETTER_SETTER_QUICK_ASSIST);
}
 
Example 3
Source File: GetterSetterCorrectionSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Used by quick assist
 * @param context the invocation context
 * @param coveringNode the covering node
 * @param locations the problems at the corrent location
 * @param resultingCollections the resulting proposals
 * @return <code>true</code> if the quick assist is applicable at this offset
 */
public static boolean addGetterSetterProposal(IInvocationContext context, ASTNode coveringNode, IProblemLocation[] locations, ArrayList<ICommandAccess> resultingCollections) {
	if (locations != null) {
		for (int i= 0; i < locations.length; i++) {
			int problemId= locations[i].getProblemId();
			if (problemId == IProblem.UnusedPrivateField)
				return false;
			if (problemId == IProblem.UnqualifiedFieldAccess)
				return false;
		}
	}
	return addGetterSetterProposal(context, coveringNode, resultingCollections, IProposalRelevance.GETTER_SETTER_QUICK_ASSIST);
}
 
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;
}
 
Example 5
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isUnusedMember(IProblemLocation problem) {
	int id= problem.getProblemId();
	return id == IProblem.UnusedPrivateMethod || id == IProblem.UnusedPrivateConstructor || id == IProblem.UnusedPrivateField || id == IProblem.UnusedPrivateType
			|| id == IProblem.LocalVariableIsNeverUsed || id == IProblem.ArgumentIsNeverUsed;
}