/** * Set the superclass for this class. * * @param name superclass name */ public void setSuperclass(String name) { if (m_class instanceof TypeDeclaration) { ((TypeDeclaration)m_class).setSuperclassType(createType(name)); } else { throw new IllegalStateException("Internal error - can't set superclass on an enum or other special type"); } }
public static Consumer<TypeDeclaration> superClass(final String name) { return td -> { final AST ast = td.getAST(); final org.eclipse.jdt.core.dom.Type type = ast.newSimpleType(ast.newName(name)); td.setSuperclassType(type); }; }
private void setSuperType(TypeDeclaration declaration) { ClassInstanceCreation classInstanceCreation= (ClassInstanceCreation) fAnonymousInnerClassNode.getParent(); ITypeBinding binding= classInstanceCreation.resolveTypeBinding(); if (binding == null) return; Type newType= (Type) ASTNode.copySubtree(fAnonymousInnerClassNode.getAST(), classInstanceCreation.getType()); if (binding.getSuperclass().getQualifiedName().equals("java.lang.Object")) { //$NON-NLS-1$ Assert.isTrue(binding.getInterfaces().length <= 1); if (binding.getInterfaces().length == 0) return; declaration.superInterfaceTypes().add(0, newType); } else { declaration.setSuperclassType(newType); } }
private void setSuperType(TypeDeclaration declaration) throws JavaModelException { ClassInstanceCreation classInstanceCreation= (ClassInstanceCreation) fAnonymousInnerClassNode.getParent(); ITypeBinding binding= classInstanceCreation.resolveTypeBinding(); if (binding == null) return; Type newType= (Type) ASTNode.copySubtree(fAnonymousInnerClassNode.getAST(), classInstanceCreation.getType()); if (binding.getSuperclass().getQualifiedName().equals("java.lang.Object")) { //$NON-NLS-1$ Assert.isTrue(binding.getInterfaces().length <= 1); if (binding.getInterfaces().length == 0) return; declaration.superInterfaceTypes().add(0, newType); } else { declaration.setSuperclassType(newType); } }
private void setSuperType(TypeDeclaration declaration) { ClassInstanceCreation classInstanceCreation= (ClassInstanceCreation) fAnonymousInnerClassNode.getParent(); ITypeBinding binding= classInstanceCreation.resolveTypeBinding(); if (binding == null) return; Type newType= (Type) ASTNode.copySubtree(fAnonymousInnerClassNode.getAST(), classInstanceCreation.getType()); if (binding.getSuperclass().getQualifiedName().equals("java.lang.Object")) { //$NON-NLS-1$ Assert.isTrue(binding.getInterfaces().length <= 1); if (binding.getInterfaces().length == 0) return; declaration.superInterfaceTypes().add(0, newType); } else { declaration.setSuperclassType(newType); } }
/** * Adds extends keyword to a class. If class already extends another class it will silently fail * * @param path path of java bean * @param extendingClassName name of the class bean is extending */ public static void addExtendsClass(final Path path, final String extendingClassName) { final CompilationUnit unit = getCompilationUnit(path); unit.recordModifications(); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); final AST ast = unit.getAST(); final Type superclassType = classType.getSuperclassType(); if (superclassType == null) { classType.setSuperclassType(ast.newSimpleType(ast.newSimpleName(extendingClassName))); final String rewrite = rewrite(unit, ast); GlobalUtils.writeToFile(rewrite, path); } }
/** * Adds extends keyword to a class. If class already extends another class it will silently fail * * @param path path of java bean * @param extendingClassName name of the class bean is extending */ public static void addExtendsClass(final Path path, final String extendingClassName) { final CompilationUnit unit = getCompilationUnit(path); unit.recordModifications(); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); final AST ast = unit.getAST(); final Type superclassType = classType.getSuperclassType(); if (superclassType == null) { classType.setSuperclassType(ast.newSimpleType(ast.newSimpleName(extendingClassName))); final String rewrite = rewrite(unit, ast); GlobalUtils.writeToFile(rewrite, path); } }
/** * Writes a component * * @param info component information * @param context plugin context * @return path of created file */ public static Path writeEssentialsComponent(final ComponentInformation info, final PluginContext context) { final File siteDirectory = context.getSiteDirectory(); final String sitePath = siteDirectory.getAbsolutePath(); final Path path = createJavaClass(sitePath, info.getTargetClassName(), info.getTargetPackageName(), EssentialConst.FILE_EXTENSION_JAVA); final CompilationUnit unit = getCompilationUnit(path); unit.recordModifications(); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); final AST ast = unit.getAST(); unit.getPackage().setName(ast.newName(DOT_SPLITTER.split(info.getTargetPackageName()))); // import declaration essentials: final List<String> imports = info.getImports(); for (String anImport : imports) { addImport(unit, ast, anImport); } // add extends: classType.setSuperclassType(ast.newSimpleType(ast.newSimpleName(info.getExtendingComponentName()))); addHippoGeneratedAnnotation(info.getTargetClassName(), unit, classType, ast); replaceFile(path, unit, ast); return path; }
/** * Writes a component * * @param info component information * @param context plugin context * @return path of created file */ public static Path writeEssentialsComponent(final ComponentInformation info, final PluginContext context) { final File siteDirectory = context.getSiteDirectory(); final String sitePath = siteDirectory.getAbsolutePath(); final Path path = createJavaClass(sitePath, info.getTargetClassName(), info.getTargetPackageName(), EssentialConst.FILE_EXTENSION_JAVA); final CompilationUnit unit = getCompilationUnit(path); unit.recordModifications(); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); final AST ast = unit.getAST(); unit.getPackage().setName(ast.newName(DOT_SPLITTER.split(info.getTargetPackageName()))); // import declaration essentials: final List<String> imports = info.getImports(); for (String anImport : imports) { addImport(unit, ast, anImport); } // add extends: classType.setSuperclassType(ast.newSimpleType(ast.newSimpleName(info.getExtendingComponentName()))); addHippoGeneratedAnnotation(info.getTargetClassName(), unit, classType, ast); replaceFile(path, unit, ast); return path; }
return getSuperclassType(); } else { setSuperclassType((Type) child); return null;
return getSuperclassType(); } else { setSuperclassType((Type) child); return null;
return getSuperclassType(); } else { setSuperclassType((Type) child); return null;
return getSuperclassType(); } else { setSuperclassType((Type) child); return null;
return getSuperclassType(); } else { setSuperclassType((Type) child); return null;
ASTNode clone0(AST target) { TypeDeclaration result = new TypeDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.internalSetModifiers(getModifiers()); result.setSuperclass( (Name) ASTNode.copySubtree(target, getSuperclass())); result.superInterfaces().addAll( ASTNode.copySubtrees(target, superInterfaces())); } result.setInterface(isInterface()); result.setName((SimpleName) getName().clone(target)); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.typeParameters().addAll( ASTNode.copySubtrees(target, typeParameters())); result.setSuperclassType( (Type) ASTNode.copySubtree(target, getSuperclassType())); result.superInterfaceTypes().addAll( ASTNode.copySubtrees(target, superInterfaceTypes())); } result.bodyDeclarations().addAll( ASTNode.copySubtrees(target, bodyDeclarations())); return result; }
@Override ASTNode clone0(AST target) { TypeDeclaration result = new TypeDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.internalSetModifiers(getModifiers()); result.setSuperclass( (Name) ASTNode.copySubtree(target, getSuperclass())); result.superInterfaces().addAll( ASTNode.copySubtrees(target, superInterfaces())); } result.setInterface(isInterface()); result.setName((SimpleName) getName().clone(target)); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.typeParameters().addAll( ASTNode.copySubtrees(target, typeParameters())); result.setSuperclassType( (Type) ASTNode.copySubtree(target, getSuperclassType())); result.superInterfaceTypes().addAll( ASTNode.copySubtrees(target, superInterfaceTypes())); } result.bodyDeclarations().addAll( ASTNode.copySubtrees(target, bodyDeclarations())); return result; }
ASTNode clone0(AST target) { TypeDeclaration result = new TypeDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.internalSetModifiers(getModifiers()); result.setSuperclass( (Name) ASTNode.copySubtree(target, getSuperclass())); result.superInterfaces().addAll( ASTNode.copySubtrees(target, superInterfaces())); } result.setInterface(isInterface()); result.setName((SimpleName) getName().clone(target)); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.typeParameters().addAll( ASTNode.copySubtrees(target, typeParameters())); result.setSuperclassType( (Type) ASTNode.copySubtree(target, getSuperclassType())); result.superInterfaceTypes().addAll( ASTNode.copySubtrees(target, superInterfaceTypes())); } result.bodyDeclarations().addAll( ASTNode.copySubtrees(target, bodyDeclarations())); return result; }
ASTNode clone0(AST target) { TypeDeclaration result = new TypeDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.internalSetModifiers(getModifiers()); result.setSuperclass( (Name) ASTNode.copySubtree(target, getSuperclass())); result.superInterfaces().addAll( ASTNode.copySubtrees(target, superInterfaces())); } result.setInterface(isInterface()); result.setName((SimpleName) getName().clone(target)); if (this.ast.apiLevel >= AST.JLS3) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.typeParameters().addAll( ASTNode.copySubtrees(target, typeParameters())); result.setSuperclassType( (Type) ASTNode.copySubtree(target, getSuperclassType())); result.superInterfaceTypes().addAll( ASTNode.copySubtrees(target, superInterfaceTypes())); } result.bodyDeclarations().addAll( ASTNode.copySubtrees(target, bodyDeclarations())); return result; }
ASTNode clone0(AST target) { TypeDeclaration result = new TypeDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.internalSetModifiers(getModifiers()); result.setSuperclass( (Name) ASTNode.copySubtree(target, getSuperclass())); result.superInterfaces().addAll( ASTNode.copySubtrees(target, superInterfaces())); } result.setInterface(isInterface()); result.setName((SimpleName) getName().clone(target)); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.typeParameters().addAll( ASTNode.copySubtrees(target, typeParameters())); result.setSuperclassType( (Type) ASTNode.copySubtree(target, getSuperclassType())); result.superInterfaceTypes().addAll( ASTNode.copySubtrees(target, superInterfaceTypes())); } result.bodyDeclarations().addAll( ASTNode.copySubtrees(target, bodyDeclarations())); return result; }
ASTNode clone0(AST target) { TypeDeclaration result = new TypeDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.internalSetModifiers(getModifiers()); result.setSuperclass( (Name) ASTNode.copySubtree(target, getSuperclass())); result.superInterfaces().addAll( ASTNode.copySubtrees(target, superInterfaces())); } result.setInterface(isInterface()); result.setName((SimpleName) getName().clone(target)); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.typeParameters().addAll( ASTNode.copySubtrees(target, typeParameters())); result.setSuperclassType( (Type) ASTNode.copySubtree(target, getSuperclassType())); result.superInterfaceTypes().addAll( ASTNode.copySubtrees(target, superInterfaceTypes())); } result.bodyDeclarations().addAll( ASTNode.copySubtrees(target, bodyDeclarations())); return result; }