View | Details | Raw Unified | Return to bug 288211 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java (+1 lines)
Lines 853-858 Link Here
853
		p.setBindingsRecovery(true);
853
		p.setBindingsRecovery(true);
854
		p.setProject( javaProject );
854
		p.setProject( javaProject );
855
		p.setKind( ASTParser.K_COMPILATION_UNIT );
855
		p.setKind( ASTParser.K_COMPILATION_UNIT );
856
		p.ignoreMethodBodies();
856
		p.createASTs( parseUnits, keys,  requestor, null);
857
		p.createASTs( parseUnits, keys,  requestor, null);
857
	}
858
	}
858
	
859
	
(-)src/org/eclipse/jdt/apt/tests/AptBuilderTests.java (-4 / +4 lines)
Lines 371-378 Link Here
371
		// parse the source, parsing runs through the compiler, and this registers the 
371
		// parse the source, parsing runs through the compiler, and this registers the 
372
		// file a second time with the Compiler#DebugRequestor 
372
		// file a second time with the Compiler#DebugRequestor 
373
		//
373
		//
374
		expectingCompiledClasses(new String[]{"p1.p2.p3.p4.C", "p1.p2.p3.p4.A", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$
374
		expectingCompiledClasses(new String[]{"p1.p2.p3.p4.C", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$
375
		expectingCompilingOrder(new String[]{"p1.p2.p3.p4.C", "p1.p2.p3.p4.A", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$
375
		expectingCompilingOrder(new String[]{"p1.p2.p3.p4.C", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$
376
		
376
		
377
		//
377
		//
378
		// now make sure that p1.p2.p3.p4.C is not compiled when A uses NoOp Annotation
378
		// now make sure that p1.p2.p3.p4.C is not compiled when A uses NoOp Annotation
Lines 448-461 Link Here
448
		
448
		
449
		fullBuild( project.getFullPath() );
449
		fullBuild( project.getFullPath() );
450
		expectingNoProblems();
450
		expectingNoProblems();
451
		expectingCompiledClasses(new String[] {"p1.A", "p1.A", "generatedfilepackage.GeneratedFileTest"}); //$NON-NLS-1 //$NON_NLS-2$
451
		expectingCompiledClasses(new String[] {"p1.A", "generatedfilepackage.GeneratedFileTest"}); //$NON-NLS-1 //$NON_NLS-2$
452
		
452
		
453
		// touch A - make sure its public shape changes.
453
		// touch A - make sure its public shape changes.
454
		env.addClass( srcRoot, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
454
		env.addClass( srcRoot, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
455
			modifiedCode );
455
			modifiedCode );
456
		incrementalBuild( project.getFullPath() );
456
		incrementalBuild( project.getFullPath() );
457
		expectingNoProblems();
457
		expectingNoProblems();
458
		expectingCompiledClasses(new String[]{"p1.A", "p1.A"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
458
		expectingCompiledClasses(new String[]{"p1.A"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
459
	}
459
	}
460
460
461
	/**
461
	/**
(-)compiler/org/eclipse/jdt/internal/compiler/Compiler.java (-7 / +6 lines)
Lines 760-775 Link Here
760
760
761
		long analyzeStart = System.currentTimeMillis();
761
		long analyzeStart = System.currentTimeMillis();
762
		this.stats.resolveTime += analyzeStart - resolveStart;
762
		this.stats.resolveTime += analyzeStart - resolveStart;
763
763
		
764
		// flow analysis
764
		//No need of analysis or generation of code if statements are not required		
765
		unit.analyseCode();
765
		if (!this.options.ignoreMethodBodies) unit.analyseCode(); // flow analysis
766
766
767
		long generateStart = System.currentTimeMillis();
767
		long generateStart = System.currentTimeMillis();
768
		this.stats.analyzeTime += generateStart - analyzeStart;
768
		this.stats.analyzeTime += generateStart - analyzeStart;
769
769
	
770
		// code generation
770
		if (!this.options.ignoreMethodBodies) unit.generateCode(); // code generation
771
		unit.generateCode();
771
		
772
773
		// reference info
772
		// reference info
774
		if (this.options.produceReferenceInfo && unit.scope != null)
773
		if (this.options.produceReferenceInfo && unit.scope != null)
775
			unit.scope.storeDependencyInfo();
774
			unit.scope.storeDependencyInfo();
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-2 / +4 lines)
Lines 333-339 Link Here
333
	public boolean reportMissingOverrideAnnotationForInterfaceMethodImplementation;
333
	public boolean reportMissingOverrideAnnotationForInterfaceMethodImplementation;
334
	/** Indicate if annotation processing generates classfiles */
334
	/** Indicate if annotation processing generates classfiles */
335
	public boolean generateClassFiles;
335
	public boolean generateClassFiles;
336
336
	public boolean ignoreMethodBodies;
337
337
338
	// keep in sync with warningTokenToIrritant and warningTokenFromIrritant
338
	// keep in sync with warningTokenToIrritant and warningTokenFromIrritant
339
	public final static String[] warningTokens = {
339
	public final static String[] warningTokens = {
Lines 1028-1034 Link Here
1028
		
1028
		
1029
		// dead code detection
1029
		// dead code detection
1030
		this.reportDeadCodeInTrivialIfStatement = false;
1030
		this.reportDeadCodeInTrivialIfStatement = false;
1031
1031
		
1032
		// ignore method bodies
1033
		this.ignoreMethodBodies = false;
1032
	}
1034
	}
1033
1035
1034
	public void set(Map optionsMap) {
1036
	public void set(Map optionsMap) {
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-28 / +38 lines)
Lines 9450-9484 Link Here
9450
	int length;
9450
	int length;
9451
	if (this.astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) != 0) {
9451
	if (this.astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) != 0) {
9452
		this.astPtr -= length;
9452
		this.astPtr -= length;
9453
		if (this.astStack[this.astPtr + 1] instanceof ExplicitConstructorCall)
9453
		if ((cd.bits & ASTNode.HasLocalType) != 0 || !this.options.ignoreMethodBodies) {
9454
			//avoid a isSomeThing that would only be used here BUT what is faster between two alternatives ?
9454
			if (this.astStack[this.astPtr + 1] instanceof ExplicitConstructorCall)
9455
			{
9455
				//avoid a isSomeThing that would only be used here BUT what is faster between two alternatives ?
9456
			System.arraycopy(
9456
				{
9457
				this.astStack,
9457
				System.arraycopy(
9458
				this.astPtr + 2,
9458
					this.astStack,
9459
				cd.statements = new Statement[length - 1],
9459
					this.astPtr + 2,
9460
				0,
9460
					cd.statements = new Statement[length - 1],
9461
				length - 1);
9461
					0,
9462
			cd.constructorCall = (ExplicitConstructorCall) this.astStack[this.astPtr + 1];
9462
					length - 1);
9463
		} else { //need to add explicitly the super();
9463
				cd.constructorCall = (ExplicitConstructorCall) this.astStack[this.astPtr + 1];
9464
			System.arraycopy(
9464
			} else { //need to add explicitly the super();
9465
				this.astStack,
9465
				System.arraycopy(
9466
				this.astPtr + 1,
9466
					this.astStack,
9467
				cd.statements = new Statement[length],
9467
					this.astPtr + 1,
9468
				0,
9468
					cd.statements = new Statement[length],
9469
				length);
9469
					0,
9470
			cd.constructorCall = SuperReference.implicitSuperConstructorCall();
9470
					length);
9471
				cd.constructorCall = SuperReference.implicitSuperConstructorCall();
9472
			}
9471
		}
9473
		}
9472
	} else {
9474
	} else {
9473
		cd.constructorCall = SuperReference.implicitSuperConstructorCall();
9475
		if (!this.options.ignoreMethodBodies) {
9476
			cd.constructorCall = SuperReference.implicitSuperConstructorCall();
9477
		}
9474
		if (!containsComment(cd.bodyStart, cd.bodyEnd)) {
9478
		if (!containsComment(cd.bodyStart, cd.bodyEnd)) {
9475
			cd.bits |= ASTNode.UndocumentedEmptyBlock;
9479
			cd.bits |= ASTNode.UndocumentedEmptyBlock;
9476
		}
9480
		}
9477
	}
9481
	}
9478
9482
9479
	if (cd.constructorCall.sourceEnd == 0) {
9483
	ExplicitConstructorCall explicitConstructorCall = cd.constructorCall;
9480
		cd.constructorCall.sourceEnd = cd.sourceEnd;
9484
	if (explicitConstructorCall != null && explicitConstructorCall.sourceEnd == 0) {
9481
		cd.constructorCall.sourceStart = cd.sourceStart;
9485
		explicitConstructorCall.sourceEnd = cd.sourceEnd;
9486
		explicitConstructorCall.sourceStart = cd.sourceStart;
9482
	}
9487
	}
9483
}
9488
}
9484
// A P I
9489
// A P I
Lines 9691-9702 Link Here
9691
	md.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
9696
	md.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
9692
	int length;
9697
	int length;
9693
	if (this.astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) != 0) {
9698
	if (this.astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) != 0) {
9694
		System.arraycopy(
9699
		if ((md.bits & ASTNode.HasLocalType) == 0 && this.options.ignoreMethodBodies) {
9695
			this.astStack,
9700
			// ignore statements
9696
			(this.astPtr -= length) + 1,
9701
			this.astPtr -= length;
9697
			md.statements = new Statement[length],
9702
		} else {
9698
			0,
9703
			System.arraycopy(
9699
			length);
9704
				this.astStack,
9705
				(this.astPtr -= length) + 1,
9706
				md.statements = new Statement[length],
9707
				0,
9708
				length);
9709
		}
9700
	} else {
9710
	} else {
9701
		if (!containsComment(md.bodyStart, md.bodyEnd)) {
9711
		if (!containsComment(md.bodyStart, md.bodyEnd)) {
9702
			md.bits |= ASTNode.UndocumentedEmptyBlock;
9712
			md.bits |= ASTNode.UndocumentedEmptyBlock;
(-)dom/org/eclipse/jdt/core/dom/ASTParser.java (-1 / +22 lines)
Lines 149-154 Link Here
149
	private boolean statementsRecovery;
149
	private boolean statementsRecovery;
150
150
151
	/**
151
	/**
152
	 * Request to ignore parsing the method bodies. Defaults to <code>false</code>.
153
     */
154
	private boolean ignoreMethodBodies;
155
	/**
152
     * Request for a bindings recovery. Defaults to <code>false</code>.
156
     * Request for a bindings recovery. Defaults to <code>false</code>.
153
     */
157
     */
154
    private boolean bindingsRecovery;
158
    private boolean bindingsRecovery;
Lines 226-231 Link Here
226
		this.rawSource = null;
230
		this.rawSource = null;
227
		this.typeRoot = null;
231
		this.typeRoot = null;
228
		this.resolveBindings = false;
232
		this.resolveBindings = false;
233
		this.ignoreMethodBodies = false;
229
		this.sourceLength = -1;
234
		this.sourceLength = -1;
230
		this.sourceOffset = 0;
235
		this.sourceOffset = 0;
231
		this.workingCopyOwner = DefaultWorkingCopyOwner.PRIMARY;
236
		this.workingCopyOwner = DefaultWorkingCopyOwner.PRIMARY;
Lines 564-569 Link Here
564
	public void setStatementsRecovery(boolean enabled) {
569
	public void setStatementsRecovery(boolean enabled) {
565
		this.statementsRecovery = enabled;
570
		this.statementsRecovery = enabled;
566
	}
571
	}
572
	
573
	/**
574
	 * Requests an abstract syntax tree without method bodies. 
575
	 * If this functions is called, even the code analysis and generation are not done.
576
	 * If the function has anonymous classes, the method bodies will be retained. 
577
	 * This flag is honored only when the source is a compilation unit and the full 
578
	 * AST is required.
579
	 *
580
	 * @since 3.6
581
	 */
582
	public void ignoreMethodBodies() {
583
		this.ignoreMethodBodies = true;
584
	}
567
585
568
    /**
586
    /**
569
     * Sets the working copy owner using when resolving bindings, where
587
     * Sets the working copy owner using when resolving bindings, where
Lines 730-735 Link Here
730
		try {
748
		try {
731
			int flags = 0;
749
			int flags = 0;
732
			if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
750
			if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
751
			if (this.ignoreMethodBodies) flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
733
			if (this.resolveBindings) {
752
			if (this.resolveBindings) {
734
				if (this.project == null)
753
				if (this.project == null)
735
					throw new IllegalStateException("project not specified"); //$NON-NLS-1$
754
					throw new IllegalStateException("project not specified"); //$NON-NLS-1$
Lines 790-795 Link Here
790
			int flags = 0;
809
			int flags = 0;
791
			if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
810
			if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
792
			if (this.bindingsRecovery)  flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
811
			if (this.bindingsRecovery)  flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
812
			if (this.ignoreMethodBodies) flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
793
			return CompilationUnitResolver.resolve(elements, this.apiLevel, this.compilerOptions, this.project, this.workingCopyOwner, flags, monitor);
813
			return CompilationUnitResolver.resolve(elements, this.apiLevel, this.compilerOptions, this.project, this.workingCopyOwner, flags, monitor);
794
		} finally {
814
		} finally {
795
			// re-init defaults to allow reuse (and avoid leaking)
815
			// re-init defaults to allow reuse (and avoid leaking)
Lines 900-905 Link Here
900
					}
920
					}
901
					int flags = 0;
921
					int flags = 0;
902
					if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
922
					if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
923
					if (searcher == null && this.ignoreMethodBodies) flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
903
					if (needToResolveBindings) {
924
					if (needToResolveBindings) {
904
						if (this.bindingsRecovery) flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
925
						if (this.bindingsRecovery) flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
905
						try {
926
						try {
Lines 1034-1040 Link Here
1034
			ast.setFlag(ICompilationUnit.ENABLE_STATEMENTS_RECOVERY);
1055
			ast.setFlag(ICompilationUnit.ENABLE_STATEMENTS_RECOVERY);
1035
		}
1056
		}
1036
		converter.setAST(ast);
1057
		converter.setAST(ast);
1037
		CodeSnippetParsingUtil codeSnippetParsingUtil = new CodeSnippetParsingUtil();
1058
		CodeSnippetParsingUtil codeSnippetParsingUtil = new CodeSnippetParsingUtil(this.ignoreMethodBodies);
1038
		CompilationUnit compilationUnit = ast.newCompilationUnit();
1059
		CompilationUnit compilationUnit = ast.newCompilationUnit();
1039
		if (this.sourceLength == -1) {
1060
		if (this.sourceLength == -1) {
1040
			this.sourceLength = this.rawSource.length;
1061
			this.sourceLength = this.rawSource.length;
(-)dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java (-14 / +27 lines)
Lines 340-345 Link Here
340
	public static void parse(ICompilationUnit[] compilationUnits, ASTRequestor astRequestor, int apiLevel, Map options, int flags, IProgressMonitor monitor) {
340
	public static void parse(ICompilationUnit[] compilationUnits, ASTRequestor astRequestor, int apiLevel, Map options, int flags, IProgressMonitor monitor) {
341
		try {
341
		try {
342
			CompilerOptions compilerOptions = new CompilerOptions(options);
342
			CompilerOptions compilerOptions = new CompilerOptions(options);
343
			compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
343
			Parser parser = new CommentRecorderParser(
344
			Parser parser = new CommentRecorderParser(
344
				new ProblemReporter(
345
				new ProblemReporter(
345
						DefaultErrorHandlingPolicies.proceedWithAllProblems(),
346
						DefaultErrorHandlingPolicies.proceedWithAllProblems(),
Lines 363-370 Link Here
363
				//real parse of the method....
364
				//real parse of the method....
364
				org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
365
				org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
365
				if (types != null) {
366
				if (types != null) {
366
					for (int j = 0, typeLength = types.length; j < typeLength; j++)
367
					for (int j = 0, typeLength = types.length; j < typeLength; j++) {
367
						types[j].parseMethods(parser, compilationUnitDeclaration);
368
						types[j].parseMethods(parser, compilationUnitDeclaration);
369
					}
368
				}
370
				}
369
371
370
				// convert AST
372
				// convert AST
Lines 393-398 Link Here
393
		boolean statementsRecovery = (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0;
395
		boolean statementsRecovery = (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0;
394
		compilerOptions.performMethodsFullRecovery = statementsRecovery;
396
		compilerOptions.performMethodsFullRecovery = statementsRecovery;
395
		compilerOptions.performStatementsRecovery = statementsRecovery;
397
		compilerOptions.performStatementsRecovery = statementsRecovery;
398
		compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
396
		Parser parser = new CommentRecorderParser(
399
		Parser parser = new CommentRecorderParser(
397
			new ProblemReporter(
400
			new ProblemReporter(
398
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
401
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
Lines 435-447 Link Here
435
				}
438
				}
436
			}
439
			}
437
		} else {
440
		} else {
438
			//fill the methods bodies in order for the code to be generated
441
				//fill the methods bodies in order for the code to be generated
439
			//real parse of the method....
442
				//real parse of the method....			
440
			org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
443
				org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
441
			if (types != null) {
444
				if (types != null) {
442
				for (int i = 0, length = types.length; i < length; i++)
445
					for (int j = 0, typeLength = types.length; j < typeLength; j++) {
443
					types[i].parseMethods(parser, compilationUnitDeclaration);
446
						types[j].parseMethods(parser, compilationUnitDeclaration);
444
			}
447
					}
448
				}
445
		}
449
		}
446
		return compilationUnitDeclaration;
450
		return compilationUnitDeclaration;
447
	}
451
	}
Lines 466-480 Link Here
466
			}
470
			}
467
			environment = new CancelableNameEnvironment(((JavaProject) javaProject), owner, monitor);
471
			environment = new CancelableNameEnvironment(((JavaProject) javaProject), owner, monitor);
468
			problemFactory = new CancelableProblemFactory(monitor);
472
			problemFactory = new CancelableProblemFactory(monitor);
473
			CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
474
			compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
469
			CompilationUnitResolver resolver =
475
			CompilationUnitResolver resolver =
470
				new CompilationUnitResolver(
476
				new CompilationUnitResolver(
471
					environment,
477
					environment,
472
					getHandlingPolicy(),
478
					getHandlingPolicy(),
473
					getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0),
479
					compilerOptions,
474
					getRequestor(),
480
					getRequestor(),
475
					problemFactory,
481
					problemFactory,
476
					monitor);
482
					monitor);
477
478
			resolver.resolve(compilationUnits, bindingKeys, requestor, apiLevel, options, owner, flags);
483
			resolver.resolve(compilationUnits, bindingKeys, requestor, apiLevel, options, owner, flags);
479
			if (NameLookup.VERBOSE) {
484
			if (NameLookup.VERBOSE) {
480
				System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
485
				System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
Lines 509-531 Link Here
509
		try {
514
		try {
510
			environment = new CancelableNameEnvironment(((JavaProject)javaProject), owner, monitor);
515
			environment = new CancelableNameEnvironment(((JavaProject)javaProject), owner, monitor);
511
			problemFactory = new CancelableProblemFactory(monitor);
516
			problemFactory = new CancelableProblemFactory(monitor);
517
			CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
518
			boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
519
			compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
512
			resolver =
520
			resolver =
513
				new CompilationUnitResolver(
521
				new CompilationUnitResolver(
514
					environment,
522
					environment,
515
					getHandlingPolicy(),
523
					getHandlingPolicy(),
516
					getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0),
524
					compilerOptions,
517
					getRequestor(),
525
					getRequestor(),
518
					problemFactory,
526
					problemFactory,
519
					monitor);
527
					monitor);
520
528
			boolean analyzeCode = true;
529
			boolean generateCode = true;
530
			if (ignoreMethodBodies) {
531
				analyzeCode = false;
532
				generateCode = false;
533
			}
521
			unit =
534
			unit =
522
				resolver.resolve(
535
				resolver.resolve(
523
					null, // no existing compilation unit declaration
536
					null, // no existing compilation unit declaration
524
					sourceUnit,
537
					sourceUnit,
525
					nodeSearcher,
538
					nodeSearcher,
526
					true, // method verification
539
					true, // method verification
527
					true, // analyze code
540
					analyzeCode, // analyze code
528
					true); // generate code
541
					generateCode); // generate code
529
			if (resolver.hasCompilationAborted) {
542
			if (resolver.hasCompilationAborted) {
530
				// the bindings could not be resolved due to missing types in name environment
543
				// the bindings could not be resolved due to missing types in name environment
531
				// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
544
				// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
(-)model/org/eclipse/jdt/core/ICompilationUnit.java (+8 lines)
Lines 63-68 Link Here
63
public static final int ENABLE_BINDINGS_RECOVERY = 0x04;
63
public static final int ENABLE_BINDINGS_RECOVERY = 0x04;
64
64
65
/**
65
/**
66
 * Constant indicating that a reconcile operation could ignore to parse the method bodies.
67
 * @see ASTParser#ignoreMethodBodies()
68
 * @since 3.6
69
 */
70
public static final int IGNORE_METHOD_BODIES = 0x08;
71
72
73
/**
66
 * Applies a text edit to the compilation unit's buffer.
74
 * Applies a text edit to the compilation unit's buffer.
67
 * <p>
75
 * <p>
68
 * Note that the edit is simply applied to the compilation unit's buffer.
76
 * Note that the edit is simply applied to the compilation unit's buffer.
(-)model/org/eclipse/jdt/core/compiler/ReconcileContext.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 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 94-99 Link Here
94
		parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
94
		parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
95
		parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
95
		parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
96
		parser.setSource(this.workingCopy);
96
		parser.setSource(this.workingCopy);
97
		if ((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0)
98
			parser.ignoreMethodBodies();
97
		return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
99
		return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
98
	}
100
	}
99
	return this.operation.makeConsistent(this.workingCopy);
101
	return this.operation.makeConsistent(this.workingCopy);
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-1 / +3 lines)
Lines 145-154 Link Here
145
		// disable task tags checking to speed up parsing
145
		// disable task tags checking to speed up parsing
146
		options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
146
		options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
147
	}
147
	}
148
	CompilerOptions compilerOptions = new CompilerOptions(options);
149
	compilerOptions.ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
148
	SourceElementParser parser = new SourceElementParser(
150
	SourceElementParser parser = new SourceElementParser(
149
		requestor,
151
		requestor,
150
		problemFactory,
152
		problemFactory,
151
		new CompilerOptions(options),
153
		compilerOptions,
152
		true/*report local declarations*/,
154
		true/*report local declarations*/,
153
		!createAST /*optimize string literals only if not creating a DOM AST*/);
155
		!createAST /*optimize string literals only if not creating a DOM AST*/);
154
	parser.reportOnlyOneSyntaxError = !computeProblems;
156
	parser.reportOnlyOneSyntaxError = !computeProblems;
(-)model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java (-6 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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 157-168 Link Here
157
		try {
157
		try {
158
			environment = new CancelableNameEnvironment(project, workingCopyOwner, monitor);
158
			environment = new CancelableNameEnvironment(project, workingCopyOwner, monitor);
159
			problemFactory = new CancelableProblemFactory(monitor);
159
			problemFactory = new CancelableProblemFactory(monitor);
160
			CompilerOptions compilerOptions = getCompilerOptions(project.getOptions(true), creatingAST, ((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0));
161
			boolean ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
162
			compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
160
			problemFinder = new CompilationUnitProblemFinder(
163
			problemFinder = new CompilationUnitProblemFinder(
161
				environment,
164
				environment,
162
				getHandlingPolicy(),
165
				getHandlingPolicy(),
163
				getCompilerOptions(project.getOptions(true), creatingAST, ((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0)),
166
				compilerOptions,
164
				getRequestor(),
167
				getRequestor(),
165
				problemFactory);
168
				problemFactory);
169
			boolean analyzeCode = true;
170
			boolean generateCode = true;
171
			if (ignoreMethodBodies) {
172
				analyzeCode = false;
173
				generateCode = false;
174
			}
166
			CompilationUnitDeclaration unit = null;
175
			CompilationUnitDeclaration unit = null;
167
			if (parser != null) {
176
			if (parser != null) {
168
				problemFinder.parser = parser;
177
				problemFinder.parser = parser;
Lines 172-179 Link Here
172
						unit,
181
						unit,
173
						unitElement,
182
						unitElement,
174
						true, // verify methods
183
						true, // verify methods
175
						true, // analyze code
184
						analyzeCode, // analyze code
176
						true); // generate code
185
						generateCode); // generate code
177
				} catch (AbortCompilation e) {
186
				} catch (AbortCompilation e) {
178
					problemFinder.handleInternalException(e, unit);
187
					problemFinder.handleInternalException(e, unit);
179
				}
188
				}
Lines 182-189 Link Here
182
					problemFinder.resolve(
191
					problemFinder.resolve(
183
						unitElement,
192
						unitElement,
184
						true, // verify methods
193
						true, // verify methods
185
						true, // analyze code
194
						analyzeCode, // analyze code
186
						true); // generate code
195
						generateCode); // generate code
187
			}
196
			}
188
			CompilationResult unitResult = unit.compilationResult;
197
			CompilationResult unitResult = unit.compilationResult;
189
			CategorizedProblem[] unitProblems = unitResult.getProblems();
198
			CategorizedProblem[] unitProblems = unitResult.getProblems();
(-)model/org/eclipse/jdt/internal/core/util/CodeSnippetParsingUtil.java (+13 lines)
Lines 32-37 Link Here
32
public class CodeSnippetParsingUtil {
32
public class CodeSnippetParsingUtil {
33
33
34
	public RecordedParsingInformation recordedParsingInformation;
34
	public RecordedParsingInformation recordedParsingInformation;
35
	public boolean ignoreMethodBodies;
36
	
37
	public CodeSnippetParsingUtil(boolean ignoreMethodBodies) {
38
		this.ignoreMethodBodies = ignoreMethodBodies;
39
	}
40
41
	public CodeSnippetParsingUtil() {
42
		this(false);
43
	}
35
44
36
	private RecordedParsingInformation getRecordedParsingInformation(CompilationResult compilationResult, int[][] commentPositions) {
45
	private RecordedParsingInformation getRecordedParsingInformation(CompilationResult compilationResult, int[][] commentPositions) {
37
		int problemsCount = compilationResult.problemCount;
46
		int problemsCount = compilationResult.problemCount;
Lines 62-67 Link Here
62
			throw new IllegalArgumentException();
71
			throw new IllegalArgumentException();
63
		}
72
		}
64
		CompilerOptions compilerOptions = new CompilerOptions(settings);
73
		CompilerOptions compilerOptions = new CompilerOptions(settings);
74
		compilerOptions.ignoreMethodBodies = this.ignoreMethodBodies;
65
		final ProblemReporter problemReporter = new ProblemReporter(
75
		final ProblemReporter problemReporter = new ProblemReporter(
66
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
76
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
67
					compilerOptions,
77
					compilerOptions,
Lines 92-97 Link Here
92
			throw new IllegalArgumentException();
102
			throw new IllegalArgumentException();
93
		}
103
		}
94
		CompilerOptions compilerOptions = new CompilerOptions(settings);
104
		CompilerOptions compilerOptions = new CompilerOptions(settings);
105
		compilerOptions.ignoreMethodBodies = this.ignoreMethodBodies;
95
		CommentRecorderParser parser =
106
		CommentRecorderParser parser =
96
			new CommentRecorderParser(
107
			new CommentRecorderParser(
97
				new ProblemReporter(
108
				new ProblemReporter(
Lines 144-149 Link Here
144
			throw new IllegalArgumentException();
155
			throw new IllegalArgumentException();
145
		}
156
		}
146
		CompilerOptions compilerOptions = new CompilerOptions(settings);
157
		CompilerOptions compilerOptions = new CompilerOptions(settings);
158
		// don't set ignoreMethodBodies
147
		final ProblemReporter problemReporter = new ProblemReporter(
159
		final ProblemReporter problemReporter = new ProblemReporter(
148
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
160
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
149
					compilerOptions,
161
					compilerOptions,
Lines 182-187 Link Here
182
			throw new IllegalArgumentException();
194
			throw new IllegalArgumentException();
183
		}
195
		}
184
		CompilerOptions compilerOptions = new CompilerOptions(settings);
196
		CompilerOptions compilerOptions = new CompilerOptions(settings);
197
		// don't set ignoreMethodBodies
185
		final ProblemReporter problemReporter = new ProblemReporter(
198
		final ProblemReporter problemReporter = new ProblemReporter(
186
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
199
					DefaultErrorHandlingPolicies.proceedWithAllProblems(),
187
					compilerOptions,
200
					compilerOptions,
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (+71 lines)
Lines 10425-10428 Link Here
10425
		CompilationUnit unit = (CompilationUnit) root;
10425
		CompilationUnit unit = (CompilationUnit) root;
10426
		assertTrue("No problem reported", unit.getProblems().length != 0);
10426
		assertTrue("No problem reported", unit.getProblems().length != 0);
10427
	}
10427
	}
10428
	/**
10429
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=288211
10430
	 */
10431
	public void test0715() throws JavaModelException {
10432
		final char[] source = ("System.out.println()\nint i;\n").toCharArray();
10433
		ASTParser parser = ASTParser.newParser(AST.JLS3);
10434
		parser.setKind(ASTParser.K_STATEMENTS);
10435
		parser.setStatementsRecovery(true);
10436
		parser.ignoreMethodBodies();
10437
		parser.setSource(source);
10438
		ASTNode root = parser.createAST(null);
10439
		assertEquals("Not a block", ASTNode.BLOCK, root.getNodeType());
10440
		Block block = (Block) root;
10441
		List statements = block.statements();
10442
		assertEquals("Wrong size", 2, statements.size());
10443
	}
10444
	/**
10445
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=288211
10446
	 */
10447
	public void test0716() {
10448
		String src = "switch (state) {case 4:double M0,M1;}";
10449
		char[] source = src.toCharArray();
10450
		ASTParser parser = ASTParser.newParser(AST.JLS3);
10451
		parser.setKind (ASTParser.K_STATEMENTS);
10452
		parser.ignoreMethodBodies();
10453
		parser.setSource (source);
10454
		ASTNode result = parser.createAST (null);
10455
		assertNotNull("no result", result);
10456
		assertEquals("Wrong type", ASTNode.BLOCK, result.getNodeType());
10457
		Block block = (Block) result;
10458
		List statements = block.statements();
10459
		assertNotNull("No statements", statements);
10460
		assertEquals("Wrong size", 1, statements.size());
10461
		final ASTNode node = (ASTNode) statements.get(0);
10462
		assertEquals("Not a switch statement", ASTNode.SWITCH_STATEMENT, node.getNodeType());
10463
		SwitchStatement statement = (SwitchStatement) node;
10464
		statements = statement.statements();
10465
		assertEquals("wrong size", 2, statements.size());
10466
		assertEquals("Not a switch case", ASTNode.SWITCH_CASE, ((ASTNode) statements.get(0)).getNodeType());
10467
		assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, ((ASTNode) statements.get(1)).getNodeType());
10468
	}
10469
	/**
10470
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=288211
10471
	 */
10472
	public void test0717() throws JavaModelException {
10473
		final char[] source = ("  class MyCommand extends CompoundCommand\n" + 
10474
				"  {\n" + 
10475
				"    public void execute()\n" + 
10476
				"    {\n" + 
10477
				"      // ...\n" + 
10478
				"      appendAndExecute(new AddCommand());\n" + 
10479
				"      if (condition) appendAndExecute(new AddCommand());\n" + 
10480
				"    }\n" + 
10481
				"  }").toCharArray();
10482
		ASTParser parser = ASTParser.newParser(AST.JLS3);
10483
		parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
10484
		parser.setStatementsRecovery(false);
10485
		parser.ignoreMethodBodies();
10486
		parser.setSource(source);
10487
		ASTNode root = parser.createAST(null);
10488
		assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
10489
		TypeDeclaration typeDeclaration = (TypeDeclaration) root;
10490
		typeDeclaration.accept(new ASTVisitor() {
10491
			public boolean visit(MethodDeclaration node) {
10492
				Block body = node.getBody();
10493
				assertNotNull(body);
10494
				assertTrue(body.statements().size() == 0);
10495
				return true;
10496
			}
10497
		});
10498
	}
10428
}
10499
}
(-)src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java (+75 lines)
Lines 2208-2211 Link Here
2208
			},
2208
			},
2209
			"LA~B<LC;:1TV;LC;:1TE;>;");
2209
			"LA~B<LC;:1TV;LC;:1TE;>;");
2210
	}
2210
	}
2211
	
2212
	public void testIgnoreMethodBodies1() throws CoreException {
2213
		this.workingCopies = createWorkingCopies(new String[] {
2214
				"/P/p1/X.java",
2215
				"package p1;\n" +
2216
				"public class X {\n" +
2217
				"  public int foo() {\n" +
2218
				"    int i = 0;\n" + 
2219
				"  }\n" +
2220
				"  public int bar() {\n" +
2221
				"    int i = 0;\n" + 
2222
				"    new X() /*start*/{\n" +
2223
				"    }/*end*/;" +
2224
				"  }\n" +
2225
				"}",
2226
			});
2227
			TestASTRequestor requestor = new TestASTRequestor();
2228
			ASTParser parser = ASTParser.newParser(AST.JLS3);
2229
			parser.ignoreMethodBodies();
2230
			parser.createASTs(this.workingCopies, new String[] {}, requestor, null);
2231
			// statement declaring i should not be in the AST
2232
			assertASTNodesEqual(
2233
					"package p1;\n" +
2234
					"public class X {\n" +
2235
					"  public int foo(){\n" +
2236
					"  }\n" +
2237
					"  public int bar(){\n" +
2238
					"    int i=0;\n" + 
2239
					"    new X(){\n" +
2240
					"    }\n" +
2241
					";\n" +
2242
					"  }\n" +
2243
					"}\n" +
2244
					"\n",
2245
					requestor.asts
2246
				);
2247
	}
2248
	public void testIgnoreMethodBodies2() throws CoreException {
2249
		this.workingCopies = createWorkingCopies(new String[] {
2250
				"/P/p1/X.java",
2251
				"package p1;\n" +
2252
				"public class X {\n" +
2253
				"  public int foo() {\n" +
2254
				"    int i = 0;\n" + 
2255
				"  }\n" +
2256
				"  public int bar() {\n" +
2257
				"    int i = 0;\n" + 
2258
				"    new X() /*start*/{\n" +
2259
				"    }/*end*/;" +
2260
				"  }\n" +
2261
				"}",
2262
			});
2263
			TestASTRequestor requestor = new TestASTRequestor();
2264
			ASTParser parser = ASTParser.newParser(AST.JLS3);
2265
			parser.ignoreMethodBodies();
2266
			parser.setResolveBindings(true);
2267
			parser.setProject(getJavaProject("P"));
2268
			parser.createASTs(this.workingCopies, new String[] {}, requestor, null);
2269
			// statement declaring i should not be in the AST
2270
			assertASTNodesEqual(
2271
					"package p1;\n" +
2272
					"public class X {\n" +
2273
					"  public int foo(){\n" +
2274
					"  }\n" +
2275
					"  public int bar(){\n" +
2276
					"    int i=0;\n" + 
2277
					"    new X(){\n" +
2278
					"    }\n" +
2279
					";\n" +
2280
					"  }\n" +
2281
					"}\n" +
2282
					"\n",
2283
					requestor.asts
2284
				);
2285
	}
2211
}
2286
}
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (-1 / +68 lines)
Lines 97-103 Link Here
97
//	JavaModelManager.VERBOSE = true;
97
//	JavaModelManager.VERBOSE = true;
98
//	org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
98
//	org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
99
//	TESTS_PREFIX = "testIgnoreIfBetterNonAccessibleRule";
99
//	TESTS_PREFIX = "testIgnoreIfBetterNonAccessibleRule";
100
//	TESTS_NAMES = new String[] { "testRawUsage" };
100
//	TESTS_NAMES = new String[] { "testIgnoreMethodBodies1", "testIgnoreMethodBodies2" };
101
//	TESTS_NUMBERS = new int[] { 118823 };
101
//	TESTS_NUMBERS = new int[] { 118823 };
102
//	TESTS_RANGE = new int[] { 16, -1 };
102
//	TESTS_RANGE = new int[] { 16, -1 };
103
}
103
}
Lines 4323-4326 Link Here
4323
		deleteProject("P1");
4323
		deleteProject("P1");
4324
	}
4324
	}
4325
}
4325
}
4326
/*
4327
 * Ensure that the option ICompilationUnit.IGNORE_METHOD_BODIES is honored
4328
 */
4329
public void testIgnoreMethodBodies1() throws CoreException {	
4330
	setWorkingCopyContents(
4331
		"package p1;\n" +
4332
		"import p2.*;" +
4333
		"public class X {\n" +
4334
		"  public int foo() {\n" + // force an error by not returning
4335
		"    int i = 0;\n" + 
4336
		"  }\n" +
4337
		"}");
4338
	org.eclipse.jdt.core.dom.CompilationUnit ast = this.workingCopy.reconcile(AST.JLS3, ICompilationUnit.IGNORE_METHOD_BODIES, null, null);
4339
	// X.foo() not returning any value should not be reported
4340
	assertProblems("Working copy should have problems:",
4341
			"----------\n" +
4342
			"1. WARNING in /Reconciler/src/p1/X.java (at line 2)\n"+
4343
			"	import p2.*;public class X {\n" +
4344
			"	       ^^\n" +
4345
			"The import p2 is never used\n"+
4346
			"----------\n"
4347
		);
4348
	// statement declaring i should not be in the AST
4349
	assertASTNodeEquals(
4350
			"Unexpected participant ast",
4351
			"package p1;\n" +
4352
			"import p2.*;\n" +
4353
			"public class X {\n" +
4354
			"  public int foo(){\n" +
4355
			"  }\n" +
4356
			"}\n",
4357
			ast
4358
		);
4359
}
4360
public void testIgnoreMethodBodies2() throws CoreException {	
4361
	setWorkingCopyContents(
4362
		"package p1;\n" +
4363
		"import p2.*;" +
4364
		"public class X {\n" +
4365
		"  public void foo() {\n" +
4366
		"    int i = 0;\n" + 
4367
		"  }\n" +
4368
		"  public int bar() {\n" +
4369
		"    int i = 0;\n" + 
4370
		"    new X() /*start*/{\n" +
4371
		"    }/*end*/;" +
4372
		"  }\n" +
4373
		"}");
4374
	org.eclipse.jdt.core.dom.CompilationUnit ast = this.workingCopy.reconcile(AST.JLS3, ICompilationUnit.IGNORE_METHOD_BODIES, null, null);
4375
	// methods with anonymous classes should have their statements intact
4376
	assertASTNodeEquals(
4377
			"Unexpected ast",
4378
			"package p1;\n" +
4379
			"import p2.*;\n" +
4380
			"public class X {\n" +
4381
			"  public void foo(){\n" +
4382
			"  }\n" +
4383
			"  public int bar(){\n" +
4384
			"    int i=0;\n" + 
4385
			"    new X(){\n" +
4386
			"    }\n" +
4387
			";\n" +
4388
			"  }\n" +
4389
			"}\n",
4390
			ast
4391
		);
4392
}
4326
}
4393
}

Return to bug 288211