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 406469 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeAnnotationsTest.java (+111 lines)
Lines 860-863 Link Here
860
		assertEqualString(preview, buf.toString());
860
		assertEqualString(preview, buf.toString());
861
	}
861
	}
862
862
863
	/**
864
	 * ASTRewriterTests for PackageQualifiedType
865
	 * @throws Exception
866
	 * 
867
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=406469
868
	 */
869
	public void testPackageQualifiedTypeAnnotations() throws Exception {
870
		if (this.apiLevel < AST.JLS8) return;
871
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test406469.bug", false, null);
872
		String contents = "package test406469.bug;\n" +
873
				"import java.lang.annotation.*;\n" +
874
				"public class X {\n" +
875
				"	@Target(ElementType.TYPE_USE)\n" +
876
				"	@Retention(RetentionPolicy.RUNTIME)\n" +
877
				"	@Documented\n" +
878
				"	static @interface NonNull { }\n" +
879
				"	class Inner {}\n" +
880
				"	\n" +
881
				"	/**\n" +
882
				" 	* @param arg  \n" +
883
				" 	*/\n" +
884
				"	test406469.bug.@NonNull IOException foo(\n" +
885
				"			test406469.bug.@NonNull FileNotFoundException arg)\n" +
886
				"		throws test406469.bug.@NonNull EOFException {\n" +
887
				"		try {\n" +
888
				"			test406469.bug.@NonNull IOError e = new test406469.bug.IOError();\n" +
889
				"			throw e;\n" +
890
				"		} catch (test406469.bug.@NonNull IOError e) {\n" +
891
				"		}\n" +
892
				"		return null;\n" +
893
				"	} \n" +
894
				"	test406469.bug.@NonNull X.@NonNull Inner fInner;\n" +
895
				"} \n" +
896
				"@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {} \n" +
897
				"@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface A {} \n" +
898
				"@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface B {} \n" +
899
				"\n" +
900
				"class Outer {\n" +
901
				"	public class Inner {\n" +
902
				"		public class Deeper {}\n" +
903
				"	}\n" +
904
				"}\n" +
905
				"class IOException extends Exception {private static final long serialVersionUID=10001L;}\n" +
906
				"class FileNotFoundException extends Exception{private static final long serialVersionUID=10002L;}\n" +
907
				"class EOFException extends Exception{private static final long serialVersionUID=10003L;}\n" +
908
				"class IOError extends Exception{private static final long serialVersionUID=10004L;}\n";
909
		StringBuffer buf = new StringBuffer(contents);			
910
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
911
		CompilationUnit astRoot= createAST(cu, /* resolve */ true, false);
912
		ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
913
		AST ast= astRoot.getAST();
914
		TypeDeclaration typeDeclaration= findTypeDeclaration(astRoot, "X");
915
		MethodDeclaration methodDeclaration= findMethodDeclaration(typeDeclaration, "foo");
916
		{   //replace an annotation.
917
			PackageQualifiedType packageQualifiedType = (PackageQualifiedType) methodDeclaration.getReturnType2();
918
			MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
919
			markerAnnotation.setTypeName(ast.newSimpleName("Marker"));
920
			rewrite.replace((ASTNode) packageQualifiedType.annotations().get(0), markerAnnotation, null);
921
922
			// remove an annotation
923
			SingleVariableDeclaration param = (SingleVariableDeclaration) methodDeclaration.parameters().get(0);
924
			packageQualifiedType = (PackageQualifiedType) param.getType();
925
			rewrite.remove((ASTNode) packageQualifiedType.annotations().get(0), null);
926
			
927
			// insert an annotation
928
			packageQualifiedType = (PackageQualifiedType) methodDeclaration.thrownExceptionTypes().get(0);
929
			markerAnnotation= ast.newMarkerAnnotation();
930
			markerAnnotation.setTypeName(ast.newSimpleName("Marker"));
931
			rewrite.getListRewrite(packageQualifiedType, PackageQualifiedType.ANNOTATIONS_PROPERTY).insertLast(markerAnnotation, null);
932
		}
933
		String preview= evaluateRewrite(cu, rewrite);
934
		String contentsmodified = "package test406469.bug;\n" +
935
				"import java.lang.annotation.*;\n" +
936
				"public class X {\n" +
937
				"	@Target(ElementType.TYPE_USE)\n" +
938
				"	@Retention(RetentionPolicy.RUNTIME)\n" +
939
				"	@Documented\n" +
940
				"	static @interface NonNull { }\n" +
941
				"	class Inner {}\n" +
942
				"	\n" +
943
				"	/**\n" +
944
				" 	* @param arg  \n" +
945
				" 	*/\n" +
946
				"	test406469.bug.@Marker IOException foo(\n" +
947
				"			FileNotFoundException arg)\n" +
948
				"		throws test406469.bug.@NonNull @Marker EOFException {\n" +
949
				"		try {\n" +
950
				"			test406469.bug.@NonNull IOError e = new test406469.bug.IOError();\n" +
951
				"			throw e;\n" +
952
				"		} catch (test406469.bug.@NonNull IOError e) {\n" +
953
				"		}\n" +
954
				"		return null;\n" +
955
				"	} \n" +
956
				"	test406469.bug.@NonNull X.@NonNull Inner fInner;\n" +
957
				"} \n" +
958
				"@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {} \n" +
959
				"@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface A {} \n" +
960
				"@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface B {} \n" +
961
				"\n" +
962
				"class Outer {\n" +
963
				"	public class Inner {\n" +
964
				"		public class Deeper {}\n" +
965
				"	}\n" +
966
				"}\n" +
967
				"class IOException extends Exception {private static final long serialVersionUID=10001L;}\n" +
968
				"class FileNotFoundException extends Exception{private static final long serialVersionUID=10002L;}\n" +
969
				"class EOFException extends Exception{private static final long serialVersionUID=10003L;}\n" +
970
				"class IOError extends Exception{private static final long serialVersionUID=10004L;}\n";
971
		assertEqualString(preview, contentsmodified);
972
	}
973
863
}
974
}
(-)a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java (+14 lines)
Lines 3972-3977 Link Here
3972
		return false;
3972
		return false;
3973
	}
3973
	}
3974
	/* (non-Javadoc)
3974
	/* (non-Javadoc)
3975
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.PackageQualifiedType)
3976
	 */
3977
	public boolean visit(PackageQualifiedType node) {
3978
		if (!hasChildrenChanges(node)) {
3979
			return doVisitUnchangedChildren(node);
3980
		}
3981
		rewriteRequiredNode(node, PackageQualifiedType.QUALIFIER_PROPERTY);
3982
		if (node.getAST().apiLevel() >= AST.JLS8) {
3983
			rewriteTypeAnnotations(node, PackageQualifiedType.ANNOTATIONS_PROPERTY, node.getStartPosition());
3984
		}
3985
		rewriteRequiredNode(node, PackageQualifiedType.NAME_PROPERTY);
3986
		return false;
3987
	}
3988
	/* (non-Javadoc)
3975
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ParameterizedType)
3989
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ParameterizedType)
3976
	 */
3990
	 */
3977
	public boolean visit(ParameterizedType node) {
3991
	public boolean visit(ParameterizedType node) {
(-)a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java (+15 lines)
Lines 1409-1414 Link Here
1409
		this.result.append(')');
1409
		this.result.append(')');
1410
		return false;
1410
		return false;
1411
	}
1411
	}
1412
1413
	/*
1414
	 * @see ASTVisitor#visit(PackageQualifiedType)
1415
	 * @since 3.9
1416
	 */
1417
	public boolean visit(PackageQualifiedType node) {
1418
		getChildNode(node, PackageQualifiedType.QUALIFIER_PROPERTY).accept(this);
1419
		this.result.append('.');
1420
		if (node.getAST().apiLevel() >= AST.JLS8) {
1421
			visitList(node, PackageQualifiedType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
1422
		}
1423
		getChildNode(node, PackageQualifiedType.NAME_PROPERTY).accept(this);
1424
		return false;
1425
	}
1426
1412
	/*
1427
	/*
1413
	 * @see ASTVisitor#visit(ParameterizedType)
1428
	 * @see ASTVisitor#visit(ParameterizedType)
1414
	 * @since 3.0
1429
	 * @since 3.0

Return to bug 406469