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 460521
Collapse All | Expand All

(-)a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest18.java (-1 / +232 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2014 GK Software AG, IBM Corporation and others.
2
 * Copyright (c) 2014, 2015 GK Software AG, IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 382-385 Link Here
382
		buf.append("}\n");
382
		buf.append("}\n");
383
		assertEquals(buf.toString(), doc.get());
383
		assertEquals(buf.toString(), doc.get());
384
	}
384
	}
385
386
	public void testOverride5() throws CoreException {
387
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
388
		IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null);
389
		StringBuffer buf= new StringBuffer();
390
		buf.append("package test1;\n");
391
		buf.append("\n");
392
		buf.append("public interface I1 {\n");
393
		buf.append("    equals\n");
394
		buf.append("}\n");
395
		ICompilationUnit cu= pack1.createCompilationUnit("I1.java", buf.toString(), false, null);
396
397
		String str= "equals";
398
		int offset= buf.toString().indexOf(str) + str.length();
399
400
		CompletionProposalCollector collector= createCollector(cu, offset);
401
		collector.setReplacementLength(0);
402
		codeComplete(cu, offset, collector);
403
404
		IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals();
405
		assertEquals(1, proposals.length);
406
		IEditorPart part= JavaUI.openInEditor(cu);
407
		IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
408
		proposals[0].apply(doc);
409
410
		buf= new StringBuffer();
411
		buf.append("package test1;\n");
412
		buf.append("\n");
413
		buf.append("public interface I1 {\n");
414
		buf.append("    /* (non-Javadoc)\n");
415
		buf.append("     * @see java.lang.Object#equals(java.lang.Object)\n");
416
		buf.append("     */\n");
417
		buf.append("    @Override\n");
418
		buf.append("    public boolean equals(Object arg0);\n");
419
		buf.append("}\n");
420
		assertEquals(buf.toString(), doc.get());
421
	}
422
423
	public void testOverride6() throws CoreException {
424
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
425
		IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null);
426
		StringBuffer buf= new StringBuffer();
427
		buf.append("package test1;\n");
428
		buf.append("\n");
429
		buf.append("public interface I2 {\n");
430
		buf.append("    hashCode\n");
431
		buf.append("}\n");
432
		ICompilationUnit cu= pack1.createCompilationUnit("I2.java", buf.toString(), false, null);
433
434
		String str= "hashCode";
435
		int offset= buf.toString().indexOf(str) + str.length();
436
437
		CompletionProposalCollector collector= createCollector(cu, offset);
438
		collector.setReplacementLength(0);
439
		codeComplete(cu, offset, collector);
440
441
		IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals();
442
		assertEquals(1, proposals.length);
443
		IEditorPart part= JavaUI.openInEditor(cu);
444
		IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
445
		proposals[0].apply(doc);
446
447
		buf= new StringBuffer();
448
		buf.append("package test1;\n");
449
		buf.append("\n");
450
		buf.append("public interface I2 {\n");
451
		buf.append("    /* (non-Javadoc)\n");
452
		buf.append("     * @see java.lang.Object#hashCode()\n");
453
		buf.append("     */\n");
454
		buf.append("    @Override\n");
455
		buf.append("    public int hashCode();\n");
456
		buf.append("}\n");
457
		assertEquals(buf.toString(), doc.get());
458
	}
459
460
	public void testOverride7() throws CoreException {
461
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
462
		IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null);
463
		StringBuffer buf= new StringBuffer();
464
		buf.append("package test1;\n");
465
		buf.append("\n");
466
		buf.append("public interface I3 {\n");
467
		buf.append("    toString\n");
468
		buf.append("}\n");
469
		ICompilationUnit cu= pack1.createCompilationUnit("I3.java", buf.toString(), false, null);
470
471
		String str= "toString";
472
		int offset= buf.toString().indexOf(str) + str.length();
473
474
		CompletionProposalCollector collector= createCollector(cu, offset);
475
		collector.setReplacementLength(0);
476
		codeComplete(cu, offset, collector);
477
478
		IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals();
479
		assertEquals(1, proposals.length);
480
		IEditorPart part= JavaUI.openInEditor(cu);
481
		IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
482
		proposals[0].apply(doc);
483
484
		buf= new StringBuffer();
485
		buf.append("package test1;\n");
486
		buf.append("\n");
487
		buf.append("public interface I3 {\n");
488
		buf.append("    /* (non-Javadoc)\n");
489
		buf.append("     * @see java.lang.Object#toString()\n");
490
		buf.append("     */\n");
491
		buf.append("    @Override\n");
492
		buf.append("    public String toString();\n");
493
		buf.append("}\n");
494
		assertEquals(buf.toString(), doc.get());
495
	}
496
497
	public void testOverride8() throws CoreException {
498
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
499
		IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null);
500
		StringBuffer buf= new StringBuffer();
501
		buf.append("package test1;\n");
502
		buf.append("\n");
503
		buf.append("public interface I4 {\n");
504
		buf.append("    clone\n");
505
		buf.append("}\n");
506
		ICompilationUnit cu= pack1.createCompilationUnit("I4.java", buf.toString(), false, null);
507
508
		String str= "clone";
509
		int offset= buf.toString().indexOf(str) + str.length();
510
511
		CompletionProposalCollector collector= createCollector(cu, offset);
512
		collector.setReplacementLength(0);
513
		codeComplete(cu, offset, collector);
514
515
		IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals();
516
		assertEquals(3, proposals.length);
517
		IEditorPart part= JavaUI.openInEditor(cu);
518
		IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
519
		proposals[2].apply(doc);
520
521
		buf= new StringBuffer();
522
		buf.append("package test1;\n");
523
		buf.append("\n");
524
		buf.append("public interface I4 {\n");
525
		buf.append("    /* (non-Javadoc)\n");
526
		buf.append("     * @see java.lang.Object#clone()\n");
527
		buf.append("     */\n");
528
		buf.append("    public Object clone() throws CloneNotSupportedException;\n");
529
		buf.append("}\n");
530
		assertEquals(buf.toString(), doc.get());
531
	}
532
533
	public void testOverride9() throws CoreException {
534
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
535
		IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null);
536
		StringBuffer buf= new StringBuffer();
537
		buf.append("package test1;\n");
538
		buf.append("\n");
539
		buf.append("public interface I5 {\n");
540
		buf.append("    finalize\n");
541
		buf.append("}\n");
542
		ICompilationUnit cu= pack1.createCompilationUnit("I5.java", buf.toString(), false, null);
543
544
		String str= "finalize";
545
		int offset= buf.toString().indexOf(str) + str.length();
546
547
		CompletionProposalCollector collector= createCollector(cu, offset);
548
		collector.setReplacementLength(0);
549
		codeComplete(cu, offset, collector);
550
551
		IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals();
552
		assertEquals(2, proposals.length);
553
		IEditorPart part= JavaUI.openInEditor(cu);
554
		IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
555
		proposals[1].apply(doc);
556
557
		buf= new StringBuffer();
558
		buf.append("package test1;\n");
559
		buf.append("\n");
560
		buf.append("public interface I5 {\n");
561
		buf.append("    /* (non-Javadoc)\n");
562
		buf.append("     * @see java.lang.Object#finalize()\n");
563
		buf.append("     */\n");
564
		buf.append("    public void finalize() throws Throwable;\n");
565
		buf.append("}\n");
566
		assertEquals(buf.toString(), doc.get());
567
	}
568
569
	public void testOverride10() throws CoreException {
570
		IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
571
		IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null);
572
		StringBuffer buf= new StringBuffer();
573
		buf.append("package test1;\n");
574
		buf.append("\n");
575
		buf.append("public interface I6 extends A {\n");
576
		buf.append("    myAbs\n");
577
		buf.append("}\n");
578
		buf.append("\n");
579
		buf.append("interface A {\n");
580
		buf.append("    void myAbstractM();\n");
581
		buf.append("}\n");
582
		ICompilationUnit cu= pack1.createCompilationUnit("I6.java", buf.toString(), false, null);
583
584
		String str= "myAbs";
585
		int offset= buf.toString().indexOf(str) + str.length();
586
587
		CompletionProposalCollector collector= createCollector(cu, offset);
588
		collector.setReplacementLength(0);
589
		codeComplete(cu, offset, collector);
590
591
		IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals();
592
		assertEquals(2, proposals.length);
593
		IEditorPart part= JavaUI.openInEditor(cu);
594
		IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput());
595
		proposals[0].apply(doc);
596
597
		buf= new StringBuffer();
598
		buf.append("package test1;\n");
599
		buf.append("\n");
600
		buf.append("public interface I6 extends A {\n");
601
		buf.append("    /* (non-Javadoc)\n");
602
		buf.append("     * @see test1.A#myAbstractM()\n");
603
		buf.append("     */\n");
604
		buf.append("    @Override\n");
605
		buf.append("    public default void myAbstractM() {\n");
606
		buf.append("        //TODO\n");
607
		buf.append("        \n");
608
		buf.append("    }\n");
609
		buf.append("}\n");
610
		buf.append("\n");
611
		buf.append("interface A {\n");
612
		buf.append("    void myAbstractM();\n");
613
		buf.append("}\n");
614
		assertEquals(buf.toString(), doc.get());
615
	}
385
}
616
}
(-)a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java (-18 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
2
 * Copyright (c) 2000, 2015 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 350-356 Link Here
350
350
351
		String delimiter= unit.findRecommendedLineSeparator();
351
		String delimiter= unit.findRecommendedLineSeparator();
352
		int modifiers= binding.getModifiers();
352
		int modifiers= binding.getModifiers();
353
		if (!(inInterface && Modifier.isAbstract(modifiers))) {
353
		ITypeBinding declaringType= binding.getDeclaringClass();
354
		ITypeBinding typeObject= ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
355
		if (!(inInterface && declaringType == typeObject)) {
354
			// generate a method body
356
			// generate a method body
355
357
356
			Map<String, String> options= javaProject.getOptions(true);
358
			Map<String, String> options= javaProject.getOptions(true);
Lines 368-374 Link Here
368
				}
370
				}
369
			} else {
371
			} else {
370
				SuperMethodInvocation invocation= ast.newSuperMethodInvocation();
372
				SuperMethodInvocation invocation= ast.newSuperMethodInvocation();
371
				ITypeBinding declaringType= binding.getDeclaringClass();
372
				if (declaringType.isInterface()) {
373
				if (declaringType.isInterface()) {
373
					String qualifier= imports.addImport(declaringType.getErasure(), context);
374
					String qualifier= imports.addImport(declaringType.getErasure(), context);
374
					Name name= ASTNodeFactory.newName(ast, qualifier);
375
					Name name= ASTNodeFactory.newName(ast, qualifier);
Lines 405-411 Link Here
405
				decl.setJavadoc(javadoc);
406
				decl.setJavadoc(javadoc);
406
			}
407
			}
407
		}
408
		}
408
		if (settings != null && settings.overrideAnnotation && JavaModelUtil.is50OrHigher(javaProject)) {
409
		boolean overrideAnnotationRequired= settings != null && settings.overrideAnnotation && JavaModelUtil.is50OrHigher(javaProject);
410
		if (inInterface && declaringType == typeObject && !Modifier.isPublic(modifiers)) {
411
			overrideAnnotationRequired= false;
412
		}
413
		if (overrideAnnotationRequired) {
409
			addOverrideAnnotation(javaProject, rewrite, decl, binding);
414
			addOverrideAnnotation(javaProject, rewrite, decl, binding);
410
		}
415
		}
411
416
Lines 661-675 Link Here
661
666
662
	private static List<IExtendedModifier> getImplementationModifiers(AST ast, IMethodBinding method, boolean inInterface, ImportRewrite importRewrite, ImportRewriteContext context) throws JavaModelException {
667
	private static List<IExtendedModifier> getImplementationModifiers(AST ast, IMethodBinding method, boolean inInterface, ImportRewrite importRewrite, ImportRewriteContext context) throws JavaModelException {
663
		IJavaProject javaProject= importRewrite.getCompilationUnit().getJavaProject();
668
		IJavaProject javaProject= importRewrite.getCompilationUnit().getJavaProject();
664
		int modifiers= method.getModifiers() & ~Modifier.ABSTRACT & ~Modifier.NATIVE & ~Modifier.PRIVATE;
669
		int modifiers= method.getModifiers();
665
		if (inInterface) {
670
		if (inInterface) {
666
			modifiers= modifiers & ~Modifier.PROTECTED;
671
			modifiers= modifiers & ~Modifier.PROTECTED;
667
			if (!method.getDeclaringClass().isInterface() ) {
672
			if (!method.getDeclaringClass().isInterface() ) {
668
				modifiers= modifiers | Modifier.PUBLIC;
673
				modifiers= modifiers | Modifier.PUBLIC;
669
			}
674
			}
675
			if (Modifier.isAbstract(modifiers)) {
676
				modifiers= modifiers | Modifier.DEFAULT;
677
			}
670
		} else {
678
		} else {
671
			modifiers= modifiers & ~Modifier.DEFAULT;
679
			modifiers= modifiers & ~Modifier.DEFAULT;
672
		}
680
		}
681
		modifiers= modifiers & ~Modifier.ABSTRACT & ~Modifier.NATIVE & ~Modifier.PRIVATE;
673
		IAnnotationBinding[] annotations= method.getAnnotations();
682
		IAnnotationBinding[] annotations= method.getAnnotations();
674
		
683
		
675
		if (modifiers != Modifier.NONE && annotations.length > 0) {
684
		if (modifiers != Modifier.NONE && annotations.length > 0) {
Lines 729-735 Link Here
729
		IMethodBinding[] typeMethods= typeBinding.getDeclaredMethods();
738
		IMethodBinding[] typeMethods= typeBinding.getDeclaredMethods();
730
		for (int index= 0; index < typeMethods.length; index++) {
739
		for (int index= 0; index < typeMethods.length; index++) {
731
			final int modifiers= typeMethods[index].getModifiers();
740
			final int modifiers= typeMethods[index].getModifiers();
732
			if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers))
741
			if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers))
733
				allMethods.add(typeMethods[index]);
742
				allMethods.add(typeMethods[index]);
734
		}
743
		}
735
		ITypeBinding clazz= typeBinding.getSuperclass();
744
		ITypeBinding clazz= typeBinding.getSuperclass();
Lines 737-743 Link Here
737
			IMethodBinding[] methods= clazz.getDeclaredMethods();
746
			IMethodBinding[] methods= clazz.getDeclaredMethods();
738
			for (int offset= 0; offset < methods.length; offset++) {
747
			for (int offset= 0; offset < methods.length; offset++) {
739
				final int modifiers= methods[offset].getModifiers();
748
				final int modifiers= methods[offset].getModifiers();
740
				if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
749
				if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)) {
741
					if (findOverridingMethod(methods[offset], allMethods) == null)
750
					if (findOverridingMethod(methods[offset], allMethods) == null)
742
						allMethods.add(methods[offset]);
751
						allMethods.add(methods[offset]);
743
				}
752
				}
Lines 756-770 Link Here
756
			getOverridableMethods(ast, ast.resolveWellKnownType("java.lang.Object"), allMethods); //$NON-NLS-1$
765
			getOverridableMethods(ast, ast.resolveWellKnownType("java.lang.Object"), allMethods); //$NON-NLS-1$
757
		if (!isSubType)
766
		if (!isSubType)
758
			allMethods.removeAll(Arrays.asList(typeMethods));
767
			allMethods.removeAll(Arrays.asList(typeMethods));
759
		int modifiers= 0;
760
		if (!typeBinding.isInterface()) {
761
			for (int index= allMethods.size() - 1; index >= 0; index--) {
762
				IMethodBinding method= allMethods.get(index);
763
				modifiers= method.getModifiers();
764
				if (Modifier.isFinal(modifiers))
765
					allMethods.remove(index);
766
			}
767
		}
768
		return allMethods.toArray(new IMethodBinding[allMethods.size()]);
768
		return allMethods.toArray(new IMethodBinding[allMethods.size()]);
769
	}
769
	}
770
770
Lines 772-779 Link Here
772
		IMethodBinding[] methods= superBinding.getDeclaredMethods();
772
		IMethodBinding[] methods= superBinding.getDeclaredMethods();
773
		for (int offset= 0; offset < methods.length; offset++) {
773
		for (int offset= 0; offset < methods.length; offset++) {
774
			final int modifiers= methods[offset].getModifiers();
774
			final int modifiers= methods[offset].getModifiers();
775
			if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
775
			if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)) {
776
				if (findOverridingMethod(methods[offset], allMethods) == null && !Modifier.isStatic(modifiers))
776
				if (findOverridingMethod(methods[offset], allMethods) == null)
777
					allMethods.add(methods[offset]);
777
					allMethods.add(methods[offset]);
778
			}
778
			}
779
		}
779
		}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OverrideMethodsAction.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2015 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 184-190 Link Here
184
					notifyResult(false);
184
					notifyResult(false);
185
					return;
185
					return;
186
				}
186
				}
187
				if (type.isInterface()) {
187
				if (type.isInterface() && !JavaModelUtil.is18OrHigher(type.getJavaProject())) {
188
					MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_interface_not_applicable);
188
					MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_interface_not_applicable);
189
					notifyResult(false);
189
					notifyResult(false);
190
					return;
190
					return;

Return to bug 460521