List of usage examples for org.eclipse.jdt.core.dom TypeDeclaration typeParameters
ASTNode.NodeList typeParameters
To view the source code for org.eclipse.jdt.core.dom TypeDeclaration typeParameters.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }//from ww w . ja va 2s.c o m if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); } this.fBuffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$ node.getName().accept(this); if (node.getAST().apiLevel() >= JLS3) { if (!node.typeParameters().isEmpty()) { this.fBuffer.append("<");//$NON-NLS-1$ for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext();) { TypeParameter t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(",");//$NON-NLS-1$ } } this.fBuffer.append(">");//$NON-NLS-1$ } } this.fBuffer.append(" ");//$NON-NLS-1$ if (node.getAST().apiLevel() >= JLS3) { if (node.getSuperclassType() != null) { this.fBuffer.append("extends ");//$NON-NLS-1$ node.getSuperclassType().accept(this); this.fBuffer.append(" ");//$NON-NLS-1$ } if (!node.superInterfaceTypes().isEmpty()) { this.fBuffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$ for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext();) { Type t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append(" ");//$NON-NLS-1$ } } this.fBuffer.append("{");//$NON-NLS-1$ BodyDeclaration prev = null; for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = it.next(); if (prev instanceof EnumConstantDeclaration) { // enum constant declarations do not include punctuation if (d instanceof EnumConstantDeclaration) { // enum constant declarations are separated by commas this.fBuffer.append(", ");//$NON-NLS-1$ } else { // semicolon separates last enum constant declaration from // first class body declarations this.fBuffer.append("; ");//$NON-NLS-1$ } } d.accept(this); prev = d; } this.fBuffer.append("}");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(TypeDeclaration node) { boa.types.Ast.Declaration.Builder b = boa.types.Ast.Declaration.newBuilder(); // b.setPosition(pos.build()); b.setName(node.getName().getFullyQualifiedName()); if (node.isInterface()) b.setKind(boa.types.Ast.TypeKind.INTERFACE); else//from w w w.j av a2s . c om b.setKind(boa.types.Ast.TypeKind.CLASS); for (Object m : node.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); b.addModifiers(modifiers.pop()); } for (Object t : node.typeParameters()) { boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); String name = ((TypeParameter) t).getName().getFullyQualifiedName(); String bounds = ""; for (Object o : ((TypeParameter) t).typeBounds()) { if (bounds.length() > 0) bounds += " & "; bounds += typeName((org.eclipse.jdt.core.dom.Type) o); } if (bounds.length() > 0) name = name + " extends " + bounds; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.GENERIC); b.addGenericParameters(tb.build()); } if (node.getSuperclassType() != null) { boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex(typeName(node.getSuperclassType()))); tb.setKind(boa.types.Ast.TypeKind.CLASS); b.addParents(tb.build()); } for (Object t : node.superInterfaceTypes()) { boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) t))); tb.setKind(boa.types.Ast.TypeKind.INTERFACE); b.addParents(tb.build()); } for (Object d : node.bodyDeclarations()) { if (d instanceof FieldDeclaration) { fields.push(new ArrayList<boa.types.Ast.Variable>()); ((FieldDeclaration) d).accept(this); for (boa.types.Ast.Variable v : fields.pop()) b.addFields(v); } else if (d instanceof MethodDeclaration) { methods.push(new ArrayList<boa.types.Ast.Method>()); ((MethodDeclaration) d).accept(this); for (boa.types.Ast.Method m : methods.pop()) b.addMethods(m); } else if (d instanceof Initializer) { methods.push(new ArrayList<boa.types.Ast.Method>()); ((Initializer) d).accept(this); for (boa.types.Ast.Method m : methods.pop()) b.addMethods(m); } else { declarations.push(new ArrayList<boa.types.Ast.Declaration>()); ((BodyDeclaration) d).accept(this); for (boa.types.Ast.Declaration nd : declarations.pop()) b.addNestedDeclarations(nd); } } // TODO initializers // TODO enum constants // TODO annotation type members declarations.peek().add(b.build()); 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);/*from w ww . jav a2s .com*/ 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:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w. j av a 2s. c o m public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } // @Inria pushNode(node, node.getName().toString()); visitListAsNode(EntityType.MODIFIERS, node.modifiers()); visitListAsNode(EntityType.TYPE_ARGUMENTS, node.typeParameters()); if (node.getSuperclassType() != null) { node.getSuperclassType().accept(this); } visitListAsNode(EntityType.SUPER_INTERFACE_TYPES, node.superInterfaceTypes()); // @Inria // Change Distiller does not check the changes at Class Field declaration for (FieldDeclaration fd : node.getFields()) { fd.accept(this); } // @Inria // Visit Declaration and Body (inside MD visiting) for (MethodDeclaration md : node.getMethods()) { md.accept(this); } return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }//from ww w .j av a 2 s.co m if (node.getAST().apiLevel() >= AST.JLS3) { printModifiers(node.modifiers()); } this.buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$ node.getName().accept(this); if (node.getAST().apiLevel() >= AST.JLS3) { if (!node.typeParameters().isEmpty()) { this.buffer.append("<");//$NON-NLS-1$ for (Iterator it = node.typeParameters().iterator(); it.hasNext();) { TypeParameter t = (TypeParameter) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(",");//$NON-NLS-1$ } } this.buffer.append(">");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ if (node.getAST().apiLevel() >= AST.JLS3) { if (node.getSuperclassType() != null) { this.buffer.append("extends ");//$NON-NLS-1$ node.getSuperclassType().accept(this); this.buffer.append(" ");//$NON-NLS-1$ } if (!node.superInterfaceTypes().isEmpty()) { this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$ for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext();) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(", ");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ } } this.buffer.append("{\n");//$NON-NLS-1$ this.indent++; BodyDeclaration prev = null; for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = (BodyDeclaration) it.next(); if (prev instanceof EnumConstantDeclaration) { // enum constant declarations do not include punctuation if (d instanceof EnumConstantDeclaration) { // enum constant declarations are separated by commas this.buffer.append(", ");//$NON-NLS-1$ } else { // semicolon separates last enum constant declaration from // first class body declarations this.buffer.append("; ");//$NON-NLS-1$ } } d.accept(this); } this.indent--; printIndent(); this.buffer.append("}\n");//$NON-NLS-1$ return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(TypeDeclaration node) { if (node.getName().getStartPosition() == -1) return true; // this is a fake type created by parsing in class body mode handleToken(node.getName(), TokenNameIdentifier, true, false); List<TypeParameter> typeParameters = node.typeParameters(); handleTypeParameters(typeParameters); if (!node.isInterface() && !node.superInterfaceTypes().isEmpty()) { // fix for: class A<E> extends ArrayList<String>implements Callable<String> handleToken(node.getName(), TokenNameimplements, true, false); }//from w w w . ja v a2 s. c o m handleToken(node.getName(), TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_type_declaration, false); handleCommas(node.superInterfaceTypes(), this.options.insert_space_before_comma_in_superinterfaces, this.options.insert_space_after_comma_in_superinterfaces); return true; }
From source file:com.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*w ww .j a v a 2 s . c om*/ public boolean visit(TypeDeclaration node) { String hint = node.getName().getIdentifier(); int startLoc = node.getName().getStartPosition(); int endLoc = node.getStartPosition() + node.getLength() - 1; try { _container.add(new Hint("type", startLoc, endLoc, hint)); //$NON-NLS-1$ addBrackets(node.typeParameters()); } catch (BadLocationException e) { _cancelProcessing.set(true); } return shouldContinue(); }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.TypeDeclaration node) { ITypeBinding binding = node.resolveBinding(); // prepare name SimpleIdentifier name;//from w ww .ja v a 2 s .com { name = translateSimpleName(node.getName()); if (binding != null) { ITypeBinding declaringClass = binding.getDeclaringClass(); if (declaringClass != null) { context.putInnerClassName(name); name.setToken(token(TokenType.IDENTIFIER, declaringClass.getName() + "_" + name.getName())); } } } // interface Token abstractToken = null; if (node.isInterface() || org.eclipse.jdt.core.dom.Modifier.isAbstract(node.getModifiers())) { abstractToken = token(Keyword.ABSTRACT); } // type parameters TypeParameterList typeParams = null; { List<TypeParameter> typeParameters = Lists.newArrayList(); List<?> javaTypeParameters = node.typeParameters(); if (!javaTypeParameters.isEmpty()) { for (Iterator<?> I = javaTypeParameters.iterator(); I.hasNext();) { org.eclipse.jdt.core.dom.TypeParameter javaTypeParameter = (org.eclipse.jdt.core.dom.TypeParameter) I .next(); TypeParameter typeParameter = translate(javaTypeParameter); typeParameters.add(typeParameter); } typeParams = typeParameterList(typeParameters); } } // extends ExtendsClause extendsClause = null; if (node.getSuperclassType() != null) { TypeName superType = translate(node.getSuperclassType()); extendsClause = extendsClause(superType); } // implements ImplementsClause implementsClause = null; if (!node.superInterfaceTypes().isEmpty()) { List<TypeName> interfaces = Lists.newArrayList(); for (Object javaInterface : node.superInterfaceTypes()) { interfaces.add((TypeName) translate((org.eclipse.jdt.core.dom.ASTNode) javaInterface)); } implementsClause = implementsClause(interfaces); } // members List<ClassMember> members = translateBodyDeclarations(node.bodyDeclarations()); for (ClassMember member : members) { if (member instanceof ConstructorDeclaration) { ConstructorDeclaration constructor = (ConstructorDeclaration) member; constructor.setReturnType(name); } } // ClassDeclaration classDeclaration = new ClassDeclaration(translateJavadoc(node), null, abstractToken, null, name, typeParams, extendsClause, null, implementsClause, null, members, null); context.putNodeBinding(classDeclaration, binding); context.putNodeTypeBinding(classDeclaration, binding); context.putNodeTypeBinding(name, binding); return done(classDeclaration); }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link TypeDeclaration}s. */ @Override/*from ww w .j a v a 2s . c o m*/ public boolean visit(TypeDeclaration node) { sync(node); List<Op> breaks = visitModifiers(node.modifiers(), Direction.VERTICAL, Optional.<BreakTag>absent()); boolean hasSuperclassType = node.getSuperclassType() != null; boolean hasSuperInterfaceTypes = !node.superInterfaceTypes().isEmpty(); builder.open(ZERO); builder.addAll(breaks); token(node.isInterface() ? "interface" : "class"); builder.space(); visit(node.getName()); if (!node.typeParameters().isEmpty()) { visitTypeParameters(node.typeParameters(), hasSuperclassType || hasSuperInterfaceTypes ? plusFour : ZERO, BreakOrNot.YES); } if (hasSuperclassType || hasSuperInterfaceTypes) { builder.open(plusFour); if (hasSuperclassType) { builder.breakToFill(" "); token("extends"); // TODO(b/20761216): using a non-breaking space here could cause >100 char lines builder.space(); node.getSuperclassType().accept(this); } if (hasSuperInterfaceTypes) { builder.breakToFill(" "); builder.open(node.superInterfaceTypes().size() > 1 ? plusFour : ZERO); token(node.isInterface() ? "extends" : "implements"); builder.space(); boolean first = true; for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { if (!first) { token(","); builder.breakToFill(" "); } superInterfaceType.accept(this); first = false; } builder.close(); } builder.close(); } builder.close(); if (node.bodyDeclarations() == null) { token(";"); } else { addBodyDeclarations(node.bodyDeclarations(), BracesOrNot.YES, FirstDeclarationsOrNot.YES); builder.guessToken(";"); } return false; }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGenerator.java
License:Apache License
/** * Generate the Generics for this Interface. * /*from w w w. j a v a 2 s. co m*/ * @param clazz * the UML class * @param ast * the JDT Java AST * @param td * TypeDeclaration JDT */ @SuppressWarnings("unchecked") public void generateClassTemplateParams(Classifier clazz, AST ast, TypeDeclaration td) { TemplateSignature templateSignature = clazz.getOwnedTemplateSignature(); if (templateSignature != null) { EList<TemplateParameter> templateParameters = templateSignature.getParameters(); for (TemplateParameter templateParameter : templateParameters) { Classifier classifier = (Classifier) templateParameter.getOwnedParameteredElement(); String typeName = classifier.getLabel(); TypeParameter typeParameter = ast.newTypeParameter(); typeParameter.setName(ast.newSimpleName(typeName)); td.typeParameters().add(typeParameter); } } }