private void createSourceAnchorsForInterfaceInheritance(TypeDeclaration node, Type type) { if (!node.superInterfaceTypes().isEmpty()) node.superInterfaceTypes().stream().forEach(createSourceAnchorForInheritance(type)); }
private void getInterfaces(TypeDeclaration node) { if(node.superInterfaceTypes()!=null) { for(Object o : node.superInterfaceTypes()) { String interfaceName = ((Type)o).resolveBinding().getBinaryName(); interfaces.add(interfaceName); } } }
public static boolean isTypeSerializable(TypeDeclaration type) { List<Type> interfaces = type.superInterfaceTypes(); for (Type intf : interfaces) { String name = intf.toString().trim(); if (name.equals("Serializable") || name.equals("java.io.Serializable")) { return true; } } return false; }
/** * Add an interface to this class definition. * * @param type interface type */ public void addInterface(String type) { if (m_class instanceof TypeDeclaration) { ((TypeDeclaration)m_class).superInterfaceTypes().add(m_source.createType(type)); } else if (m_class instanceof EnumDeclaration) { ((EnumDeclaration)m_class).superInterfaceTypes().add(m_source.createType(type)); } else { // should not be possible, but just in case of added types in future throw new IllegalStateException("Internal error - interface not supported for class 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; }
@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); } }; }
@Override public boolean visit(TypeDeclaration node) { Type superClasses = node.getSuperclassType(); List<Type> superInterfaces = node.superInterfaceTypes(); processType(superClasses, "Extending class", SourceType.INHERITANCE); if (superInterfaces != null) { for (Type inter : superInterfaces) { processType(inter, "Implementing interface", SourceType.INHERITANCE); } } return true; }
public static void main(String[] args) { String source = "public interface A extends A_Super{}"; ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(source.toCharArray()); CompilationUnit cu = (CompilationUnit) parser.createAST(null); AST ast = cu.getAST(); TypeDeclaration td = (TypeDeclaration) cu.types().get(0); td.superInterfaceTypes().add(ast.newSimpleType(ast.newSimpleName("B"))); System.out.println(source); System.out.println(cu); }
@SuppressWarnings("unchecked") public String[] getSuperInterfaces() { if (superInterfaces == EMPTY_STRING_ARRAY) { superInterfaces = convertASTNodeListToStringArray(getASTNode().superInterfaceTypes()); } // add added super interfaces to the array superInterfaces = combineArrayAndList(superInterfaces, addedSuperInterfaces); return superInterfaces; }
@SuppressWarnings("unchecked") public String[] getSuperInterfaces() { if (superInterfaces == EMPTY_STRING_ARRAY) { superInterfaces = convertASTNodeListToStringArray(getASTNode().superInterfaceTypes()); } // add added super interfaces to the array superInterfaces = combineArrayAndList(superInterfaces, addedSuperInterfaces); return superInterfaces; }
private void setSuperInterface() { List<Type> superInterfaces = typeDeclaration.superInterfaceTypes(); if (superInterfaces != null) { for (Type superInterface : superInterfaces) { SM_Type inferredType = (new Resolver()).resolveType(superInterface, parentPkg.getParentProject()); if(inferredType != null) { superTypes.add(inferredType); inferredType.addThisAsChildToSuperType(this); } } } }
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; }
@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); } 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; }
@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(); }
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); } }
@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(); }
@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(); }
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(); }
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); } }