View | Details | Raw Unified | Return to bug 264443
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (-1 / +128 lines)
Lines 122-128 Link Here
122
	static {
122
	static {
123
//		TESTS_NAMES = new String[] {"test0602"};
123
//		TESTS_NAMES = new String[] {"test0602"};
124
//		TESTS_RANGE = new int[] { 670, -1 };
124
//		TESTS_RANGE = new int[] { 670, -1 };
125
//		TESTS_NUMBERS =  new int[] { 697, 698 };
125
//		TESTS_NUMBERS =  new int[] { 699, 700, 701 };
126
	}
126
	}
127
	public static Test suite() {
127
	public static Test suite() {
128
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
128
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
Lines 9977-9980 Link Here
9977
			}
9977
			}
9978
		}
9978
		}
9979
	}
9979
	}
9980
9981
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264443
9982
	public void test0699() throws JavaModelException {
9983
		ICompilationUnit workingCopy = null;
9984
		try {
9985
			workingCopy = getWorkingCopy("/Converter/src/example/Test.java", true/*resolve*/);
9986
			String contents =
9987
				"package example;\n" + 
9988
				"public class Test {\n" + 
9989
				"	public void test() throws Throwable {\n" + 
9990
				"		B /*start*/b = new B()/*end*/;\n" + 
9991
				"	}\n" + 
9992
				"}";
9993
	
9994
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) buildAST(contents, workingCopy, false, true, true);
9995
			IVariableBinding variableBinding = fragment.resolveBinding();
9996
			final String key = variableBinding.getKey();
9997
			ASTParser parser = ASTParser.newParser(AST.JLS3);
9998
			parser.setProject(workingCopy.getJavaProject());
9999
			parser.setResolveBindings(true);
10000
			parser.setKind(ASTParser.K_COMPILATION_UNIT);
10001
	
10002
			parser.createASTs(
10003
					new ICompilationUnit[] { workingCopy },
10004
					new String[] { key },
10005
					new ASTRequestor() {
10006
						public void acceptBinding(String bindingKey,
10007
								IBinding binding) {
10008
							assertEquals("Wrong key", key, bindingKey);
10009
							assertTrue("Not a variable binding", binding.getKind() == IBinding.VARIABLE);
10010
						}
10011
	
10012
						public void acceptAST(ICompilationUnit source,
10013
								CompilationUnit astCompilationUnit) {
10014
						}
10015
					}, null);
10016
		} finally {
10017
			if (workingCopy != null) {
10018
				workingCopy.discardWorkingCopy();
10019
			}
10020
		}
10021
	}
10022
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264443
10023
	public void test0700() throws JavaModelException {
10024
		ICompilationUnit workingCopy = null;
10025
		try {
10026
			workingCopy = getWorkingCopy("/Converter/src/example/Test.java", true/*resolve*/);
10027
			String contents =
10028
				"package example;\n" + 
10029
				"import java.io.IOException;\n" +
10030
				"public class Test {\n" + 
10031
				"	public void test() throws IOException, RuntimeException {\n" + 
10032
				"		B /*start*/b = new B()/*end*/;\n" + 
10033
				"	}\n" + 
10034
				"}";
10035
	
10036
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) buildAST(contents, workingCopy, false, true, true);
10037
			IVariableBinding variableBinding = fragment.resolveBinding();
10038
			final String key = variableBinding.getKey();
10039
			ASTParser parser = ASTParser.newParser(AST.JLS3);
10040
			parser.setProject(workingCopy.getJavaProject());
10041
			parser.setResolveBindings(true);
10042
			parser.setKind(ASTParser.K_COMPILATION_UNIT);
10043
	
10044
			parser.createASTs(
10045
					new ICompilationUnit[] { workingCopy },
10046
					new String[] { key },
10047
					new ASTRequestor() {
10048
						public void acceptBinding(String bindingKey,
10049
								IBinding binding) {
10050
							assertEquals("Wrong key", key, bindingKey);
10051
							assertTrue("Not a variable binding", binding.getKind() == IBinding.VARIABLE);
10052
						}
10053
	
10054
						public void acceptAST(ICompilationUnit source,
10055
								CompilationUnit astCompilationUnit) {
10056
						}
10057
					}, null);
10058
		} finally {
10059
			if (workingCopy != null) {
10060
				workingCopy.discardWorkingCopy();
10061
			}
10062
		}
10063
	}
10064
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264443
10065
	//no thrown exceptions
10066
	public void test0701() throws JavaModelException {
10067
		ICompilationUnit workingCopy = null;
10068
		try {
10069
			workingCopy = getWorkingCopy("/Converter/src/example/Test.java", true/*resolve*/);
10070
			String contents =
10071
				"package example;\n" + 
10072
				"import java.io.IOException;\n" +
10073
				"public class Test {\n" + 
10074
				"	public void test() {\n" + 
10075
				"		B /*start*/b = new B()/*end*/;\n" + 
10076
				"	}\n" + 
10077
				"}";
10078
	
10079
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) buildAST(contents, workingCopy, false, true, true);
10080
			IVariableBinding variableBinding = fragment.resolveBinding();
10081
			final String key = variableBinding.getKey();
10082
			ASTParser parser = ASTParser.newParser(AST.JLS3);
10083
			parser.setProject(workingCopy.getJavaProject());
10084
			parser.setResolveBindings(true);
10085
			parser.setKind(ASTParser.K_COMPILATION_UNIT);
10086
	
10087
			parser.createASTs(
10088
					new ICompilationUnit[] { workingCopy },
10089
					new String[] { key },
10090
					new ASTRequestor() {
10091
						public void acceptBinding(String bindingKey,
10092
								IBinding binding) {
10093
							assertEquals("Wrong key", key, bindingKey);
10094
							assertTrue("Not a variable binding", binding.getKind() == IBinding.VARIABLE);
10095
						}
10096
	
10097
						public void acceptAST(ICompilationUnit source,
10098
								CompilationUnit astCompilationUnit) {
10099
						}
10100
					}, null);
10101
		} finally {
10102
			if (workingCopy != null) {
10103
				workingCopy.discardWorkingCopy();
10104
			}
10105
		}
10106
	}
9980
}
10107
}
(-)model/org/eclipse/jdt/internal/core/util/BindingKeyParser.java (-14 / +56 lines)
Lines 743-752 Link Here
743
	}
743
	}
744
744
745
	private void parseLocalVariable() {
745
	private void parseLocalVariable() {
746
	 	if (this.scanner.nextToken() != Scanner.LOCAL_VAR) {
746
		if (this.scanner.nextToken() != Scanner.LOCAL_VAR) {
747
	 		malformedKey();
747
			malformedKey();
748
			return;
748
			return;
749
	 	}
749
		}
750
		char[] varName = this.scanner.getTokenSource();
750
		char[] varName = this.scanner.getTokenSource();
751
		if (Character.isDigit(varName[0])) {
751
		if (Character.isDigit(varName[0])) {
752
			int index = Integer.parseInt(new String(varName));
752
			int index = Integer.parseInt(new String(varName));
Lines 759-792 Link Here
759
		} else {
759
		} else {
760
			int occurrenceCount = 0;
760
			int occurrenceCount = 0;
761
			if (this.scanner.isAtLocalVariableStart()) {
761
			if (this.scanner.isAtLocalVariableStart()) {
762
			 	if (this.scanner.nextToken() != Scanner.LOCAL_VAR) {
762
				if (this.scanner.nextToken() != Scanner.LOCAL_VAR) {
763
			 		malformedKey();
763
					malformedKey();
764
					return;
764
					return;
765
			 	}
765
				}
766
				char[] occurrence = this.scanner.getTokenSource();
766
				char[] occurrence = this.scanner.getTokenSource();
767
				occurrenceCount = Integer.parseInt(new String(occurrence));
767
				occurrenceCount = Integer.parseInt(new String(occurrence));
768
			}
768
			}
769
		 	consumeLocalVar(varName, occurrenceCount);
769
			consumeLocalVar(varName, occurrenceCount);
770
		}
770
		}
771
 	}
771
	}
772
772
773
	private void parseMethod() {
773
	private void parseMethod() {
774
	 	char[] selector = this.scanner.getTokenSource();
774
		char[] selector = this.scanner.getTokenSource();
775
	 	this.scanner.skipMethodSignature();
775
		this.scanner.skipMethodSignature();
776
	 	char[] signature = this.scanner.getTokenSource();
776
		char[] signature = this.scanner.getTokenSource();
777
	 	consumeMethod(selector, signature);
777
		consumeMethod(selector, signature);
778
	 	if (this.scanner.isAtThrownStart()) {
778
		if (this.scanner.isAtThrownStart()) {
779
			parseThrownExceptions();
779
			parseThrownExceptions();
780
	 	}
780
		}
781
		if (this.scanner.isAtParametersStart())
781
		if (this.scanner.isAtParametersStart())
782
			parseParameterizedMethod();
782
			parseParameterizedMethod();
783
	}
783
	}
784
784
785
	private void parseAnnotation() {
785
	private void parseAnnotation() {
786
		/*
787
		 * The call parser.parse() might have a side-effect on the current token type
788
		 * See bug 264443
789
		 */
790
		int token = this.scanner.token;
786
		BindingKeyParser parser = newParser();
791
		BindingKeyParser parser = newParser();
787
		parser.parse();
792
		parser.parse();
788
		consumeParser(parser);
793
		consumeParser(parser);
789
		consumeAnnotation();
794
		consumeAnnotation();
795
		this.scanner.token = token;
790
	}
796
	}
791
797
792
	private void parseCapture() {
798
	private void parseCapture() {
Lines 803-811 Link Here
803
	}
809
	}
804
810
805
	private void parseCaptureWildcard() {
811
	private void parseCaptureWildcard() {
812
		/*
813
		 * The call parser.parse() might have a side-effect on the current token type
814
		 * See bug 264443
815
		 */
816
		int token = this.scanner.token;
806
		BindingKeyParser parser = newParser();
817
		BindingKeyParser parser = newParser();
807
		parser.parse();
818
		parser.parse();
808
		consumeParser(parser);
819
		consumeParser(parser);
820
		this.scanner.token = token;
809
	}
821
	}
810
822
811
	private void parseField() {
823
	private void parseField() {
Lines 815-820 Link Here
815
	}
827
	}
816
828
817
	private void parseThrownExceptions() {
829
	private void parseThrownExceptions() {
830
		/*
831
		 * The call parser.parse() might have a side-effect on the current token type
832
		 * See bug 264443
833
		 */
834
		int token = this.scanner.token;
818
		while (this.scanner.isAtThrownStart()) {
835
		while (this.scanner.isAtThrownStart()) {
819
			this.scanner.skipThrownStart();
836
			this.scanner.skipThrownStart();
820
			BindingKeyParser parser = newParser();
837
			BindingKeyParser parser = newParser();
Lines 822-827 Link Here
822
			consumeParser(parser);
839
			consumeParser(parser);
823
			consumeException();
840
			consumeException();
824
		}
841
		}
842
		this.scanner.token = token;
825
	}
843
	}
826
844
827
	private void parseParameterizedType(char[] typeName, boolean isRaw) {
845
	private void parseParameterizedType(char[] typeName, boolean isRaw) {
Lines 860-868 Link Here
860
878
861
	private void parseReturnType() {
879
	private void parseReturnType() {
862
		this.scanner.index++; // skip ')'
880
		this.scanner.index++; // skip ')'
881
		/*
882
		 * The call parser.parse() might have a side-effect on the current token type
883
		 * See bug 264443
884
		 */
885
		int token = this.scanner.token;
863
		BindingKeyParser parser = newParser();
886
		BindingKeyParser parser = newParser();
864
		parser.parse();
887
		parser.parse();
865
		consumeParser(parser);
888
		consumeParser(parser);
889
		this.scanner.token = token;
866
	}
890
	}
867
891
868
	private void parseSecondaryType() {
892
	private void parseSecondaryType() {
Lines 871-887 Link Here
871
	}
895
	}
872
896
873
	private void parseTypeArgument() {
897
	private void parseTypeArgument() {
898
		/*
899
		 * The call parser.parse() might have a side-effect on the current token type
900
		 * See bug 264443
901
		 */
902
		int token = this.scanner.token;
874
		BindingKeyParser parser = newParser();
903
		BindingKeyParser parser = newParser();
875
		parser.parse();
904
		parser.parse();
876
		consumeParser(parser);
905
		consumeParser(parser);
906
		this.scanner.token = token;
877
	}
907
	}
878
908
879
	private void parseTypeWithCapture() {
909
	private void parseTypeWithCapture() {
880
		if (this.scanner.nextToken() != Scanner.CAPTURE) return;
910
		if (this.scanner.nextToken() != Scanner.CAPTURE) return;
911
		/*
912
		 * The call parser.parse() might have a side-effect on the current token type
913
		 * See bug 264443
914
		 */
915
		int token = this.scanner.token;
881
		BindingKeyParser parser = newParser();
916
		BindingKeyParser parser = newParser();
882
		parser.parse();
917
		parser.parse();
883
		consumeParser(parser);
918
		consumeParser(parser);
884
		consumeTypeWithCapture();
919
		consumeTypeWithCapture();
920
		this.scanner.token = token;
885
	}
921
	}
886
922
887
	private void parseTypeVariable() {
923
	private void parseTypeVariable() {
Lines 941-949 Link Here
941
	}
977
	}
942
	
978
	
943
	private void parseWildcardBound() {
979
	private void parseWildcardBound() {
980
		/*
981
		 * The call parser.parse() might have a side-effect on the current token type
982
		 * See bug 264443
983
		 */
984
		int token = this.scanner.token;
944
		BindingKeyParser parser = newParser();
985
		BindingKeyParser parser = newParser();
945
		parser.parse();
986
		parser.parse();
946
		consumeParser(parser);
987
		consumeParser(parser);
988
		this.scanner.token = token;
947
	}
989
	}
948
990
949
}
991
}

Return to bug 264443