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

The following examples show how to use org.eclipse.jdt.core.compiler.IProblem#UnqualifiedFieldAccess . 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: 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 2
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static CompilationUnitRewriteOperationsFix createAddFieldQualifierFix(CompilationUnit compilationUnit, IProblemLocation problem) {
	if (IProblem.UnqualifiedFieldAccess != problem.getProblemId())
		return null;

	AddThisQualifierOperation operation= getUnqualifiedFieldAccessResolveOperation(compilationUnit, problem);
	if (operation == null)
		return null;

	String groupName= operation.getDescription();
	return new CodeStyleFix(groupName, compilationUnit, new CompilationUnitRewriteOperation[] {operation});
}
 
Example 3
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] problems,
		boolean addThisQualifier,
		boolean changeNonStaticAccessToStatic,
		boolean changeIndirectStaticAccessToDirect) {

	if (!addThisQualifier && !changeNonStaticAccessToStatic && !changeIndirectStaticAccessToDirect)
		return null;

	List<CompilationUnitRewriteOperation> operations= new ArrayList<CompilationUnitRewriteOperation>();
	if (addThisQualifier) {
		for (int i= 0; i < problems.length; i++) {
			IProblemLocation problem= problems[i];
			if (problem.getProblemId() == IProblem.UnqualifiedFieldAccess) {
				AddThisQualifierOperation operation= getUnqualifiedFieldAccessResolveOperation(compilationUnit, problem);
				if (operation != null)
					operations.add(operation);
			}
		}
	}

	addToStaticAccessOperations(compilationUnit, problems, changeNonStaticAccessToStatic, changeIndirectStaticAccessToDirect, operations);

	if (operations.isEmpty())
		return null;

	CompilationUnitRewriteOperation[] operationsArray= operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
	return new CodeStyleFix(FixMessages.CodeStyleFix_change_name, compilationUnit, operationsArray);
}
 
Example 4
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 5
Source File: CodeStyleCleanUp.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) {
	if (IProblem.UnqualifiedFieldAccess == problem.getProblemId())
		return isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_ALWAYS);

	if (CodeStyleFix.isIndirectStaticAccess(problem))
		return isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_SUBTYPE_ACCESS);

	if (CodeStyleFix.isNonStaticAccess(problem))
		return isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_INSTANCE_ACCESS);

	return false;
}