use of org.eclipse.jdt.core.dom.CheASTParser in project che by eclipse.
the class ASTNodeFactory method newType.
public static Type newType(AST ast, String content) {
StringBuffer buffer = new StringBuffer(TYPE_HEADER);
buffer.append(content);
buffer.append(TYPE_FOOTER);
CheASTParser p = CheASTParser.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];
ASTNode type = methodDecl.getReturnType2();
ASTNode result = ASTNode.copySubtree(ast, type);
result.accept(new PositionClearer());
return (Type) result;
}
use of org.eclipse.jdt.core.dom.CheASTParser in project che by eclipse.
the class StubUtility method getParameterTypeNamesForSeeTag.
/*
* Returns the parameters type names used in see tags. Currently, these are always fully qualified.
*/
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
try {
CheASTParser parser = CheASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(overridden.getJavaProject());
IBinding[] bindings = parser.createBindings(new IJavaElement[] { overridden }, null);
if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
}
} catch (IllegalStateException e) {
// method does not exist
}
// fall back code. Not good for generic methods!
String[] paramTypes = overridden.getParameterTypes();
String[] paramTypeNames = new String[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) {
paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
}
return paramTypeNames;
}
use of org.eclipse.jdt.core.dom.CheASTParser in project che by eclipse.
the class ASTProvider method createAST.
/**
* Creates a new compilation unit AST.
*
* @param input the Java element for which to create the AST
* @param progressMonitor the progress monitor
* @return AST
*/
public static CompilationUnit createAST(final ITypeRoot input, final IProgressMonitor progressMonitor) {
if (!hasSource(input))
return null;
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
final CheASTParser parser = CheASTParser.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;
if (DEBUG)
System.err.println(getThreadName() + " - " + DEBUG_PREFIX + "creating AST for: " + //$NON-NLS-1$ //$NON-NLS-2$
input.getElementName());
root[0] = (CompilationUnit) parser.createAST(progressMonitor);
//mark as unmodifiable
ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
} catch (OperationCanceledException ex) {
return;
}
}
public void handleException(Throwable ex) {
LOG.error(ex.getMessage(), ex);
}
});
return root[0];
}
use of org.eclipse.jdt.core.dom.CheASTParser in project che by eclipse.
the class JavadocContentAccess2 method createAST.
private static CompilationUnit createAST(IJavaElement element, String cuSource) {
Assert.isNotNull(element);
CheASTParser parser = CheASTParser.newParser(AST.JLS8);
IJavaProject javaProject = element.getJavaProject();
parser.setProject(javaProject);
Map<String, String> options = javaProject.getOptions(true);
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
JavaCore.ENABLED);
parser.setCompilerOptions(options);
parser.setSource(cuSource.toCharArray());
return (CompilationUnit) parser.createAST(null);
}
use of org.eclipse.jdt.core.dom.CheASTParser in project che by eclipse.
the class OverrideCompletionProposal method getRecoveredAST.
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 CheASTParser parser = CheASTParser.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());
}
Aggregations