Refine search
public boolean isDummyType(final AbstractTypeDeclaration it) { if ((it instanceof TypeDeclaration)) { return (("MISSING".equals(((TypeDeclaration)it).getName().getIdentifier()) && (!((TypeDeclaration)it).isInterface())) && (((TypeDeclaration)it).getModifiers() == 0)); } return false; }
CompilationUnit cu = ast.newCompilationUnit(); PackageDeclaration p1 = ast.newPackageDeclaration(); p1.setName(ast.newSimpleName("foo")); cu.setPackage(p1); 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(); td.bodyDeclarations().add(md); Block block = ast.newBlock();
@Override public boolean visit(TypeDeclaration node) { push(node.isInterface() ? JavaNode.INTERFACE : JavaNode.CLASS, node.getName().toString(), node.getStartPosition(), node.getLength()); return true; }
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) { AST ast= typeDecl.getAST(); Javadoc javadoc= typeDecl.getJavadoc(); ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY); List<TypeParameter> typeParams= typeDecl.typeParameters(); for (int i= typeParams.size() - 1; i >= 0; i--) { TypeParameter decl= typeParams.get(i); String name= '<' + decl.getName().getIdentifier() + '>'; if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) { TagElement newTag= ast.newTagElement(); newTag.setTagName(TagElement.TAG_PARAM); TextElement text= ast.newTextElement(); text.setText(name); newTag.fragments().add(text); insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); //$NON-NLS-1$ insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl)); } } }
int treeSize() { return memSize() + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize()) + (this.modifiers == null ? 0 : this.modifiers.listSize()) + (this.typeName == null ? 0 : getName().treeSize()) + (this.typeParameters == null ? 0 : this.typeParameters.listSize()) + (this.optionalSuperclassName == null ? 0 : getSuperclass().treeSize()) + (this.optionalSuperclassType == null ? 0 : getSuperclassType().treeSize()) + (this.superInterfaceNames == null ? 0 : this.superInterfaceNames.listSize()) + (this.superInterfaceTypes == null ? 0 : this.superInterfaceTypes.listSize()) + this.bodyDeclarations.listSize(); } }
@SuppressWarnings("unchecked") @Override 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; }
/** * Returns name of the class, e.g. {@code FooBarBean} * * @param path path to java source file */ public static String getClassName(final Path path) { final CompilationUnit unit = getCompilationUnit(path); unit.recordModifications(); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); return classType.getName().getIdentifier(); }
private void createParameterClass(MethodDeclaration methodDeclaration, CompilationUnitRewrite cuRewrite) throws CoreException { if (fCreateAsTopLevel) { IPackageFragmentRoot root= (IPackageFragmentRoot) cuRewrite.getCu().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); fOtherChanges.addAll(fParameterObjectFactory.createTopLevelParameterObject(root)); } else { ASTRewrite rewriter= cuRewrite.getASTRewrite(); TypeDeclaration enclosingType= (TypeDeclaration) methodDeclaration.getParent(); ListRewrite bodyRewrite= rewriter.getListRewrite(enclosingType, TypeDeclaration.BODY_DECLARATIONS_PROPERTY); String fqn= enclosingType.getName().getFullyQualifiedName(); TypeDeclaration classDeclaration= fParameterObjectFactory.createClassDeclaration(fqn, cuRewrite, null); classDeclaration.modifiers().add(rewriter.getAST().newModifier(ModifierKeyword.PUBLIC_KEYWORD)); classDeclaration.modifiers().add(rewriter.getAST().newModifier(ModifierKeyword.STATIC_KEYWORD)); bodyRewrite.insertBefore(classDeclaration, methodDeclaration, null); } }
@Override public void endVisit(TypeDeclaration node) { if (skipNode(node)) { return; } GenericSequentialFlowInfo info = processSequential(node, node.getSuperclassType()); process(info, node.superInterfaceTypes()); process(info, node.bodyDeclarations()); info.setNoReturn(); }
final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == MODIFIERS2_PROPERTY) { return modifiers(); } if (property == TYPE_PARAMETERS_PROPERTY) { return typeParameters(); } if (property == SUPER_INTERFACES_PROPERTY) { return superInterfaces(); } if (property == SUPER_INTERFACE_TYPES_PROPERTY) { return superInterfaceTypes(); } if (property == BODY_DECLARATIONS_PROPERTY) { return bodyDeclarations(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); }
@SuppressWarnings("unchecked") @Test public void testGenerateClass() { AST ast = AST.newAST(AST.JLS3); CompilationUnit cu = ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); TypeDeclaration typeDeclaration = interfaceGenerator.generateClass( clazz, ast, cu); assertEquals(typeDeclaration.toString(), td.toString()); }
public boolean visit(TypeDeclaration node) { if (found(node, node.getName()) && this.resolveBinding) this.foundBinding = node.resolveBinding(); return true; }
@Override public boolean visit(TypeDeclaration node) { handleBodyDeclarations(node.bodyDeclarations()); if (node.getName().getStartPosition() == -1) return true; // this is a fake type created by parsing in class body mode breakLineBefore(node); handleBracedCode(node, node.getName(), this.options.brace_position_for_type_declaration, this.options.indent_body_declarations_compare_to_type_header); this.declarationModifierVisited = false; return true; }
@Override public boolean hasTypeVariable(String name) { TypeDeclaration type = (TypeDeclaration) body; List<TypeParameter> typeParameters = type.typeParameters(); for (TypeParameter typeParameter : typeParameters) { if (Strings.areEqual(name, typeParameter.getName().getIdentifier())) { return true; } } return false; }
public static ASTRewriteCorrectionProposal getMakeTypeAbstractProposal(ICompilationUnit cu, TypeDeclaration typeDeclaration, int relevance) { AST ast= typeDeclaration.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); Modifier newModifier= ast.newModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD); rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY).insertLast(newModifier, null); String label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_addabstract_description, typeDeclaration.getName().getIdentifier()); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, relevance, image); proposal.addLinkedPosition(rewrite.track(newModifier), true, "modifier"); //$NON-NLS-1$ return proposal; }
@SuppressWarnings("unchecked") private void generateConstructorDefault(Classifier clazz, AST ast, TypeDeclaration td) { MethodDeclaration constructor = ast.newMethodDeclaration(); constructor.setConstructor(true); constructor.setName(ast.newSimpleName(clazz.getName())); constructor.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); Block block = ast.newBlock(); constructor.setBody(block); td.bodyDeclarations().add(constructor); }
private static boolean isInterfaceOrAnnotation(ASTNode node) { boolean isInterface= (node instanceof TypeDeclaration) && ((TypeDeclaration) node).isInterface(); boolean isAnnotation= node instanceof AnnotationTypeDeclaration; return isInterface || isAnnotation; }
@SuppressWarnings("unchecked") public static Consumer<TypeDeclaration> superInterfaces(final List<String> types) { return td -> { final AST ast = td.getAST(); for (final String name : types) { final org.eclipse.jdt.core.dom.Type type = ast.newSimpleType(ast.newName(name)); td.superInterfaceTypes().add(type); } }; }
public boolean visit(TypeDeclaration typeDeclaration) { List<Type> supertypes = new ArrayList<Type>(); Type superclass = typeDeclaration.getSuperclassType(); if (superclass != null) { supertypes.add(superclass); } supertypes.addAll(typeDeclaration.superInterfaceTypes()); SDType sdType = visitTypeDeclaration(typeDeclaration, supertypes); containerStack.push(sdType); sdType.setIsInterface(typeDeclaration.isInterface()); return true; }
private boolean isFinalClassWithoutInheritance(ASTNode node) { if (node instanceof TypeDeclaration) { TypeDeclaration clazz = (TypeDeclaration) node; return isFinalClass(clazz) && clazz.superInterfaceTypes().isEmpty() && (clazz.getSuperclassType() == null || hasType(clazz.getSuperclassType().resolveBinding(), "java.lang.Object")); } return false; }