Java Code Examples for org.eclipse.jdt.core.dom.ASTParser#setIgnoreMethodBodies()
The following examples show how to use
org.eclipse.jdt.core.dom.ASTParser#setIgnoreMethodBodies() .
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: JdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private boolean isParameterNamesAvailable() throws Exception { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setIgnoreMethodBodies(true); IJavaProject javaProject = projectProvider.getJavaProject(resourceSet); parser.setProject(javaProject); IType type = javaProject.findType("org.eclipse.xtext.common.types.testSetups.TestEnum"); IBinding[] bindings = parser.createBindings(new IJavaElement[] { type }, null); ITypeBinding typeBinding = (ITypeBinding) bindings[0]; IMethodBinding[] methods = typeBinding.getDeclaredMethods(); for(IMethodBinding method: methods) { if (method.isConstructor()) { IMethod element = (IMethod) method.getJavaElement(); if (element.exists()) { String[] parameterNames = element.getParameterNames(); if (parameterNames.length == 1 && parameterNames[0].equals("string")) { return true; } } else { return false; } } } return false; }
Example 2
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static String getPackageName(IJavaProject javaProject, String fileContent) { if (fileContent == null) { return ""; } //TODO probably not the most efficient way to get the package name as this reads the whole file; char[] source = fileContent.toCharArray(); ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); parser.setProject(javaProject); parser.setIgnoreMethodBodies(true); parser.setSource(source); CompilationUnit ast = (CompilationUnit) parser.createAST(null); PackageDeclaration pkg = ast.getPackage(); return (pkg == null || pkg.getName() == null)?"":pkg.getName().getFullyQualifiedName(); }
Example 3
Source File: ReconcileContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resolved AST with {@link AST#JLS3 JLS3} level. * It is created from the current state of the working copy. * Creates one if none exists yet. * Returns <code>null</code> if the current state of the working copy * doesn't allow the AST to be created (e.g. if the working copy's content * cannot be parsed). * <p> * If the AST level requested during reconciling is not {@link AST#JLS3} * or if binding resolutions was not requested, then a different AST is created. * Note that this AST does not become the current AST and it is only valid for * the requestor. * </p> * * @return the AST created from the current state of the working copy, * or <code>null</code> if none could be created * @exception JavaModelException if the contents of the working copy * cannot be accessed. Reasons include: * <ul> * <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li> * </ul> * @deprecated JLS3 has been deprecated. This method has been replaced by {@link #getAST4()} which returns an AST * with JLS4 level. */ public org.eclipse.jdt.core.dom.CompilationUnit getAST3() throws JavaModelException { if (this.operation.astLevel != AST.JLS3 || !this.operation.resolveBindings) { // create AST (optionally resolving bindings) ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true)); if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject())) parser.setResolveBindings(true); parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); parser.setSource(this.workingCopy); parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0); return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor); } return this.operation.makeConsistent(this.workingCopy); }
Example 4
Source File: ReconcileContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resolved AST with {@link AST#JLS4 JLS4} level. * It is created from the current state of the working copy. * Creates one if none exists yet. * Returns <code>null</code> if the current state of the working copy * doesn't allow the AST to be created (e.g. if the working copy's content * cannot be parsed). * <p> * If the AST level requested during reconciling is not {@link AST#JLS4} * or if binding resolutions was not requested, then a different AST is created. * Note that this AST does not become the current AST and it is only valid for * the requestor. * </p> * * @return the AST created from the current state of the working copy, * or <code>null</code> if none could be created * @exception JavaModelException if the contents of the working copy * cannot be accessed. Reasons include: * <ul> * <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li> * </ul> * @deprecated JLS4 has been deprecated. This method has been replaced by {@link #getAST8()} which returns an AST * with JLS8 level. * @since 3.7.1 */ public org.eclipse.jdt.core.dom.CompilationUnit getAST4() throws JavaModelException { if (this.operation.astLevel != AST.JLS4 || !this.operation.resolveBindings) { // create AST (optionally resolving bindings) ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true)); if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject())) parser.setResolveBindings(true); parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); parser.setSource(this.workingCopy); parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0); return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor); } return this.operation.makeConsistent(this.workingCopy); }
Example 5
Source File: ReconcileContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Returns a resolved AST with {@link AST#JLS8 JLS8} level. * It is created from the current state of the working copy. * Creates one if none exists yet. * Returns <code>null</code> if the current state of the working copy * doesn't allow the AST to be created (e.g. if the working copy's content * cannot be parsed). * <p> * If the AST level requested during reconciling is not {@link AST#JLS8} * or if binding resolutions was not requested, then a different AST is created. * Note that this AST does not become the current AST and it is only valid for * the requestor. * </p> * * @return the AST created from the current state of the working copy, * or <code>null</code> if none could be created * @exception JavaModelException if the contents of the working copy * cannot be accessed. Reasons include: * <ul> * <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li> * </ul> * @since 3.10 */ public org.eclipse.jdt.core.dom.CompilationUnit getAST8() throws JavaModelException { if (this.operation.astLevel != AST.JLS8 || !this.operation.resolveBindings) { // create AST (optionally resolving bindings) ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true)); if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject())) parser.setResolveBindings(true); parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); parser.setSource(this.workingCopy); parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0); return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor); } return this.operation.makeConsistent(this.workingCopy); }