use of com.github.javaparser.ast.AccessSpecifier in project javaparser by javaparser.
the class ConstructorDeclaration method getDeclarationAsString.
/**
* The declaration returned has this schema:
*
* [accessSpecifier] className ([paramType [paramName]])
* [throws exceptionsList]
*/
@Override
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName) {
StringBuffer sb = new StringBuffer();
if (includingModifiers) {
AccessSpecifier accessSpecifier = ModifierSet.getAccessSpecifier(getModifiers());
sb.append(accessSpecifier.getCodeRepresenation());
sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " ");
}
sb.append(getName());
sb.append("(");
boolean firstParam = true;
for (Parameter param : getParameters()) {
if (firstParam) {
firstParam = false;
} else {
sb.append(", ");
}
if (includingParameterName) {
sb.append(param.toStringWithoutComments());
} else {
sb.append(param.getType().toStringWithoutComments());
}
}
sb.append(")");
if (includingThrows) {
boolean firstThrow = true;
for (NameExpr thr : getThrows()) {
if (firstThrow) {
firstThrow = false;
sb.append(" throws ");
} else {
sb.append(", ");
}
sb.append(thr.toStringWithoutComments());
}
}
return sb.toString();
}
use of com.github.javaparser.ast.AccessSpecifier in project javaparser by javaparser.
the class MethodDeclaration method getDeclarationAsString.
/**
* The declaration returned has this schema:
*
* [accessSpecifier] [static] [abstract] [final] [native]
* [synchronized] returnType methodName ([paramType [paramName]])
* [throws exceptionsList]
* @return method declaration as String
*/
@Override
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName) {
StringBuffer sb = new StringBuffer();
if (includingModifiers) {
AccessSpecifier accessSpecifier = ModifierSet.getAccessSpecifier(getModifiers());
sb.append(accessSpecifier.getCodeRepresenation());
sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " ");
if (ModifierSet.isStatic(getModifiers())) {
sb.append("static ");
}
if (ModifierSet.isAbstract(getModifiers())) {
sb.append("abstract ");
}
if (ModifierSet.isFinal(getModifiers())) {
sb.append("final ");
}
if (ModifierSet.isNative(getModifiers())) {
sb.append("native ");
}
if (ModifierSet.isSynchronized(getModifiers())) {
sb.append("synchronized ");
}
}
// TODO verify it does not print comments connected to the type
sb.append(getType().toStringWithoutComments());
sb.append(" ");
sb.append(getName());
sb.append("(");
boolean firstParam = true;
for (Parameter param : getParameters()) {
if (firstParam) {
firstParam = false;
} else {
sb.append(", ");
}
if (includingParameterName) {
sb.append(param.toStringWithoutComments());
} else {
sb.append(param.getType().toStringWithoutComments());
if (param.isVarArgs()) {
sb.append("...");
}
}
}
sb.append(")");
if (includingThrows) {
boolean firstThrow = true;
for (NameExpr thr : getThrows()) {
if (firstThrow) {
firstThrow = false;
sb.append(" throws ");
} else {
sb.append(", ");
}
sb.append(thr.toStringWithoutComments());
}
}
return sb.toString();
}
Aggregations