本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTParser.setStatementsRecovery方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTParser.setStatementsRecovery方法的具體用法?Java ASTParser.setStatementsRecovery怎麽用?Java ASTParser.setStatementsRecovery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ASTParser
的用法示例。
在下文中一共展示了ASTParser.setStatementsRecovery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRecoveredAST
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit getRecoveredAST(IDocument document, int offset, Document recoveredDocument) {
CompilationUnit ast = SharedASTProvider.getInstance().getAST(fCompilationUnit, null);
if (ast != null) {
recoveredDocument.set(document.get());
return ast;
}
char[] content= document.get().toCharArray();
// clear prefix to avoid compile errors
int index= offset - 1;
while (index >= 0 && Character.isJavaIdentifierPart(content[index])) {
content[index]= ' ';
index--;
}
recoveredDocument.set(new String(content));
final ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setSource(content);
parser.setUnitName(fCompilationUnit.getElementName());
parser.setProject(fCompilationUnit.getJavaProject());
return (CompilationUnit) parser.createAST(new NullProgressMonitor());
}
示例2: getRecoveredAST
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit getRecoveredAST(IDocument document, int offset, Document recoveredDocument) {
CompilationUnit ast= SharedASTProvider.getAST(fCompilationUnit, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
if (ast != null) {
recoveredDocument.set(document.get());
return ast;
}
char[] content= document.get().toCharArray();
// clear prefix to avoid compile errors
int index= offset - 1;
while (index >= 0 && Character.isJavaIdentifierPart(content[index])) {
content[index]= ' ';
index--;
}
recoveredDocument.set(new String(content));
final ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setSource(content);
parser.setUnitName(fCompilationUnit.getElementName());
parser.setProject(fCompilationUnit.getJavaProject());
return (CompilationUnit) parser.createAST(new NullProgressMonitor());
}
示例3: newASTParser
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static ASTParser newASTParser() {
final ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(IASTSharedValues.SHARED_AST_STATEMENT_RECOVERY);
parser.setBindingsRecovery(IASTSharedValues.SHARED_BINDING_RECOVERY);
return parser;
}
示例4: getExpectedTypeForGenericParameters
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private ITypeBinding getExpectedTypeForGenericParameters() {
char[][] chKeys= context.getExpectedTypesKeys();
if (chKeys == null || chKeys.length == 0) {
return null;
}
String[] keys= new String[chKeys.length];
for (int i= 0; i < keys.length; i++) {
keys[i]= String.valueOf(chKeys[0]);
}
final ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
parser.setProject(compilationUnit.getJavaProject());
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
final Map<String, IBinding> bindings= new HashMap<>();
ASTRequestor requestor= new ASTRequestor() {
@Override
public void acceptBinding(String bindingKey, IBinding binding) {
bindings.put(bindingKey, binding);
}
};
parser.createASTs(new ICompilationUnit[0], keys, requestor, null);
if (bindings.size() > 0) {
return (ITypeBinding) bindings.get(keys[0]);
}
return null;
}
示例5: 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);
}
示例6: parseCus
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static List<ParsedCu> parseCus(IJavaProject javaProject, String compilerCompliance, String text) {
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
if (javaProject != null) {
parser.setProject(javaProject);
} else if (compilerCompliance != null) {
Map<String, String> options= JavaCore.getOptions();
JavaModelUtil.setComplianceOptions(options, compilerCompliance);
parser.setCompilerOptions(options);
}
parser.setSource(text.toCharArray());
parser.setStatementsRecovery(true);
CompilationUnit unit= (CompilationUnit) parser.createAST(null);
if (unit.types().size() > 0)
return parseAsTypes(text, unit);
parser.setProject(javaProject);
parser.setSource(text.toCharArray());
parser.setStatementsRecovery(true);
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
ASTNode root= parser.createAST(null);
if (root instanceof TypeDeclaration) {
List<BodyDeclaration> bodyDeclarations= ((TypeDeclaration) root).bodyDeclarations();
if (bodyDeclarations.size() > 0)
return Collections.singletonList(new ParsedCu(text, ASTParser.K_CLASS_BODY_DECLARATIONS, null, null));
}
parser.setProject(javaProject);
parser.setSource(text.toCharArray());
parser.setStatementsRecovery(true);
parser.setKind(ASTParser.K_STATEMENTS);
root= parser.createAST(null);
if (root instanceof Block) {
List<Statement> statements= ((Block) root).statements();
if (statements.size() > 0)
return Collections.singletonList(new ParsedCu(text, ASTParser.K_STATEMENTS, null, null));
}
return Collections.emptyList();
}
示例7: createCleanUpASTParser
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static ASTParser createCleanUpASTParser() {
ASTParser result= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
result.setResolveBindings(true);
result.setStatementsRecovery(ASTProvider.SHARED_AST_STATEMENT_RECOVERY);
result.setBindingsRecovery(ASTProvider.SHARED_BINDING_RECOVERY);
return result;
}
示例8: getExpectedType
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Returns the type binding of the expected type as it is contained in the
* code completion context.
*
* @return the binding of the expected type
*/
private ITypeBinding getExpectedType() {
char[][] chKeys= fInvocationContext.getCoreContext().getExpectedTypesKeys();
if (chKeys == null || chKeys.length == 0)
return null;
String[] keys= new String[chKeys.length];
for (int i= 0; i < keys.length; i++) {
keys[i]= String.valueOf(chKeys[0]);
}
final ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(fCompilationUnit.getJavaProject());
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
final Map<String, IBinding> bindings= new HashMap<String, IBinding>();
ASTRequestor requestor= new ASTRequestor() {
@Override
public void acceptBinding(String bindingKey, IBinding binding) {
bindings.put(bindingKey, binding);
}
};
parser.createASTs(new ICompilationUnit[0], keys, requestor, null);
if (bindings.size() > 0)
return (ITypeBinding) bindings.get(keys[0]);
return null;
}
示例9: createQuickFixAST
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static CompilationUnit createQuickFixAST(ICompilationUnit compilationUnit, IProgressMonitor monitor) {
ASTParser astParser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
astParser.setSource(compilationUnit);
astParser.setResolveBindings(true);
astParser.setStatementsRecovery(ASTProvider.SHARED_AST_STATEMENT_RECOVERY);
astParser.setBindingsRecovery(ASTProvider.SHARED_BINDING_RECOVERY);
return (CompilationUnit) astParser.createAST(monitor);
}
示例10: createCU
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static CompilationUnit createCU(ICompilationUnit cu, boolean resolveBindings) {
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setProject(cu.getJavaProject());
parser.setSource(cu);
parser.setResolveBindings(resolveBindings);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
return unit;
}
示例11: 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);
}
示例12: writeMarkersExtendedTestSuite
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private void writeMarkersExtendedTestSuite() {
System.out.println("********** Writing markers in test suite" + suiteClass);
String testClassFileName = getSuiteFileName(suiteClass);
final IFile fileTestClass = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(testClassFileName));
String fileContents = readFileToString(testClassFileName);
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setStatementsRecovery(true);
Map<String, String> COMPILER_OPTIONS = new HashMap<String, String>(JavaCore.getOptions());
COMPILER_OPTIONS.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
COMPILER_OPTIONS.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
COMPILER_OPTIONS.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
parser.setUnitName(suiteClass);
String[] encodings = { ENCODING };
String[] classpaths = { classPath };
String[] sources = { new File(testClassFileName).getParent() };
parser.setEnvironment(classpaths, sources, encodings, true);
parser.setSource(fileContents.toCharArray());
CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
MethodExtractingVisitor visitor = new MethodExtractingVisitor();
compilationUnit.accept(visitor);
List<MethodDeclaration> methods = visitor.getMethods();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow iw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = iw.getActivePage();
try {
IDE.openEditor(page, fileTestClass, true);
} catch (PartInitException e1) {
System.out.println("Could not open test suite");
e1.printStackTrace();
}
}
});
if (Activator.markersEnabled()) {
for (MethodDeclaration m : methods) {
if (newTests.contains(m.getName().toString())) {
int lineNumber = compilationUnit.getLineNumber(m.getStartPosition());
try {
IMarker mark = fileTestClass.createMarker("EvoSuiteQuickFixes.newtestmarker");
mark.setAttribute(IMarker.MESSAGE, "This test case needs to be verified.");
mark.setAttribute(IMarker.LINE_NUMBER, lineNumber);
mark.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
mark.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
mark.setAttribute(IMarker.LOCATION, fileTestClass.getName());
mark.setAttribute(IMarker.CHAR_START, m.getStartPosition());
mark.setAttribute(IMarker.CHAR_END, m.getStartPosition() + 1);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
}
}
示例13: writeMarkersTestSuite
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
protected void writeMarkersTestSuite() {
if (Activator.markersEnabled()) {
System.out.println("********** Writing markers in test suite" + suiteClass);
String testClassFileName = getSuiteFileName(suiteClass);
final IFile fileTestClass = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(testClassFileName));
String fileContents = readFileToString(testClassFileName);
if (fileContents.isEmpty()) {
System.out.println("Not writing markers in test suite " + testClassFileName + " (not found)");
return;
}
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setStatementsRecovery(true);
@SuppressWarnings("unchecked")
Map<String, String> COMPILER_OPTIONS = new HashMap<String, String>(JavaCore.getOptions());
COMPILER_OPTIONS.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
COMPILER_OPTIONS.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
COMPILER_OPTIONS.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
parser.setUnitName(suiteClass);
String[] encodings = { ENCODING };
String[] classpaths = { classPath };
String[] sources = { new File(testClassFileName).getParent() };
parser.setEnvironment(classpaths, sources, encodings, true);
parser.setSource(fileContents.toCharArray());
CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
MethodExtractingVisitor visitor = new MethodExtractingVisitor();
compilationUnit.accept(visitor);
List<MethodDeclaration> methods = visitor.getMethods();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow iw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = iw.getActivePage();
try {
IDE.openEditor(page, fileTestClass, true);
} catch (PartInitException e1) {
System.out.println("Could not open test suite");
e1.printStackTrace();
}
}
});
for (MethodDeclaration m : methods) {
int lineNumber = compilationUnit.getLineNumber(m.getStartPosition());
try {
IMarker mark = fileTestClass.createMarker("EvoSuiteQuickFixes.newtestmarker");
mark.setAttribute(IMarker.MESSAGE, "This test case needs to be verified.");
mark.setAttribute(IMarker.LINE_NUMBER, lineNumber);
mark.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
mark.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
mark.setAttribute(IMarker.LOCATION, fileTestClass.getName());
mark.setAttribute(IMarker.CHAR_START, m.getStartPosition());
mark.setAttribute(IMarker.CHAR_END, m.getStartPosition() + 1);
} catch (CoreException e) {
e.printStackTrace();
}
}
} else
System.out.println("********** Markers are disabled");
}
示例14: getAST
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Get the AST of a file, including additional source paths to resolve
* cross-file bindings. It is assumed that a CompilationUnit will be
* returned. A heuristic is used to set the file's path variable.
* <p>
* Note: this may only yield a big improvement if the above heuristic fails
* and srcPaths contains the correct source path.
*
* @param file
* @param srcPaths
* for binding resolution
* @return the compilation unit of the file
* @throws IOException
*/
public final CompilationUnit getAST(final File file,
final Set<String> srcPaths) throws IOException {
final String sourceFile = FileUtils.readFileToString(file);
final ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
final Map<String, String> options = new Hashtable<String, String>();
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
if (useJavadocs) {
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
}
parser.setCompilerOptions(options);
parser.setSource(sourceFile.toCharArray()); // set source
parser.setResolveBindings(useBindings);
parser.setBindingsRecovery(useBindings);
parser.setStatementsRecovery(true);
parser.setUnitName(file.getAbsolutePath());
// Heuristic to retrieve source file path
final String srcFilePath;
if (file.getAbsolutePath().contains("/src")) {
srcFilePath = file.getAbsolutePath().substring(0,
file.getAbsolutePath().indexOf("src", 0) + 3);
} else {
srcFilePath = "";
}
// Add file to source paths if not already present
srcPaths.add(srcFilePath);
final String[] sourcePathEntries = srcPaths.toArray(new String[srcPaths
.size()]);
final String[] classPathEntries = new String[0];
parser.setEnvironment(classPathEntries, sourcePathEntries, null, true);
final CompilationUnit compilationUnit = (CompilationUnit) parser
.createAST(null);
return compilationUnit;
}
示例15: getASTNode
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Return an ASTNode given the content
*
* @param content
* @return
*/
public final ASTNode getASTNode(final char[] content,
final ParseType parseType) {
final ASTParser parser = ASTParser.newParser(AST.JLS8);
final int astKind;
switch (parseType) {
case CLASS_BODY:
case METHOD:
astKind = ASTParser.K_CLASS_BODY_DECLARATIONS;
break;
case COMPILATION_UNIT:
astKind = ASTParser.K_COMPILATION_UNIT;
break;
case EXPRESSION:
astKind = ASTParser.K_EXPRESSION;
break;
case STATEMENTS:
astKind = ASTParser.K_STATEMENTS;
break;
default:
astKind = ASTParser.K_COMPILATION_UNIT;
}
parser.setKind(astKind);
final Map<String, String> options = new Hashtable<String, String>();
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
if (useJavadocs) {
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
}
parser.setCompilerOptions(options);
parser.setSource(content); // set source
parser.setResolveBindings(useBindings);
parser.setBindingsRecovery(useBindings);
parser.setStatementsRecovery(true);
if (parseType != ParseType.METHOD) {
return parser.createAST(null);
} else {
final ASTNode cu = parser.createAST(null);
return getFirstMethodDeclaration(cu);
}
}