All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.source.formatter.parser.JavaClass Maven / Gradle / Ivy

There is a newer version: 1.0.1437
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.source.formatter.parser;

import com.liferay.portal.kernel.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Hugo Huijser
 */
public class JavaClass extends BaseJavaTerm {

	public JavaClass(
		String name, String packageName, List importNames,
		String content, String accessModifier, int lineNumber,
		boolean isAbstract, boolean isFinal, boolean isStatic,
		boolean isInterface, boolean anonymous) {

		super(
			name, content, accessModifier, lineNumber, isAbstract, isFinal,
			isStatic);

		_packageName = packageName;
		_importNames = importNames;
		_isInterface = isInterface;
		_anonymous = anonymous;
	}

	public void addChildJavaTerm(JavaTerm javaTerm) {
		javaTerm.setParentJavaClass(this);

		_childJavaTerms.add(javaTerm);
	}

	public void addExtendedClassNames(String... extendedClassNames) {
		for (String extendedClassName : extendedClassNames) {
			_extendedClassTypes.add(
				new JavaClassType(
					StringUtil.trim(extendedClassName), _packageName,
					_importNames));
		}
	}

	public void addImplementedClassNames(String... implementedClassNames) {
		for (String implementedClassName : implementedClassNames) {
			_implementedClassTypes.add(
				new JavaClassType(
					StringUtil.trim(implementedClassName), _packageName,
					_importNames));
		}
	}

	public List getChildJavaTerms() {
		return _childJavaTerms;
	}

	public List getExtendedClassNames() {
		return getExtendedClassNames(false);
	}

	public List getExtendedClassNames(boolean fullyQualifiedName) {
		List extendedClassNames = new ArrayList<>();

		for (JavaClassType extendedClassType : _extendedClassTypes) {
			extendedClassNames.add(
				extendedClassType.toString(fullyQualifiedName));
		}

		return extendedClassNames;
	}

	public List getImplementedClassNames() {
		return getImplementedClassNames(false);
	}

	public List getImplementedClassNames(boolean fullyQualifiedName) {
		List implementedClassNames = new ArrayList<>();

		for (JavaClassType implementedClassType : _implementedClassTypes) {
			implementedClassNames.add(
				implementedClassType.toString(fullyQualifiedName));
		}

		return implementedClassNames;
	}

	public List getImplementedClassTypes() {
		return _implementedClassTypes;
	}

	@Override
	public List getImportNames() {
		return _importNames;
	}

	public String getName(boolean fullyQualifiedClassName) {
		if (!fullyQualifiedClassName) {
			return getName();
		}

		return _packageName + "." + getName();
	}

	@Override
	public String getPackageName() {
		return _packageName;
	}

	public boolean isAnonymous() {
		return _anonymous;
	}

	public boolean isInterface() {
		return _isInterface;
	}

	private final boolean _anonymous;
	private final List _childJavaTerms = new ArrayList<>();
	private final List _extendedClassTypes = new ArrayList<>();
	private final List _implementedClassTypes =
		new ArrayList<>();
	private final List _importNames;
	private final boolean _isInterface;
	private final String _packageName;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy