Java Code Examples for org.eclipse.jdt.core.ICompilationUnit#ENABLE_BINDINGS_RECOVERY

The following examples show how to use org.eclipse.jdt.core.ICompilationUnit#ENABLE_BINDINGS_RECOVERY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaReconcilingStrategy.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Performs the reconcile and returns the AST if it was computed.
 *
 * @param unit the compilation unit
 * @param initialReconcile <code>true</code> if this is the initial reconcile
 * @return the AST or <code>null</code> if none
 * @throws JavaModelException if the original Java element does not exist
 * @since 3.4
 */
private CompilationUnit reconcile(ICompilationUnit unit, boolean initialReconcile) throws JavaModelException {
	/* fix for missing cancel flag communication */
	IProblemRequestorExtension extension= getProblemRequestorExtension();
	if (extension != null) {
		extension.setProgressMonitor(fProgressMonitor);
		extension.setIsActive(true);
	}

	try {
		boolean isASTNeeded= initialReconcile || JavaPlugin.getDefault().getASTProvider().isActive(unit);
		// reconcile
		if (fIsJavaReconcilingListener && isASTNeeded) {
			int reconcileFlags= ICompilationUnit.FORCE_PROBLEM_DETECTION;
			if (ASTProvider.SHARED_AST_STATEMENT_RECOVERY)
				reconcileFlags|= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
			if (ASTProvider.SHARED_BINDING_RECOVERY)
				reconcileFlags|= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;

			CompilationUnit ast= unit.reconcile(ASTProvider.SHARED_AST_LEVEL, reconcileFlags, null, fProgressMonitor);
			if (ast != null) {
				// mark as unmodifiable
				ASTNodes.setFlagsToAST(ast, ASTNode.PROTECT);
				return ast;
			}
		} else
			unit.reconcile(ICompilationUnit.NO_AST, true, null, fProgressMonitor);
	} catch (OperationCanceledException ex) {
		Assert.isTrue(fProgressMonitor == null || fProgressMonitor.isCanceled());
	} finally {
		/* fix for missing cancel flag communication */
		if (extension != null) {
			extension.setProgressMonitor(null);
			extension.setIsActive(false);
		}
	}

	return null;
}
 
Example 2
Source File: CompilationUnitResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static CompilationUnit convert(
		CompilationUnitDeclaration compilationUnitDeclaration,
		char[] source,
		int apiLevel,
		Map options,
		boolean needToResolveBindings,
		WorkingCopyOwner owner,
		DefaultBindingResolver.BindingTables bindingTables,
		int flags,
		IProgressMonitor monitor,
		boolean fromJavaProject) {
	BindingResolver resolver = null;
	AST ast = AST.newAST(apiLevel);
	ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
	CompilationUnit compilationUnit = null;
	ASTConverter converter = new ASTConverter(options, needToResolveBindings, monitor);
	if (needToResolveBindings) {
		resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, owner, bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, fromJavaProject);
		ast.setFlag(flags | AST.RESOLVED_BINDINGS);
	} else {
		resolver = new BindingResolver();
		ast.setFlag(flags);
	}
	ast.setBindingResolver(resolver);
	converter.setAST(ast);
	compilationUnit = converter.convert(compilationUnitDeclaration, source);
	compilationUnit.setLineEndTable(compilationUnitDeclaration.compilationResult.getLineSeparatorPositions());
	ast.setDefaultNodeFlag(0);
	ast.setOriginalModificationCount(ast.modificationCount());
	return compilationUnit;
}
 
Example 3
Source File: ASTParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates ASTs for a batch of compilation units.
 * <p>When bindings are being resolved, processing a
 * batch of compilation units is more efficient because much
 * of the work involved in resolving bindings can be shared.</p>
 * <p>
 * When bindings are being resolved, all compilation units must
 * come from the same Java project, which must be set beforehand
 * with {@link #setProject(IJavaProject) setProject}.</p>
 * <p>The compilation units are processed one at a time in no
 * specified order. For each of the compilation units in turn,</p>
 * <ul>
 * <li>{@link #createAST(IProgressMonitor) ASTParser.createAST} is called to parse it
 * and create a corresponding AST. The calls to
 * {@link #createAST(IProgressMonitor) ASTParser.createAST} all employ the same settings.</li>
 * <li>{@link ASTRequestor#acceptAST(ICompilationUnit, CompilationUnit) ASTRequestor.acceptAST}
 * is called passing the compilation unit and the corresponding AST to <code>requestor</code>.
 * </li>
 * </ul>
 * Note only ASTs from the given compilation units are reported
 * to the requestor. If additional compilation units are required to
 * resolve the original ones, the corresponding ASTs are <b>not</b>
 * reported to the requestor.
 * </p>
 * <p>
 * Note also the following parser parameters are used, regardless of what
 * may have been specified:
 * <ul>
 * <li>The {@linkplain #setKind(int) parser kind} is <code>K_COMPILATION_UNIT</code></li>
 * <li>The {@linkplain #setSourceRange(int,int) source range} is <code>(0, -1)</code></li>
 * <li>The {@linkplain #setFocalPosition(int) focal position} is not set</li>
 * </ul>
 * </p>
 * <p>
 * The <code>bindingKeys</code> parameter specifies bindings keys
 * ({@link IBinding#getKey()}) that are to be looked up. These keys may
 * be for elements either inside or outside the set of compilation
 * units being processed. When bindings are being resolved,
 * the keys and corresponding bindings (or <code>null</code> if none) are
 * passed to {@link ASTRequestor#acceptBinding(String, IBinding) ASTRequestor.acceptBinding}.
 * Note that binding keys for elements outside the set of compilation units being processed
 * are looked up after all {@link ASTRequestor#acceptAST(ICompilationUnit, CompilationUnit) ASTRequestor.acceptAST}
 * callbacks have been made.
 * Binding keys for elements inside the set of compilation units being processed
 * are looked up and reported right after the corresponding
 * {@link ASTRequestor#acceptAST(ICompilationUnit, CompilationUnit) ASTRequestor.acceptAST} callback has been made.
 * No {@link ASTRequestor#acceptBinding(String, IBinding) ASTRequestor.acceptBinding} callbacks are made unless
 * bindings are being resolved.
 * </p>
 * <p>
 * A successful call to this method returns all settings to their
 * default values so the object is ready to be reused.
 * </p>
 *
 * @param compilationUnits the compilation units to create ASTs for
 * @param bindingKeys the binding keys to create bindings for
 * @param requestor the AST requestor that collects abstract syntax trees and bindings
 * @param monitor the progress monitor used to report progress and request cancellation,
 *   or <code>null</code> if none
 * @exception IllegalStateException if the settings provided
 * are insufficient, contradictory, or otherwise unsupported
 * @since 3.1
 */
public void createASTs(ICompilationUnit[] compilationUnits, String[] bindingKeys, ASTRequestor requestor, IProgressMonitor monitor) {
	try {
		int flags = 0;
		if ((this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0) {
			flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
		}
		if ((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0) {
			flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
		}
		if ((this.bits & CompilationUnitResolver.RESOLVE_BINDING) != 0) {
			if (this.project == null)
				throw new IllegalStateException("project not specified"); //$NON-NLS-1$
			if ((this.bits & CompilationUnitResolver.BINDING_RECOVERY) != 0) {
				flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
			}
			CompilationUnitResolver.resolve(compilationUnits, bindingKeys, requestor, this.apiLevel, this.compilerOptions, this.project, this.workingCopyOwner, flags, monitor);
		} else {
			CompilationUnitResolver.parse(compilationUnits, requestor, this.apiLevel, this.compilerOptions, flags, monitor);
		}
	} finally {
		// reset to defaults to allow reuse (and avoid leaking)
		initializeDefaults();
	}
}
 
Example 4
Source File: ASTParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates bindings for a batch of Java elements.
 * 
 * <p>These elements are either
 * enclosed in {@link ICompilationUnit ICompilationUnits} or in {@link IClassFile IClassFiles}.</p>
 * <p>
 * All enclosing compilation units and class files must
 * come from the same Java project, which must be set beforehand
 * with {@link #setProject(IJavaProject) setProject}.
 * </p>
 * <p>
 * All elements must exist. If one doesn't exist, an {@link IllegalStateException}
 * is thrown.
 * </p>
 * <p>
 * The returned array has the same size as the given elements array. At a given position
 * it contains the binding of the corresponding Java element, or <code>null</code>
 * if no binding could be created.
 * </p>
 * <p>
 * Note also the following parser parameters are used, regardless of what
 * may have been specified:
 * <ul>
 * <li>The {@linkplain #setResolveBindings(boolean) binding resolution flag} is <code>true</code></li>
 * <li>The {@linkplain #setKind(int) parser kind} is <code>K_COMPILATION_UNIT</code></li>
 * <li>The {@linkplain #setSourceRange(int,int) source range} is <code>(0, -1)</code></li>
 * <li>The {@linkplain #setFocalPosition(int) focal position} is not set</li>
 * </ul>
 * </p>
 * <p>
 * A successful call to this method returns all settings to their
 * default values so the object is ready to be reused.
 * </p>
 *
 * @param elements the Java elements to create bindings for
 * @return the bindings for the given Java elements, possibly containing <code>null</code>s
 *              if some bindings could not be created
 * @exception IllegalStateException if the settings provided
 * are insufficient, contradictory, or otherwise unsupported
 * @since 3.1
 */
public IBinding[] createBindings(IJavaElement[] elements, IProgressMonitor monitor) {
	try {
		if (this.project == null)
			throw new IllegalStateException("project or classpath not specified"); //$NON-NLS-1$
		int flags = 0;
		if ((this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0) {
			flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
		}
		if ((this.bits & CompilationUnitResolver.BINDING_RECOVERY) != 0) {
			flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
		}
		if ((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0) {
			flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
		}
		return CompilationUnitResolver.resolve(elements, this.apiLevel, this.compilerOptions, this.project, this.workingCopyOwner, flags, monitor);
	} finally {
		// reset to defaults to allow reuse (and avoid leaking)
		initializeDefaults();
	}
}
 
Example 5
Source File: ASTParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates ASTs for a batch of compilation units.
 * When bindings are being resolved, processing a
 * batch of compilation units is more efficient because much
 * of the work involved in resolving bindings can be shared.
 * <p>
 * When bindings are being resolved, all compilation units are resolved using
 * the same environment, which must be set beforehand
 * with {@link #setEnvironment(String[], String[], String[], boolean) setEnvironment}.
 * The compilation units are processed one at a time in no
 * specified order. For each of the compilation units in turn,
 * <ul>
 * <li>{@link ASTParser#createAST(IProgressMonitor) ASTParser.createAST} is called to parse it
 * and create a corresponding AST. The calls to
 * {@link ASTParser#createAST(IProgressMonitor) ASTParser.createAST} all employ the same settings.</li>
 * <li>{@link FileASTRequestor#acceptAST(String, CompilationUnit) FileASTRequestor.acceptAST} is called passing
 * the compilation unit path and the corresponding AST to <code>requestor</code>. The compilation unit path is the same
 * path that is passed into the given <code>sourceFilePaths</code> parameter.
 * </li>
 * </ul>
 * Note only ASTs from the given compilation units are reported
 * to the requestor. If additional compilation units are required to
 * resolve the original ones, the corresponding ASTs are <b>not</b>
 * reported to the requestor.
 * </p>
 * <p>
 * Note also the following parser parameters are used, regardless of what
 * may have been specified:
 * <ul>
 * <li>The {@linkplain #setKind(int) parser kind} is <code>K_COMPILATION_UNIT</code></li>
 * <li>The {@linkplain #setSourceRange(int,int) source range} is <code>(0, -1)</code></li>
 * <li>The {@linkplain #setFocalPosition(int) focal position} is not set</li>
 * </ul>
 * </p>
 * <p>
 * The <code>bindingKeys</code> parameter specifies bindings keys
 * ({@link IBinding#getKey()}) that are to be looked up. These keys may
 * be for elements either inside or outside the set of compilation
 * units being processed. When bindings are being resolved,
 * the keys and corresponding bindings (or <code>null</code> if none) are
 * passed to {@link FileASTRequestor#acceptBinding(String, IBinding) FileASTRequestor.acceptBinding}. Note that binding keys
 * for elements outside the set of compilation units being processed are looked up
 * after all {@link FileASTRequestor#acceptAST(String, CompilationUnit) ASTRequestor.acceptAST}
 * callbacks have been made.
 * Binding keys for elements inside the set of compilation units being processed
 * are looked up and reported right after the corresponding
 * {@link FileASTRequestor#acceptAST(String, CompilationUnit) FileASTRequestor.acceptAST} callback has been made.
 * No {@link FileASTRequestor#acceptBinding(String, IBinding) FileASTRequestor.acceptBinding} callbacks are made unless
 * bindings are being resolved.
 * </p>
 * <p>
 * A successful call to this method returns all settings to their
 * default values so the object is ready to be reused.
 * </p>
 * <p>The given <code>encodings</code> are used to properly parse the given source units. If the platform encoding is sufficient,
 * then the given encodings can be set to <code>null</code>.</p>
 *
 * @param sourceFilePaths the compilation units to create ASTs for
 * @param encodings the given encoding for the source units
 * @param bindingKeys the binding keys to create bindings for
 * @param requestor the AST requestor that collects abstract syntax trees and bindings
 * @param monitor the progress monitor used to report progress and request cancellation,
 *   or <code>null</code> if none
 * @exception IllegalStateException if the settings provided
 * are insufficient, contradictory, or otherwise unsupported
 * @since 3.6
 */
public void createASTs(String[] sourceFilePaths, String[] encodings, String[] bindingKeys,
		FileASTRequestor requestor, IProgressMonitor monitor) {
	try {
		int flags = 0;
		if ((this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0) {
			flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
		}
		if ((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0) {
			flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
		}
		if ((this.bits & CompilationUnitResolver.RESOLVE_BINDING) != 0) {
			if (this.classpaths == null && this.sourcepaths == null && ((this.bits & CompilationUnitResolver.INCLUDE_RUNNING_VM_BOOTCLASSPATH) == 0)) {
				throw new IllegalStateException("no environment is specified"); //$NON-NLS-1$
			}
			if ((this.bits & CompilationUnitResolver.BINDING_RECOVERY) != 0) {
				flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
			}
			CompilationUnitResolver.resolve(sourceFilePaths, encodings, bindingKeys, requestor, this.apiLevel, this.compilerOptions, getClasspath(), flags, monitor);
		} else {
			CompilationUnitResolver.parse(sourceFilePaths, encodings, requestor, this.apiLevel, this.compilerOptions, flags, monitor);
		}
	} finally {
		// reset to defaults to allow reuse (and avoid leaking)
		initializeDefaults();
	}
}
 
Example 6
Source File: AST.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns true if the ast tree was created with bindings recovery, false otherwise
 *
 * @return true if the ast tree was created with bindings recovery, false otherwise
 * @since 3.3
 */
public boolean hasBindingsRecovery() {
	return (this.bits & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0;
}