本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTParser.setIgnoreMethodBodies方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTParser.setIgnoreMethodBodies方法的具體用法?Java ASTParser.setIgnoreMethodBodies怎麽用?Java ASTParser.setIgnoreMethodBodies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ASTParser
的用法示例。
在下文中一共展示了ASTParser.setIgnoreMethodBodies方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPackageName
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
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();
}
示例2: initParser
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static void initParser(ASTParser parser) {
Map<String, String> options = getCompilerOptions();
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
parser.setCompilerOptions(options);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
parser.setIgnoreMethodBodies(false);
}
示例3: execute
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
if (workbenchWindow == null)
return null;
IWorkbenchPage activePage = workbenchWindow.getActivePage();
if (activePage == null)
return null;
editor = HandlerUtil.getActiveEditor(event);
if (editor == null)
return null;
IJavaElement element = JavaUI.getEditorInputJavaElement(editor.getEditorInput());
final ICompilationUnit compilationUnit = element.getAdapter(ICompilationUnit.class);
final ITextEditor textEditor = editor.getAdapter(ITextEditor.class);
final int offset = ((ITextSelection)textEditor.getSelectionProvider().getSelection())
.getOffset();
final ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(compilationUnit);
parser.setResolveBindings(true);
parser.setIgnoreMethodBodies(true);
final CompilationUnit astUnit = (CompilationUnit)parser.createAST(null);
JavaElementRenameVisitor visitor = new JavaElementRenameVisitor(
compilationUnit.getJavaProject(), offset);
astUnit.accept(visitor);
if (visitor.getRefactoring() != null)
{
runRefactoringWizard(visitor.getRefactoringInfo(), visitor.getRefactoring());
}
return null;
}
示例4: create
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static I18NEnumVisitor create(ICompilationUnit compilationUnit) {
I18NEnumVisitor visitor = new I18NEnumVisitor();
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setIgnoreMethodBodies(true);
parser.setResolveBindings(true);
parser.setSource(compilationUnit);
ASTNode createdAST = parser.createAST(new NullProgressMonitor());
createdAST.accept(visitor);
return visitor;
}
示例5: getAST
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public CompilationUnit getAST( String source ) {
ASTParser parser = ASTParser.newParser(AST.JLS3);
@SuppressWarnings( "unchecked" )
Map<String,String> options = JavaCore.getOptions();
if(VERSION_1_5.equals(targetJdk))
JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
else if(VERSION_1_6.equals(targetJdk))
JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
else {
if(!VERSION_1_4.equals(targetJdk)) {
log.warn("Unknown targetJdk ["+targetJdk+"]. Using "+VERSION_1_4+" for parsing. Supported values are: "
+ VERSION_1_4 + ", "
+ VERSION_1_5 + ", "
+ VERSION_1_6 + ", "
+ VERSION_1_7 + ", "
+ VERSION_1_8
);
}
JavaCore.setComplianceOptions(JavaCore.VERSION_1_4, options);
}
parser.setCompilerOptions(options);
parser.setResolveBindings(false);
parser.setStatementsRecovery(false);
parser.setBindingsRecovery(false);
parser.setSource(source.toCharArray());
parser.setIgnoreMethodBodies(false);
return (CompilationUnit) parser.createAST(null);
}
示例6: getAST3
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* 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);
}
示例7: getAST4
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* 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);
}
示例8: getAST8
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* 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);
}
示例9: detectHyperlinks
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
boolean canShowMultipleHyperlinks)
{
IHyperlink[] links = null;
ITextEditor editor = (ITextEditor)getAdapter(ITextEditor.class);
IEditorInput input = editor.getEditorInput();
IJavaElement element = JavaUI.getEditorInputJavaElement(input);
if (element == null)
return links;
ITypeRoot typeRoot = (ITypeRoot)element.getAdapter(ITypeRoot.class);
try
{
IJavaElement[] srcElements = typeRoot.codeSelect(region.getOffset(), region.getLength());
if (srcElements.length == 1)
{
IJavaElement srcElement = srcElements[0];
switch (srcElement.getElementType())
{
case IJavaElement.METHOD:
IMethod method = (IMethod)srcElement;
links = getLinks(method.getDeclaringType(), null,
"//*[@id='" + srcElement.getElementName() + "']", region);
break;
case IJavaElement.TYPE:
links = getLinks((IType)srcElement, null, "//mapper", region);
break;
default:
break;
}
}
else if (srcElements.length == 0)
{
// Annotation value?
final ICompilationUnit compilationUnit = element.getAdapter(ICompilationUnit.class);
final ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(compilationUnit);
parser.setResolveBindings(true);
parser.setIgnoreMethodBodies(true);
final CompilationUnit astUnit = (CompilationUnit)parser.createAST(null);
AnnotationValueVisitor visitor = new AnnotationValueVisitor(
compilationUnit.getJavaProject(), region.getOffset());
astUnit.accept(visitor);
if (visitor.getHyperlink() != null)
{
links = new IHyperlink[]{
visitor.getHyperlink()
};
}
}
}
catch (JavaModelException e)
{
Activator.log(Status.ERROR, e.getMessage(), e);
}
return links;
}
示例10: editJavaSource
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private void editJavaSource(RefactoringStatus result) throws JavaModelException
{
final IType mapperType = info.getProject().findType(info.getNamespace());
if (mapperType == null)
return;
final ICompilationUnit compilationUnit = mapperType.getCompilationUnit();
if (compilationUnit == null)
return;
final ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(compilationUnit);
parser.setResolveBindings(true);
parser.setIgnoreMethodBodies(true);
final CompilationUnit astUnit = (CompilationUnit)parser.createAST(null);
astUnit.accept(new ASTVisitor()
{
private String typeFqn;
@Override
public boolean visit(TypeDeclaration node)
{
typeFqn = node.resolveBinding().getBinaryName();
return true;
}
@Override
public boolean visit(NormalAnnotation anno)
{
if (!info.getNamespace().equals(typeFqn))
return false;
String name = anno.getTypeName().getFullyQualifiedName();
if ("Results".equals(name))
{
@SuppressWarnings("unchecked")
List<MemberValuePair> pairs = anno.values();
for (MemberValuePair pair : pairs)
{
SimpleName key = pair.getName();
Expression value = pair.getValue();
if ("id".equals(key.getFullyQualifiedName())
&& ("\"" + info.getOldId() + "\"").equals(value.toString()))
{
List<ReplaceEdit> edits = getEdits((IFile)compilationUnit.getResource());
edits.add(new ReplaceEdit(value.getStartPosition(), value.getLength(),
"\"" + info.getNewId() + "\""));
break;
}
}
}
return true;
}
});
}
示例11: getAST4
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* 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>
* @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);
}