Java Code Examples for org.eclipse.jdt.core.dom.TypeDeclaration#getSuperclassType()

The following examples show how to use org.eclipse.jdt.core.dom.TypeDeclaration#getSuperclassType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileVisitor.java    From repositoryminer with Apache License 2.0 6 votes vote down vote up
@Override
public boolean visit(TypeDeclaration node) {
	AbstractClass clazz = new AbstractClass();
	if (node.getSuperclassType() != null) {
		ITypeBinding bind = node.getSuperclassType().resolveBinding();
		clazz.setSuperClass(bind.getQualifiedName());
	}

	clazz.setInterface(node.isInterface());
	if (packageName != null) {
		clazz.setName(packageName+'.'+node.getName().getFullyQualifiedName());
	} else {
		clazz.setName(node.getName().getFullyQualifiedName());
	}

	TypeVisitor visitor = new TypeVisitor();
	node.accept(visitor);

	clazz.setMethods(visitor.getMethods());
	clazz.setStartPosition(node.getStartPosition());
	clazz.setEndPosition(node.getStartPosition() + node.getLength() - 1);
	clazz.setFields(visitor.getFields());
	
	types.add(clazz);
	return true;
}
 
Example 2
Source File: RefactoringUtility.java    From JDeodorant with MIT License 6 votes vote down vote up
public static TypeDeclaration findDeclaringTypeDeclaration(IMethodBinding methodBinding, TypeDeclaration typeDeclaration) {
	if(typeDeclaration.resolveBinding().isEqualTo(methodBinding.getDeclaringClass())) {
		return typeDeclaration;
	}
	//method was not found in typeDeclaration
	Type superclassType = typeDeclaration.getSuperclassType();
	if(superclassType != null) {
		String superclassQualifiedName = superclassType.resolveBinding().getQualifiedName();
		SystemObject system = ASTReader.getSystemObject();
		ClassObject superclassObject = system.getClassObject(superclassQualifiedName);
		if(superclassObject != null) {
			AbstractTypeDeclaration superclassTypeDeclaration = superclassObject.getAbstractTypeDeclaration();
			if(superclassTypeDeclaration instanceof TypeDeclaration) {
				return findDeclaringTypeDeclaration(methodBinding, (TypeDeclaration)superclassTypeDeclaration);
			}
		}
	}
	return null;
}
 
Example 3
Source File: RefactoringUtility.java    From JDeodorant with MIT License 6 votes vote down vote up
public static TypeDeclaration findDeclaringTypeDeclaration(IVariableBinding variableBinding, TypeDeclaration typeDeclaration) {
	if(typeDeclaration.resolveBinding().isEqualTo(variableBinding.getDeclaringClass())) {
		return typeDeclaration;
	}
	//fragment was not found in typeDeclaration
	Type superclassType = typeDeclaration.getSuperclassType();
	if(superclassType != null) {
		String superclassQualifiedName = superclassType.resolveBinding().getQualifiedName();
		SystemObject system = ASTReader.getSystemObject();
		ClassObject superclassObject = system.getClassObject(superclassQualifiedName);
		if(superclassObject != null) {
			AbstractTypeDeclaration superclassTypeDeclaration = superclassObject.getAbstractTypeDeclaration();
			if(superclassTypeDeclaration instanceof TypeDeclaration) {
				return findDeclaringTypeDeclaration(variableBinding, (TypeDeclaration)superclassTypeDeclaration);
			}
		}
	}
	return null;
}
 
Example 4
Source File: PlantUmlPreCompiler.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(TypeDeclaration decl) {
	if (decl.getName().toString().equals(seqDiagramName)) {
		superClass = null;
		Type sc = decl.getSuperclassType();

		if (sc != null) {
			String scName = sc.resolveBinding().getQualifiedName().toString();

			if (!scName.equals("hu.elte.txtuml.api.model.seqdiag.Interaction")
					&& !scName.equals("hu.elte.txtuml.api.model.seqdiag.SequenceDiagram")) {
				superClass = sc;
			}
		}
		return true;
	}
	return false;
}
 
Example 5
Source File: RefactoringUtility.java    From JDeodorant with MIT License 6 votes vote down vote up
public static MethodDeclaration findGetterDeclarationForField(VariableDeclaration variableDeclaration, TypeDeclaration typeDeclaration) {
	for(MethodDeclaration methodDeclaration : typeDeclaration.getMethods()) {
		SimpleName simpleName = MethodDeclarationUtility.isGetter(methodDeclaration);
		if(simpleName != null && variableDeclaration.resolveBinding().isEqualTo(simpleName.resolveBinding())) {
			return methodDeclaration;
		}
	}
	//fragment was not found in typeDeclaration
	Type superclassType = typeDeclaration.getSuperclassType();
	if(superclassType != null) {
		String superclassQualifiedName = superclassType.resolveBinding().getQualifiedName();
		SystemObject system = ASTReader.getSystemObject();
		ClassObject superclassObject = system.getClassObject(superclassQualifiedName);
		if(superclassObject != null) {
			AbstractTypeDeclaration superclassTypeDeclaration = superclassObject.getAbstractTypeDeclaration();
			if(superclassTypeDeclaration instanceof TypeDeclaration) {
				return findGetterDeclarationForField(variableDeclaration, (TypeDeclaration)superclassTypeDeclaration);
			}
		}
	}
	return null;
}
 
Example 6
Source File: RefactoringUtility.java    From JDeodorant with MIT License 6 votes vote down vote up
public static VariableDeclaration findFieldDeclaration(AbstractVariable variable, TypeDeclaration typeDeclaration) {
	for(FieldDeclaration fieldDeclaration : typeDeclaration.getFields()) {
		List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
		for(VariableDeclarationFragment fragment : fragments) {
			if(variable.getVariableBindingKey().equals(fragment.resolveBinding().getKey())) {
				return fragment;
			}
		}
	}
	//fragment was not found in typeDeclaration
	Type superclassType = typeDeclaration.getSuperclassType();
	if(superclassType != null) {
		String superclassQualifiedName = superclassType.resolveBinding().getQualifiedName();
		SystemObject system = ASTReader.getSystemObject();
		ClassObject superclassObject = system.getClassObject(superclassQualifiedName);
		if(superclassObject != null) {
			AbstractTypeDeclaration superclassTypeDeclaration = superclassObject.getAbstractTypeDeclaration();
			if(superclassTypeDeclaration instanceof TypeDeclaration) {
				return findFieldDeclaration(variable, (TypeDeclaration)superclassTypeDeclaration);
			}
		}
	}
	return null;
}
 
Example 7
Source File: JavaASTVisitor.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
private boolean visitClass(TypeDeclaration node) {

        ClassInfo classInfo = new ClassInfo();
        classInfo.name = node.getName().getFullyQualifiedName();
        classInfo.fullName = NameResolver.getFullName(node);
        classInfo.visibility = getVisibility(node);
        classInfo.isAbstract = isAbstract(node);
        classInfo.isFinal = isFinal(node);
        classInfo.superClassType = node.getSuperclassType() == null ? "java.lang.Object" : NameResolver.getFullName(node.getSuperclassType());
        List<Type> superInterfaceList = node.superInterfaceTypes();
        for (Type superInterface : superInterfaceList)
            classInfo.superInterfaceTypeList.add(NameResolver.getFullName(superInterface));
        if (node.getJavadoc() != null)
            classInfo.comment = sourceContent.substring(node.getJavadoc().getStartPosition(), node.getJavadoc().getStartPosition() + node.getJavadoc().getLength());
        classInfo.content = sourceContent.substring(node.getStartPosition(), node.getStartPosition() + node.getLength());
        elementInfoPool.classInfoMap.put(classInfo.fullName, classInfo);

        MethodDeclaration[] methodDeclarations = node.getMethods();
        for (MethodDeclaration methodDeclaration : methodDeclarations) {
            MethodInfo methodInfo = createMethodInfo(methodDeclaration, classInfo.fullName);
            elementInfoPool.methodInfoMap.put(methodInfo.hashName(), methodInfo);
        }

        FieldDeclaration[] fieldDeclarations = node.getFields();
        for (FieldDeclaration fieldDeclaration : fieldDeclarations) {
            List<FieldInfo> fieldInfos = createFieldInfos(fieldDeclaration, classInfo.fullName);
            for (FieldInfo fieldInfo : fieldInfos)
                elementInfoPool.fieldInfoMap.put(fieldInfo.hashName(), fieldInfo);
        }
        return true;
    }
 
Example 8
Source File: TypeParseVisitor.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
public boolean visit(TypeDeclaration node) {
	Pair<String, String> clazzAndMethodName = NodeUtils.getTypeDecAndMethodDec(node.getName());
	String clazz = clazzAndMethodName.getFirst();
	AST ast = AST.newAST(AST.JLS8);
	Type type = ast.newSimpleType(ast.newSimpleName(clazz));
	ProjectInfo.addFieldType(clazz, "THIS", type);
	Type suType = node.getSuperclassType();
	if(suType != null){
		ProjectInfo.addFieldType(clazz, "SUPER", suType);
		ProjectInfo.addSuperClass(clazz, suType.toString());
	}
	
	List<Object> sInterfaces = node.superInterfaceTypes();
	if(sInterfaces != null){
		for(Object object : sInterfaces){
			if(object instanceof Type){
				Type interfaceType = (Type) object;
				ProjectInfo.addSuperInterface(clazz, interfaceType.toString());
			}
		}
	}
	
	FieldDeclaration fields[] = node.getFields();
	for (FieldDeclaration f : fields) {
		for (Object o : f.fragments()) {
			VariableDeclarationFragment vdf = (VariableDeclarationFragment) o;
			Type tmpType = f.getType();
			if(vdf.getExtraDimensions() > 0){
				tmpType = ast.newArrayType((Type) ASTNode.copySubtree(ast, tmpType), vdf.getExtraDimensions());
			}
			ProjectInfo.addFieldType(clazz, vdf.getName().toString(), tmpType);
		}
	}
	return true;
}
 
Example 9
Source File: ExtractSupertypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new type signature of a subtype.
 *
 * @param subRewrite
 *            the compilation unit rewrite of a subtype
 * @param declaration
 *            the type declaration of a subtype
 * @param extractedType
 *            the extracted super type
 * @param extractedBinding
 *            the binding of the extracted super type
 * @param monitor
 *            the progress monitor to use
 * @throws JavaModelException
 *             if the type parameters cannot be retrieved
 */
protected final void createTypeSignature(final CompilationUnitRewrite subRewrite, final AbstractTypeDeclaration declaration, final IType extractedType, final ITypeBinding extractedBinding, final IProgressMonitor monitor) throws JavaModelException {
	Assert.isNotNull(subRewrite);
	Assert.isNotNull(declaration);
	Assert.isNotNull(extractedType);
	Assert.isNotNull(monitor);
	try {
		monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 10);
		final AST ast= subRewrite.getAST();
		Type type= null;
		if (extractedBinding != null) {
			type= subRewrite.getImportRewrite().addImport(extractedBinding, ast);
		} else {
			subRewrite.getImportRewrite().addImport(extractedType.getFullyQualifiedName('.'));
			type= ast.newSimpleType(ast.newSimpleName(extractedType.getElementName()));
		}
		subRewrite.getImportRemover().registerAddedImport(extractedType.getFullyQualifiedName('.'));
		if (type != null) {
			final ITypeParameter[] parameters= extractedType.getTypeParameters();
			if (parameters.length > 0) {
				final ParameterizedType parameterized= ast.newParameterizedType(type);
				for (int index= 0; index < parameters.length; index++)
					parameterized.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getElementName())));
				type= parameterized;
			}
		}
		final ASTRewrite rewriter= subRewrite.getASTRewrite();
		if (type != null && declaration instanceof TypeDeclaration) {
			final TypeDeclaration extended= (TypeDeclaration) declaration;
			final Type superClass= extended.getSuperclassType();
			if (superClass != null) {
				rewriter.replace(superClass, type, subRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.ExtractSupertypeProcessor_add_supertype, SET_EXTRACT_SUPERTYPE));
				subRewrite.getImportRemover().registerRemovedNode(superClass);
			} else
				rewriter.set(extended, TypeDeclaration.SUPERCLASS_TYPE_PROPERTY, type, subRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.ExtractSupertypeProcessor_add_supertype, SET_EXTRACT_SUPERTYPE));
		}
	} finally {
		monitor.done();
	}
}
 
Example 10
Source File: ExtractSupertypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the type signature of the extracted supertype.
 *
 * @param targetRewrite
 *            the target compilation unit rewrite
 * @param superType
 *            the super type, or <code>null</code> if no super type (ie.
 *            <code>java.lang.Object</code>) is available
 * @param declaringDeclaration
 *            the declaration of the declaring type
 * @param targetDeclaration
 *            the type declaration of the target type
 */
protected final void createTypeSignature(final CompilationUnitRewrite targetRewrite, final IType superType, final AbstractTypeDeclaration declaringDeclaration, final AbstractTypeDeclaration targetDeclaration) {
	Assert.isNotNull(targetRewrite);
	Assert.isNotNull(declaringDeclaration);
	Assert.isNotNull(targetDeclaration);
	if (declaringDeclaration instanceof TypeDeclaration) {
		final TypeDeclaration declaration= (TypeDeclaration) declaringDeclaration;
		final Type superclassType= declaration.getSuperclassType();
		if (superclassType != null) {
			Type type= null;
			final ITypeBinding binding= superclassType.resolveBinding();
			if (binding != null) {
				type= targetRewrite.getImportRewrite().addImport(binding, targetRewrite.getAST());
				targetRewrite.getImportRemover().registerAddedImports(type);
			}
			if (type != null && targetDeclaration instanceof TypeDeclaration) {
				final TypeDeclaration extended= (TypeDeclaration) targetDeclaration;
				final Type targetSuperType= extended.getSuperclassType();
				if (targetSuperType != null) {
					targetRewrite.getASTRewrite().replace(targetSuperType, type, null);
				} else {
					targetRewrite.getASTRewrite().set(extended, TypeDeclaration.SUPERCLASS_TYPE_PROPERTY, type, null);
				}
			}
		}
	}
}
 
Example 11
Source File: JavaTypeHierarchyExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean visit(final TypeDeclaration node) {
	for (final Object supType : node.superInterfaceTypes()) {
		Type superType = (Type) supType;
		if (superType.isParameterizedType()) {
			superType = ((ParameterizedType) superType).getType();
		}
		final String qName = superType.resolveBinding().getErasure()
				.getQualifiedName();
		if (className.isEmpty()) {
			addTypes(qName, currentPackageName + "." + node.getName());
		} else {
			addTypes(qName, className.peek() + "." + node.getName());
		}
	}

	Type superclassType = node.getSuperclassType();
	if (superclassType != null) {
		if (superclassType.isParameterizedType()) {
			superclassType = ((ParameterizedType) superclassType)
					.getType();
		}
		addTypes(superclassType.resolveBinding().getQualifiedName(),
				currentPackageName + "." + node.getName());
	}

	if (className.isEmpty()) {
		className.push(currentPackageName + "."
				+ node.getName().getIdentifier());
		importedNames.put(node.getName().getIdentifier(),
				currentPackageName + "."
						+ node.getName().getIdentifier());
	} else {
		className.push(className.peek() + "."
				+ node.getName().getIdentifier());
		importedNames
				.put(node.getName().getIdentifier(), className.peek()
						+ "." + node.getName().getIdentifier());
	}
	return true;
}
 
Example 12
Source File: JavaTypeHierarchyExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean visit(final TypeDeclaration node) {
	for (final Object supType : node.superInterfaceTypes()) {
		Type superType = (Type) supType;
		if (superType.isParameterizedType()) {
			superType = ((ParameterizedType) superType).getType();
		}
		final String qName = superType.resolveBinding().getErasure()
				.getQualifiedName();
		if (className.isEmpty()) {
			addTypes(qName, currentPackageName + "." + node.getName());
		} else {
			addTypes(qName, className.peek() + "." + node.getName());
		}
	}

	Type superclassType = node.getSuperclassType();
	if (superclassType != null) {
		if (superclassType.isParameterizedType()) {
			superclassType = ((ParameterizedType) superclassType)
					.getType();
		}
		addTypes(superclassType.resolveBinding().getQualifiedName(),
				currentPackageName + "." + node.getName());
	}

	if (className.isEmpty()) {
		className.push(currentPackageName + "."
				+ node.getName().getIdentifier());
		importedNames.put(node.getName().getIdentifier(),
				currentPackageName + "."
						+ node.getName().getIdentifier());
	} else {
		className.push(className.peek() + "."
				+ node.getName().getIdentifier());
		importedNames
				.put(node.getName().getIdentifier(), className.peek()
						+ "." + node.getName().getIdentifier());
	}
	return true;
}
 
Example 13
Source File: AstVisitor.java    From jdt2famix with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean visit(TypeDeclaration node) {
	ITypeBinding binding = node.resolveBinding();
	if (binding == null) {
		logNullBinding("type declaration", node.getName(),
				((CompilationUnit) node.getRoot()).getLineNumber(node.getStartPosition()));
		return false;
	}
	Type type = importer.ensureTypeFromTypeBinding(binding);

	org.eclipse.jdt.core.dom.Type superclassType = node.getSuperclassType();
	/*
	 * This is an ugly patch. When the binding to the superclass or super interfaces
	 * cannot be resolved, we try to recover as much info as possible We do it here
	 * because it is hard to pass around the dom type
	 */
	if (binding.getSuperclass() == null && superclassType != null)
		importer.createInheritanceFromSubtypeToSuperDomType(type, superclassType);

	if (superclassType != null)
		type.getSuperInheritances().stream().filter(inheritance -> (inheritance.getSuperclass() instanceof Class
				&& !((Class) inheritance.getSuperclass()).getIsInterface())
				|| (inheritance.getSuperclass() instanceof ParameterizedType
						&& ((ParameterizedType) inheritance.getSuperclass()).getParameterizableClass() != null
						&& !((ParameterizedType) inheritance.getSuperclass()).getParameterizableClass()
								.getIsInterface()))
				.findFirst().ifPresent(in -> importer.createLightweightSourceAnchor(in, superclassType));

	if (binding.getInterfaces().length == 0 && !node.superInterfaceTypes().isEmpty())
		node.superInterfaceTypes().stream().forEach(t -> {
			importer.createInheritanceFromSubtypeToSuperDomType(type, (org.eclipse.jdt.core.dom.Type) t);
		});

	// create source anchors for implemented interfaces references
	createSourceAnchorsForInterfaceInheritance(node, type);

	type.setIsStub(false);
	importer.createSourceAnchor(type, node);
	importer.createLightweightSourceAnchor(type, node.getName());
	importer.ensureCommentFromBodyDeclaration(type, node);
	importer.pushOnContainerStack(type);
	return true;
}
 
Example 14
Source File: JavaTypeHierarchyExtractor.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean visit(final TypeDeclaration node) {
	for (final Object supType : node.superInterfaceTypes()) {
		Type superType = (Type) supType;
		if (superType.isParameterizedType()) {
			superType = ((ParameterizedType) superType).getType();
		}
		final String qName = superType.resolveBinding().getErasure()
				.getQualifiedName();
		if (className.isEmpty()) {
			addTypes(qName, currentPackageName + "." + node.getName());
		} else {
			addTypes(qName, className.peek() + "." + node.getName());
		}
	}

	Type superclassType = node.getSuperclassType();
	if (superclassType != null) {
		if (superclassType.isParameterizedType()) {
			superclassType = ((ParameterizedType) superclassType)
					.getType();
		}
		addTypes(superclassType.resolveBinding().getQualifiedName(),
				currentPackageName + "." + node.getName());
	}

	if (className.isEmpty()) {
		className.push(currentPackageName + "."
				+ node.getName().getIdentifier());
		importedNames.put(node.getName().getIdentifier(),
				currentPackageName + "."
						+ node.getName().getIdentifier());
	} else {
		className.push(className.peek() + "."
				+ node.getName().getIdentifier());
		importedNames
				.put(node.getName().getIdentifier(), className.peek()
						+ "." + node.getName().getIdentifier());
	}
	return true;
}
 
Example 15
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean visit(final TypeDeclaration it) {
  boolean _isDummyType = this._aSTFlattenerUtils.isDummyType(it);
  if (_isDummyType) {
    this.visitAll(it.bodyDeclarations(), this.nl());
    return false;
  }
  boolean _isNotSupportedInnerType = this._aSTFlattenerUtils.isNotSupportedInnerType(it);
  if (_isNotSupportedInnerType) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/* FIXME Non-static inner classes are not supported.*/");
    this.appendToBuffer(_builder.toString());
    this.addProblem(it, "Non-static inner classes are not supported.");
  }
  Javadoc _javadoc = it.getJavadoc();
  boolean _tripleNotEquals = (_javadoc != null);
  if (_tripleNotEquals) {
    it.getJavadoc().accept(this);
  }
  this.appendModifiers(it, it.modifiers());
  boolean _isInterface = it.isInterface();
  if (_isInterface) {
    this.appendToBuffer("interface ");
  } else {
    boolean _isPackageVisibility = this._aSTFlattenerUtils.isPackageVisibility(Iterables.<Modifier>filter(it.modifiers(), Modifier.class));
    if (_isPackageVisibility) {
      this.appendToBuffer("package ");
    }
    this.appendToBuffer("class ");
  }
  it.getName().accept(this);
  boolean _isEmpty = it.typeParameters().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    this.appendTypeParameters(it.typeParameters());
  }
  this.appendSpaceToBuffer();
  Type _superclassType = it.getSuperclassType();
  boolean _tripleNotEquals_1 = (_superclassType != null);
  if (_tripleNotEquals_1) {
    this.appendToBuffer("extends ");
    it.getSuperclassType().accept(this);
    this.appendSpaceToBuffer();
  }
  boolean _isEmpty_1 = it.superInterfaceTypes().isEmpty();
  boolean _not_1 = (!_isEmpty_1);
  if (_not_1) {
    boolean _isInterface_1 = it.isInterface();
    if (_isInterface_1) {
      this.appendToBuffer("extends ");
    } else {
      this.appendToBuffer("implements ");
    }
    this.visitAllSeparatedByComma(it.superInterfaceTypes());
  }
  this.appendToBuffer("{");
  this.increaseIndent();
  BodyDeclaration prev = null;
  List _bodyDeclarations = it.bodyDeclarations();
  for (final BodyDeclaration body : ((Iterable<BodyDeclaration>) _bodyDeclarations)) {
    {
      if ((prev instanceof EnumConstantDeclaration)) {
        if ((body instanceof EnumConstantDeclaration)) {
          this.appendToBuffer(", ");
        } else {
          this.appendToBuffer("; ");
        }
      }
      this.appendLineWrapToBuffer();
      body.accept(this);
      prev = body;
    }
  }
  ASTNode _root = it.getRoot();
  if ((_root instanceof CompilationUnit)) {
    ASTNode _root_1 = it.getRoot();
    final CompilationUnit cu = ((CompilationUnit) _root_1);
    final Consumer<Comment> _function = (Comment it_1) -> {
      it_1.accept(this);
      this.assignedComments.add(it_1);
    };
    this.unAssignedComments(cu).forEach(_function);
  }
  this.decreaseIndent();
  this.appendLineWrapToBuffer();
  this.appendToBuffer("}");
  return false;
}
 
Example 16
Source File: ClassParser.java    From aDoctor with MIT License 4 votes vote down vote up
public static ClassBean parse(TypeDeclaration pClassNode, String belongingPackage, List<String> imports) {
    int numberOfGetterOrSetter = 0;

    // Instantiate the bean
    ClassBean classBean = new ClassBean();

    if (pClassNode.getSuperclassType() != null) {
        classBean.setSuperclass(pClassNode.getSuperclassType().toString());
    } else {
        classBean.setSuperclass(null);
    }

    // Set the name
    classBean.setName(pClassNode.getName().toString());
    classBean.setImports(imports);
    classBean.setBelongingPackage(belongingPackage);

    // Get the instance variable nodes 
    Collection<FieldDeclaration> instanceVariableNodes = new ArrayList<>();
    pClassNode.accept(new InstanceVariableVisitor(instanceVariableNodes));

    classBean.setTextContent(pClassNode.toString());

    Pattern newLine = Pattern.compile("\n");
    String[] lines = newLine.split(pClassNode.toString());

    classBean.setLOC(lines.length);

    // Get the instance variable beans from the instance variable nodes
    Collection<InstanceVariableBean> instanceVariableBeans = new ArrayList<>();
    for (FieldDeclaration instanceVariableNode : instanceVariableNodes) {
        instanceVariableBeans.add(InstanceVariableParser.parse(instanceVariableNode));
    }

    // Set the collection of instance variables
    classBean.setInstanceVariables(instanceVariableBeans);

    // Get the method nodes
    Collection<MethodDeclaration> methodNodes = new ArrayList<>();
    pClassNode.accept(new MethodVisitor(methodNodes));

    // Get the method beans from the method nodes
    Collection<MethodBean> methodBeans = new ArrayList<>();
    for (MethodDeclaration methodNode : methodNodes) {

        if ((methodNode.getName().toString().contains("get") || (methodNode.getName().toString().contains("set")))) {
            if (methodNode.parameters().isEmpty()) {
                numberOfGetterOrSetter++;
            }
        }

        methodBeans.add(MethodParser.parse(methodNode, instanceVariableBeans));
    }

    classBean.setNumberOfGetterAndSetter(numberOfGetterOrSetter);

    // Iterate over the collection of methods
    for (MethodBean classMethod : methodBeans) {

        // Instantiate a collection of class-defined invocations
        Collection<MethodBean> definedInvocations = new ArrayList<>();

        // Get the method invocations
        Collection<MethodBean> classMethodInvocations = classMethod.getMethodCalls();

        // Iterate over the collection of method invocations
        for (MethodBean classMethodInvocation : classMethodInvocations) {
            definedInvocations.add(classMethodInvocation);
        }

        // Set the class-defined invocations
        classMethod.setMethodCalls(definedInvocations);
    }

    // Set the collection of methods
    classBean.setMethods(methodBeans);

    return classBean;

}
 
Example 17
Source File: ClassParser.java    From aDoctor with MIT License 4 votes vote down vote up
public static ClassBean parse(TypeDeclaration pClassNode) {
    int numberOfGetterOrSetter = 0;

    // Instantiate the bean
    ClassBean classBean = new ClassBean();

    if (pClassNode.getSuperclassType() != null) {
        classBean.setSuperclass(pClassNode.getSuperclassType().toString());
    } else {
        classBean.setSuperclass(null);
    }

    // Set the name
    classBean.setName(pClassNode.getName().toString());

    // Get the instance variable nodes 
    Collection<FieldDeclaration> instanceVariableNodes = new ArrayList<>();
    pClassNode.accept(new InstanceVariableVisitor(instanceVariableNodes));

    classBean.setTextContent(pClassNode.toString());

    Pattern newLine = Pattern.compile("\n");
    String[] lines = newLine.split(pClassNode.toString());

    classBean.setLOC(lines.length);

    // Get the instance variable beans from the instance variable nodes
    Collection<InstanceVariableBean> instanceVariableBeans = new ArrayList<>();
    for (FieldDeclaration instanceVariableNode : instanceVariableNodes) {
        instanceVariableBeans.add(InstanceVariableParser.parse(instanceVariableNode));
    }

    // Set the collection of instance variables
    classBean.setInstanceVariables(instanceVariableBeans);

    // Get the method nodes
    Collection<MethodDeclaration> methodNodes = new ArrayList<>();
    pClassNode.accept(new MethodVisitor(methodNodes));

    // Get the method beans from the method nodes
    Collection<MethodBean> methodBeans = new ArrayList<>();
    for (MethodDeclaration methodNode : methodNodes) {

        if ((methodNode.getName().toString().contains("get") || (methodNode.getName().toString().contains("set")))) {
            if (methodNode.parameters().isEmpty()) {
                numberOfGetterOrSetter++;
            }
        }

        methodBeans.add(MethodParser.parse(methodNode, instanceVariableBeans));
    }

    classBean.setNumberOfGetterAndSetter(numberOfGetterOrSetter);

    // Iterate over the collection of methods
    for (MethodBean classMethod : methodBeans) {

        // Instantiate a collection of class-defined invocations
        Collection<MethodBean> definedInvocations = new ArrayList<>();

        // Get the method invocations
        Collection<MethodBean> classMethodInvocations = classMethod.getMethodCalls();

        // Iterate over the collection of method invocations
        for (MethodBean classMethodInvocation : classMethodInvocations) {
            definedInvocations.add(classMethodInvocation);
        }

        // Set the class-defined invocations
        classMethod.setMethodCalls(definedInvocations);
    }

    // Set the collection of methods
    classBean.setMethods(methodBeans);

    return classBean;

}