use of org.eclipse.jdt.core.dom.ASTParser in project che by eclipse.
the class TypeEnvironment method createStandardType.
private StandardType createStandardType(String fullyQualifiedName, IJavaProject focus) {
try {
IType javaElementType = focus.findType(fullyQualifiedName);
StandardType result = fStandardTypes.get(javaElementType);
if (result != null)
return result;
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(focus);
IBinding[] bindings = parser.createBindings(new IJavaElement[] { javaElementType }, null);
return createStandardType((ITypeBinding) bindings[0]);
} catch (JavaModelException e) {
// fall through
}
return null;
}
use of org.eclipse.jdt.core.dom.ASTParser in project flux by eclipse.
the class ASTNodeFactory method newTypeParameter.
public static TypeParameter newTypeParameter(AST ast, String content) {
StringBuffer buffer = new StringBuffer(TYPEPARAM_HEADER);
buffer.append(content);
buffer.append(TYPEPARAM_FOOTER);
ASTParser p = ASTParser.newParser(ast.apiLevel());
p.setSource(buffer.toString().toCharArray());
CompilationUnit root = (CompilationUnit) p.createAST(null);
List<AbstractTypeDeclaration> list = root.types();
TypeDeclaration typeDecl = (TypeDeclaration) list.get(0);
MethodDeclaration methodDecl = typeDecl.getMethods()[0];
TypeParameter tp = (TypeParameter) methodDecl.typeParameters().get(0);
ASTNode result = ASTNode.copySubtree(ast, tp);
result.accept(new PositionClearer());
return (TypeParameter) result;
}
use of org.eclipse.jdt.core.dom.ASTParser in project flux by eclipse.
the class ASTNodeFactory method newStatement.
public static ASTNode newStatement(AST ast, String content) {
StringBuffer buffer = new StringBuffer(STATEMENT_HEADER);
buffer.append(content);
buffer.append(STATEMENT_FOOTER);
ASTParser p = ASTParser.newParser(ast.apiLevel());
p.setSource(buffer.toString().toCharArray());
CompilationUnit root = (CompilationUnit) p.createAST(null);
ASTNode result = ASTNode.copySubtree(ast, NodeFinder.perform(root, STATEMENT_HEADER.length(), content.length()));
result.accept(new PositionClearer());
return result;
}
use of org.eclipse.jdt.core.dom.ASTParser in project flux by eclipse.
the class ASTProvider method createAST.
private static CompilationUnit createAST(final ITypeRoot input, final IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
final ASTParser parser = ASTParser.newParser(SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(SHARED_AST_STATEMENT_RECOVERY);
parser.setBindingsRecovery(SHARED_BINDING_RECOVERY);
parser.setSource(input);
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
final CompilationUnit[] root = new CompilationUnit[1];
SafeRunner.run(new ISafeRunnable() {
public void run() {
try {
if (progressMonitor != null && progressMonitor.isCanceled())
return;
root[0] = (CompilationUnit) parser.createAST(progressMonitor);
//mark as unmodifiable
ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
} catch (OperationCanceledException ex) {
return;
}
}
public void handleException(Throwable ex) {
//$NON-NLS-1$
IStatus status = new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Error in JDT Core during AST creation", ex);
JavaPlugin.getDefault().getLog().log(status);
}
});
return root[0];
}
use of org.eclipse.jdt.core.dom.ASTParser in project flux by eclipse.
the class QuickAssistService method getProblemLocations.
public IProblemLocation getProblemLocations(ICompilationUnit liveEditUnit, int problemID, int offset, int length) {
final ASTParser parser = ASTParser.newParser(AST.JLS4);
// Parse the class as a compilation unit.
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(liveEditUnit);
parser.setResolveBindings(true);
// Return the compiled class as a compilation unit
final CompilationUnit unit = (CompilationUnit) parser.createAST(null);
IProblem[] problems = unit.getProblems();
if (problemID > 0) {
return filterOutProblems(problems, problemID);
} else {
IProblemLocation[] locations = convertProblems(unit.getProblems());
for (IProblemLocation iProblemLocation : locations) {
if (offset >= iProblemLocation.getOffset() && offset <= (iProblemLocation.getOffset() + iProblemLocation.getLength())) {
return iProblemLocation;
}
}
}
return null;
}
Aggregations