本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTParser.setBindingsRecovery方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTParser.setBindingsRecovery方法的具體用法?Java ASTParser.setBindingsRecovery怎麽用?Java ASTParser.setBindingsRecovery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ASTParser
的用法示例。
在下文中一共展示了ASTParser.setBindingsRecovery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prepareAST
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit prepareAST(String javaFile) throws IOException {
File projectRoot = new File(VALIDATION_EXAMPLES_ROOT).getAbsoluteFile();
File sourceFile = new File(projectRoot.getCanonicalPath() + VALIDATION_EXAMPLES_PACKAGE + javaFile);
ASTParser parser = ASTParser.newParser(AST.JLS8);
char[] content = SharedUtils.getFileContents(sourceFile);
String[] classpath = {};
String[] sourcepath = { projectRoot.getCanonicalPath(), new File(API_SRC_LOC).getCanonicalPath() };
String[] encodings = { "UTF-8", "UTF-8" };
parser.setSource(content);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setUnitName(sourceFile.getName());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setEnvironment(classpath, sourcepath, encodings, true);
return (CompilationUnit) parser.createAST(null);
}
示例2: parseJavaSource
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Parses the specified Java source file located in the given Java project.
*
* @param sourceFile
* The specified Java source file.
* @param project
* The given Java project.
* @return The parsed compilation unit.
* @throws IOException
* Thrown when I/O error occurs during reading the file.
* @throws JavaModelException
*/
public static CompilationUnit parseJavaSource(File sourceFile, IJavaProject project)
throws IOException, JavaModelException {
ASTParser parser = ASTParser.newParser(AST.JLS8);
char[] content = SharedUtils.getFileContents(sourceFile);
parser.setSource(content);
parser.setProject(project);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setUnitName(sourceFile.getName());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
return compilationUnit;
}
示例3: handleImportRemoval
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private void handleImportRemoval(CompilationUnit cu, ASTRewrite rewriter, ImportRewrite importRewrite,
ITypeBinding superclass) throws CoreException, JavaModelException, BadLocationException {
ICompilationUnit icu = (ICompilationUnit) cu.getJavaElement().getAdapter(IOpenable.class);
TextEdit importEdits = importRewrite.rewriteImports(new NullProgressMonitor());
TextEdit edits = rewriter.rewriteAST();
importEdits.addChild(edits);
// apply the text edits to the compilation unit
String source = icu.getSource();
Document document = new Document(source);
importEdits.apply(document);
String oldContents = icu.getBuffer().getContents();
icu.getBuffer().setContents(document.get());
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setResolveBindings(true);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setBindingsRecovery(true);
parser.setSource(icu);
CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
if (!ImportRelevanceFinder.isStillNeeded(astRoot, superclass.getQualifiedName())) {
importRewrite.removeImport(superclass.getQualifiedName());
}
icu.getBuffer().setContents(oldContents);
}
示例4: modify
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
@Override
public void modify(ICompilationUnit cu, IProgressMonitor monitor)
throws MalformedTreeException, BadLocationException, CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, modifiers.size() + 1);
// parse compilation unit
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(cu);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
CompilationUnit astRoot = (CompilationUnit) parser.createAST(subMonitor.split(1));
for (ICompilationUnitModifier compilationUnitModifier : modifiers) {
compilationUnitModifier.modifyCompilationUnit(astRoot, subMonitor.split(1));
}
}
示例5: parse
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* @param compilationUnit
* @param progressMonitor
* @return
* @throws JavaModelException
*/
public static CompilationUnit parse(final ICompilationUnit cu) {
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(cu);
parser.setResolveBindings(true);
parser.setEnvironment(null, null, null, true);
parser.setBindingsRecovery(true);
final CompilationUnit ast = (CompilationUnit) parser.createAST(new NullProgressMonitor());
return ast;
}
示例6: parseAndResolveSource
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Parse a source file, attempting to resolve references in the AST. Valid Java files will usually
* have errors in the CompilationUnit returned by this method, because classes, imports and
* methods will be undefined (because we're only looking at a single file from a whole project).
* Consequently, do not assume the returned object's getProblems() is an empty list. On the other
* hand, {@link @parseSource} returns a CompilationUnit fit for syntax checking purposes.
*/
private static CompilationUnit parseAndResolveSource(String source) {
ASTParser parser = createCompilationUnitParser();
parser.setSource(source.toCharArray());
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setEnvironment(
EMPTY_STRING_ARRAY,
EMPTY_STRING_ARRAY,
EMPTY_STRING_ARRAY,
true /* includeRunningVMBootclasspath */);
parser.setUnitName("dontCare");
return (CompilationUnit) parser.createAST(null);
}
示例7: buildAstParser
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static ASTParser buildAstParser(String[] sourceFolders) {
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
parser.setCompilerOptions(options);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setEnvironment(new String[0], sourceFolders, null, true);
// parser.setEnvironment(new String[0], new String[]{"tmp\\refactoring-toy-example\\src"}, null, false);
return parser;
}
示例8: buildAstParser
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static ASTParser buildAstParser(String[] sourceFolders) {
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
parser.setCompilerOptions(options);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setEnvironment(new String[0], sourceFolders, null, true);
//parser.setEnvironment(new String[0], new String[]{"tmp\\refactoring-toy-example\\src"}, null, false);
return parser;
}
示例9: generateExamples
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private Set<Slice> generateExamples() {
Set<Slice> slices = new HashSet<>();
File srcFile = new File(srcPath);
String[] testPaths = getTestFiles(srcFile).parallelStream().map(File::getAbsolutePath).toArray(String[]::new);
String[] folderPaths = getAllFiles(srcFile).parallelStream().map(File::getParentFile).map(File::getAbsolutePath).toArray(String[]::new);
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setEnvironment(null, folderPaths, null, true);
parser.setResolveBindings(true);
Map<String, String> options = new Hashtable<>();
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
parser.setCompilerOptions(options);
parser.setBindingsRecovery(true);
parser.createASTs(testPaths, null, new String[]{}, new FileASTRequestor() {
@Override
public void acceptAST(String sourceFilePath, CompilationUnit javaUnit) {
APIMethodVisitor visitor = new APIMethodVisitor();
javaUnit.accept(visitor);
slices.addAll(visitor.getSlices());
}
}, null);
return slices;
}
示例10: 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;
}
示例11: createSourceCuNode
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit createSourceCuNode() {
Assert.isTrue(getSourceCu() != null || getSourceClassFile() != null);
Assert.isTrue(getSourceCu() == null || getSourceClassFile() == null);
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setBindingsRecovery(true);
parser.setResolveBindings(true);
if (getSourceCu() != null) parser.setSource(getSourceCu());
else parser.setSource(getSourceClassFile());
return (CompilationUnit) parser.createAST(null);
}
示例12: 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);
}
示例13: getSuperClassCU
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit getSuperClassCU(Type superClass) {
ICompilationUnit element = (ICompilationUnit) superClass.resolveBinding().getTypeDeclaration().getJavaElement()
.getParent();
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setSource(element);
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
return cu;
}
示例14: filterDiagramsByType
import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
* Filter method to separate sequenceDiagrams from normal Layouts, leave
* normal layouts in remove SequenceDiagrams
*
*/
private void filterDiagramsByType() {
seqDiagrams = new ArrayList<TypeDeclaration>();
String diagram = null;
for (Iterator<String> iterator = diagrams.iterator(); iterator.hasNext();) {
diagram = iterator.next();
try {
IFile resource = project.getFile("src/" + diagram.replace(".", "/") + ".java");
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setSource((ICompilationUnit) JavaCore.create(resource));
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
TypeDeclaration currentType = (TypeDeclaration) cu.types().get(0);
if (SharedUtils.typeIsAssignableFrom(currentType, Interaction.class)) {
seqDiagrams.add(currentType);
iterator.remove();
nonExportedCount--;
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new ExportRuntimeException("There was an error while trying to load Class " + e.getMessage()
+ ", this error originated from the loading of " + diagram + " class", e);
}
}
}
示例15: 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;
}