List of usage examples for org.eclipse.jdt.core.dom CompilationUnit types
ASTNode.NodeList types
To view the source code for org.eclipse.jdt.core.dom CompilationUnit types.
Click Source Link
AbstractTypeDeclaration
) From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(CompilationUnit node) { if (node.getPackage() != null) { node.getPackage().accept(this); }//from ww w . j a v a 2s . c om for (Iterator<ImportDeclaration> it = node.imports().iterator(); it.hasNext();) { ImportDeclaration d = it.next(); d.accept(this); } for (Iterator<AbstractTypeDeclaration> it = node.types().iterator(); it.hasNext();) { AbstractTypeDeclaration d = it.next(); d.accept(this); } return false; }
From source file:at.bestsolution.fxide.jdt.editor.JDTJavaDocSupport.java
License:Open Source License
public static HtmlString toHtml(IJavaElement element, String rawJavadoc) { String source = rawJavadoc + "class C{}"; //$NON-NLS-1$ CompilationUnit root = createAST(element, source); if (root == null) return null; List<AbstractTypeDeclaration> types = root.types(); if (types.size() != 1) return null; AbstractTypeDeclaration type = types.get(0); Javadoc javadoc = type.getJavadoc(); String js = ""; try (InputStream in = JDTJavaDocSupport.class.getResourceAsStream("internal/prettify.js")) { js = IOUtils.readToString(in, Charset.forName("UTF-8")); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace();/* w w w. j av a2 s .c o m*/ } StringBuilder b = new StringBuilder("<html><head></head><body>"); List<TagElement> l = javadoc.tags(); for (TagElement e : l) { if (e.getTagName() == null) { b.append(' '); handleContents(b, e); } // System.err.println(" ===> " + e.getTagName()); } b.append("</body></html>"); // System.err.println(b); return new HtmlString(b.toString()); // BufferedReader r = new BufferedReader(new StringReader(javaDoc)); // StringBuilder b = new StringBuilder(); // return javaDoc.replaceAll("/\\*.*\r?\n", "").replaceAll(".*\\*", ""); }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private static Javadoc getJavadocNode(IJavaElement element, String rawJavadoc) { //FIXME: take from SharedASTProvider if available //Caveat: Javadoc nodes are not available when Javadoc processing has been disabled! //https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207 String source = rawJavadoc + "class C{}"; //$NON-NLS-1$ CompilationUnit root = createAST(element, source); if (root == null) return null; List<AbstractTypeDeclaration> types = root.types(); if (types.size() != 1) return null; AbstractTypeDeclaration type = types.get(0); return type.getJavadoc(); }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(CompilationUnit node) { // b.setPosition(pos.build()); PackageDeclaration pkg = node.getPackage(); if (pkg == null) { b.setName(""); } else {/* w w w .j a va 2 s. com*/ b.setName(pkg.getName().getFullyQualifiedName()); for (Object a : pkg.annotations()) { ((Annotation) a).accept(this); b.addModifiers(modifiers.pop()); } } for (Object i : node.imports()) { ImportDeclaration id = (ImportDeclaration) i; String imp = ""; if (id.isStatic()) imp += "static "; imp += id.getName().getFullyQualifiedName(); if (id.isOnDemand()) imp += ".*"; imports.add(imp); } for (Object t : node.types()) { declarations.push(new ArrayList<boa.types.Ast.Declaration>()); ((AbstractTypeDeclaration) t).accept(this); for (boa.types.Ast.Declaration d : declarations.pop()) b.addDeclarations(d); } for (Object c : node.getCommentList()) ((org.eclipse.jdt.core.dom.Comment) c).accept(this); return false; }
From source file:br.com.objectos.way.core.code.jdt.ASTTest.java
License:Apache License
@SuppressWarnings("unchecked") public void stackoverflow_answer() { AST ast = AST.newAST(AST.JLS8);// w ww .j a v a 2 s . c o m CompilationUnit cu = ast.newCompilationUnit(); PackageDeclaration p1 = ast.newPackageDeclaration(); p1.setName(ast.newSimpleName("foo")); cu.setPackage(p1); ImportDeclaration id = ast.newImportDeclaration(); id.setName(ast.newName(new String[] { "java", "util", "Set" })); cu.imports().add(id); TypeDeclaration td = ast.newTypeDeclaration(); td.setName(ast.newSimpleName("Foo")); TypeParameter tp = ast.newTypeParameter(); tp.setName(ast.newSimpleName("X")); td.typeParameters().add(tp); cu.types().add(td); MethodDeclaration md = ast.newMethodDeclaration(); md.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD)); md.setName(ast.newSimpleName("bar")); SingleVariableDeclaration var = ast.newSingleVariableDeclaration(); var.setType(ast.newSimpleType(ast.newSimpleName("String"))); var.setName(ast.newSimpleName("a")); md.parameters().add(var); td.bodyDeclarations().add(md); Block block = ast.newBlock(); md.setBody(block); MethodInvocation mi = ast.newMethodInvocation(); mi.setName(ast.newSimpleName("x")); ExpressionStatement e = ast.newExpressionStatement(mi); block.statements().add(e); System.out.println(cu); }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final PackageDeclaration pNode) { final IPackageBinding binding = pNode.resolveBinding(); if (ASTCrawler.checkForNull(binding)) return false; final IElement packageElem = this.convertBinding(binding); this.aDB.addElement(packageElem, binding.getModifiers()); final CompilationUnit parent = (CompilationUnit) pNode.getParent(); @SuppressWarnings("rawtypes") final List containedTypes = parent.types(); for (@SuppressWarnings("rawtypes") final Iterator it = containedTypes.iterator(); it.hasNext();) { final AbstractTypeDeclaration type = (AbstractTypeDeclaration) it.next(); final ITypeBinding typeBinding = type.resolveBinding(); final IElement typeElem = ASTCrawler.convertBinding(typeBinding); this.aDB.addElement(typeElem, typeBinding.getModifiers()); this.aDB.addRelation(packageElem, Relation.CONTAINS, typeElem); }//w w w .j ava2 s . c o m return true; }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(CompilationUnit node) { IJavaElement thisFile = node.getJavaElement(); for (Object abstractTypeDeclaration : node.types()) { if ((abstractTypeDeclaration instanceof TypeDeclaration)) { TypeDeclaration td = (TypeDeclaration) abstractTypeDeclaration; this.typeToFileMap_.put(getQualifiedName(td.resolveBinding()), thisFile); }/*from w w w.j a va 2 s . c o m*/ } return true; }
From source file:cn.ieclipse.adt.ext.jdt.SourceGenerator.java
License:Apache License
private static void merge(CompilationUnit unit, String pkgName, String typeName, String auth, String dbName, List<String> tableCreators) { unit.recordModifications();// www .ja v a 2s .c o m AST ast = unit.getAST(); TypeDeclaration type = (TypeDeclaration) unit.types().get(0); ImportDeclaration id = ast.newImportDeclaration(); id.setName(ast.newName("cn.ieclipse.aorm.Session")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.content.UriMatcher")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.database.sqlite.SQLiteDatabase")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.database.sqlite.SQLiteOpenHelper")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("java.net.Uri")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.content.ContentValue")); unit.imports().add(id); VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("AUTH")); StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(auth); vdf.setInitializer(sl); FieldDeclaration fd = ast.newFieldDeclaration(vdf); fd.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL))); fd.setType(ast.newSimpleType(ast.newSimpleName("String"))); int i = 0; type.bodyDeclarations().add(i++, fd); // URI = Uri.parse("content://" + AUTH); vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("URI")); MethodInvocation mi = ast.newMethodInvocation(); mi.setExpression(ast.newSimpleName("Uri")); mi.setName(ast.newSimpleName("parse")); InfixExpression fix = ast.newInfixExpression(); fix.setOperator(InfixExpression.Operator.PLUS); sl = ast.newStringLiteral(); sl.setLiteralValue("content://"); fix.setLeftOperand(sl); fix.setRightOperand(ast.newSimpleName("AUTH")); mi.arguments().add(fix); vdf.setInitializer(mi); fd = ast.newFieldDeclaration(vdf); fd.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL))); fd.setType(ast.newSimpleType(ast.newSimpleName("Uri"))); type.bodyDeclarations().add(i++, fd); // private mOpenHelper; vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("mOpenHelper")); fd = ast.newFieldDeclaration(vdf); fd.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fd.setType(ast.newSimpleType(ast.newName("SQLiteOpenHelper"))); type.bodyDeclarations().add(i++, fd); // private static session; vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("session")); fd = ast.newFieldDeclaration(vdf); fd.modifiers().addAll(ast.newModifiers((Modifier.PRIVATE | Modifier.STATIC))); fd.setType(ast.newSimpleType(ast.newName("Session"))); type.bodyDeclarations().add(i++, fd); // public static Session getSession(){ // return session; // } MethodDeclaration md = ast.newMethodDeclaration(); md.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC | Modifier.STATIC))); md.setReturnType2(ast.newSimpleType(ast.newName("Session"))); md.setName(ast.newSimpleName("getSession")); Block methodBlock = ast.newBlock(); ReturnStatement returnStmt = ast.newReturnStatement(); returnStmt.setExpression(ast.newSimpleName("session")); methodBlock.statements().add(returnStmt); md.setBody(methodBlock); type.bodyDeclarations().add(i, md); // modify onCreate rewriteOnCreate(unit, dbName, tableCreators); }
From source file:cn.ieclipse.adt.ext.jdt.SourceGenerator.java
License:Apache License
private static void rewriteOnCreate(CompilationUnit unit, String dbName, List<String> tableCreators) { AST ast = unit.getAST();/*from w ww. ja va 2s . c o m*/ TypeDeclaration type = (TypeDeclaration) unit.types().get(0); MethodDeclaration onCreate = getMethod(type, ("onCreate"), null); if (onCreate != null) { Block methodBlock = ast.newBlock(); // mOpenHelper = new // InlineOpenHelper(this.getContext(),"person.db",null,1); Assignment a = ast.newAssignment(); a.setOperator(Assignment.Operator.ASSIGN); a.setLeftHandSide(ast.newSimpleName("mOpenHelper")); ClassInstanceCreation cc = ast.newClassInstanceCreation(); cc.setType(ast.newSimpleType(ast.newSimpleName("SQLiteOpenHelper"))); ThisExpression thisExp = ast.newThisExpression(); MethodInvocation mi = ast.newMethodInvocation(); mi.setName(ast.newSimpleName("getContext")); mi.setExpression(thisExp); cc.arguments().add(mi); StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(dbName); cc.arguments().add(sl); cc.arguments().add(ast.newNullLiteral()); cc.arguments().add(ast.newNumberLiteral("1")); a.setRightHandSide(cc); methodBlock.statements().add(ast.newExpressionStatement(a)); AnonymousClassDeclaration acd = ast.newAnonymousClassDeclaration(); cc.setAnonymousClassDeclaration(acd); genInnerSQLiteOpenHelper(acd, ast, tableCreators); a = ast.newAssignment(); a.setOperator(Assignment.Operator.ASSIGN); a.setLeftHandSide(ast.newSimpleName("session")); ClassInstanceCreation cic = ast.newClassInstanceCreation(); cic.setType(ast.newSimpleType(ast.newSimpleName("Session"))); // SingleVariableDeclaration svd = // ast.newSingleVariableDeclaration(); // svd.setName(ast.newSimpleName("mOpenHelper")); cic.arguments().add(ast.newSimpleName("mOpenHelper")); // vdf.setInitializer(cic); a.setRightHandSide(cic); // methodBlock.statements().add(vde); methodBlock.statements().add(ast.newExpressionStatement(a)); ReturnStatement returnStmt = ast.newReturnStatement(); returnStmt.setExpression(ast.newBooleanLiteral(true)); methodBlock.statements().add(returnStmt); onCreate.setBody(methodBlock); } }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(CompilationUnit node) { if (node.getPackage() != null) { node.getPackage().accept(this); }/* w w w . java 2s . co m*/ for (Iterator it = node.imports().iterator(); it.hasNext();) { ImportDeclaration d = (ImportDeclaration) it.next(); d.accept(this); } for (Iterator it = node.types().iterator(); it.hasNext();) { AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next(); d.accept(this); } return false; }