Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 209467 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java (+56 lines)
Lines 2478-2481 Link Here
2478
		assertExpectedExistInProposals(proposals, expected);
2478
		assertExpectedExistInProposals(proposals, expected);
2479
	}
2479
	}
2480
2480
2481
	public void testQualifyType1() throws Exception {
2482
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2483
		StringBuffer buf= new StringBuffer();
2484
		buf.append("package test1;\n");
2485
		buf.append("public class E {\n");
2486
		buf.append("    public void foo(String s) {\n");
2487
		buf.append("    }\n");
2488
		buf.append("}\n");
2489
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
2490
2491
		int offset= buf.toString().indexOf("ring");
2492
		AssistContext context= getCorrectionContext(cu, offset, 0);
2493
		List proposals= collectAssists(context, false);
2494
2495
		assertCorrectLabels(proposals);
2496
2497
		buf= new StringBuffer();
2498
		buf.append("package test1;\n");
2499
		buf.append("public class E {\n");
2500
		buf.append("    public void foo(java.lang.String s) {\n");
2501
		buf.append("    }\n");
2502
		buf.append("}\n");
2503
		String expected1= buf.toString();
2504
2505
		assertExpectedExistInProposals(proposals, new String[] {expected1});
2506
	}
2507
2508
	public void testQualifyType2() throws Exception {
2509
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2510
		StringBuffer buf= new StringBuffer();
2511
		buf.append("package test1;\n");
2512
		buf.append("public class E {\n");
2513
		buf.append("    public void foo(String s) {\n");
2514
		buf.append("      System.out.print(s);\n");
2515
		buf.append("    }\n");
2516
		buf.append("}\n");
2517
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
2518
2519
		int offset= buf.toString().indexOf("ystem");
2520
		AssistContext context= getCorrectionContext(cu, offset, 0);
2521
		List proposals= collectAssists(context, false);
2522
2523
		assertCorrectLabels(proposals);
2524
2525
		buf= new StringBuffer();
2526
		buf.append("package test1;\n");
2527
		buf.append("public class E {\n");
2528
		buf.append("    public void foo(String s) {\n");
2529
		buf.append("      java.lang.System.out.print(s);\n");
2530
		buf.append("    }\n");
2531
		buf.append("}\n");
2532
		String expected1= buf.toString();
2533
2534
		assertExpectedExistInProposals(proposals, new String[] {expected1});
2535
	}
2536
	
2481
}
2537
}
(-)ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java (-1 / +41 lines)
Lines 123-129 Link Here
123
					|| getReplaceIfElseWithConditionalProposals(context, coveringNode, null) || getReplaceConditionalWithIfElseProposals(context, coveringNode, null)
123
					|| getReplaceIfElseWithConditionalProposals(context, coveringNode, null) || getReplaceConditionalWithIfElseProposals(context, coveringNode, null)
124
					|| getInverseLocalVariableProposals(context, coveringNode, null) || getPushNegationDownProposals(context, coveringNode, null)
124
					|| getInverseLocalVariableProposals(context, coveringNode, null) || getPushNegationDownProposals(context, coveringNode, null)
125
					|| getPullNegationUpProposals(context, coveredNodes, null) || getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, null)
125
					|| getPullNegationUpProposals(context, coveredNodes, null) || getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, null)
126
					|| getConvertSwitchToIfProposals(context, coveringNode, null) || GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, null, null);
126
					|| getConvertSwitchToIfProposals(context, coveringNode, null) || GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, null, null)
127
					|| getQualifyTypenameProposals(context, coveringNode, null);
127
		}
128
		}
128
		return false;
129
		return false;
129
	}
130
	}
Lines 161-166 Link Here
161
				getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, resultingCollections);
162
				getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, resultingCollections);
162
				getConvertSwitchToIfProposals(context, coveringNode, resultingCollections);
163
				getConvertSwitchToIfProposals(context, coveringNode, resultingCollections);
163
				GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, locations, resultingCollections);
164
				GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, locations, resultingCollections);
165
				getQualifyTypenameProposals(context, coveringNode, resultingCollections);
164
			}
166
			}
165
167
166
			return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
168
			return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
Lines 785-790 Link Here
785
		return parenthesizedExpression;
787
		return parenthesizedExpression;
786
	}
788
	}
787
789
790
	private static boolean getQualifyTypenameProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) {
791
		if (!(node instanceof SimpleName))
792
			return false;
793
		SimpleName simpleName = (SimpleName) node;
794
		IBinding binding= simpleName.resolveBinding();
795
		if (!(binding instanceof ITypeBinding))
796
			return false;
797
		ITypeBinding typeBinding= (ITypeBinding) binding;
798
		if (typeBinding.isPrimitive() || typeBinding.isNullType()
799
				|| typeBinding.isAnonymous())
800
			return false;
801
		if (typeBinding.getPackage() == null)
802
			return false;
803
		String[] split= typeBinding.getPackage().getName().split("[.]"); //$NON-NLS-1$
804
		if (split.length < 1)
805
			return false;
806
		if (resultingCollections == null) {
807
			return true;
808
		}
809
		AST ast = simpleName.getAST();
810
		ASTRewrite rewrite= ASTRewrite.create(ast);
811
		SimpleName nsn= ast.newSimpleName(simpleName.getFullyQualifiedName());
812
		QualifiedName qn = null;
813
		SimpleName base= ast.newSimpleName(split[0]);
814
		for (int i = 1; i < split.length; i++) {
815
			SimpleName tmp= ast.newSimpleName(split[i]);
816
			qn= ast.newQualifiedName(base, tmp);
817
		}
818
		qn= ast.newQualifiedName(qn, nsn);
819
		rewrite.replace(simpleName, qn, null);
820
		// add correction proposal
821
		String label= CorrectionMessages.AdvancedQuickAssistProcessor_qualifyTypename_description;
822
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
823
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image);
824
		resultingCollections.add(proposal);
825
		return true;
826
	}
827
	
788
	private static boolean getSplitAndConditionProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) {
828
	private static boolean getSplitAndConditionProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) {
789
		Operator andOperator= InfixExpression.Operator.CONDITIONAL_AND;
829
		Operator andOperator= InfixExpression.Operator.CONDITIONAL_AND;
790
		// check that user invokes quick assist on infix expression
830
		// check that user invokes quick assist on infix expression
(-)ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java (+1 lines)
Lines 305-310 Link Here
305
	public static String AdvancedQuickAssistProcessor_joinWithOr_description;
305
	public static String AdvancedQuickAssistProcessor_joinWithOr_description;
306
	public static String AdvancedQuickAssistProcessor_splitOrCondition_description;
306
	public static String AdvancedQuickAssistProcessor_splitOrCondition_description;
307
	public static String AdvancedQuickAssistProcessor_exchangeOperands_description;
307
	public static String AdvancedQuickAssistProcessor_exchangeOperands_description;
308
	public static String AdvancedQuickAssistProcessor_qualifyTypename_description;
308
	public static String AddTypeParameterProposal_method_label;
309
	public static String AddTypeParameterProposal_method_label;
309
	public static String AddTypeParameterProposal_type_label;
310
	public static String AddTypeParameterProposal_type_label;
310
311
(-)ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties (+2 lines)
Lines 375-380 Link Here
375
AdvancedQuickAssistProcessor_joinWithOr_description=Join selected 'if' statements with ||
375
AdvancedQuickAssistProcessor_joinWithOr_description=Join selected 'if' statements with ||
376
AdvancedQuickAssistProcessor_splitOrCondition_description=Split || condition
376
AdvancedQuickAssistProcessor_splitOrCondition_description=Split || condition
377
AdvancedQuickAssistProcessor_exchangeOperands_description=Exchange left and right operands for infix expression
377
AdvancedQuickAssistProcessor_exchangeOperands_description=Exchange left and right operands for infix expression
378
AdvancedQuickAssistProcessor_qualifyTypename_description=Qualify type name
379
378
380
379
AddTypeParameterProposal_method_label=Add type parameter ''{0}'' to ''{1}''
381
AddTypeParameterProposal_method_label=Add type parameter ''{0}'' to ''{1}''
380
AddTypeParameterProposal_type_label=Add type parameter ''{0}'' to ''{1}''
382
AddTypeParameterProposal_type_label=Add type parameter ''{0}'' to ''{1}''

Return to bug 209467