本文整理汇总了Java中com.github.javaparser.ast.AccessSpecifier类的典型用法代码示例。如果您正苦于以下问题:Java AccessSpecifier类的具体用法?Java AccessSpecifier怎么用?Java AccessSpecifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessSpecifier类属于com.github.javaparser.ast包,在下文中一共展示了AccessSpecifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetDeclaredMethods
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
@Test
public void testGetDeclaredMethods() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedReferenceTypeDeclaration string = new ReflectionClassDeclaration(String.class, typeResolver);
List<ResolvedMethodDeclaration> methods = string.getDeclaredMethods().stream()
.filter(m -> m.accessSpecifier() != AccessSpecifier.PRIVATE && m.accessSpecifier() != AccessSpecifier.DEFAULT)
.sorted((a, b) -> a.getName().compareTo(b.getName()))
.collect(Collectors.toList());
assertEquals(67, methods.size());
assertEquals("charAt", methods.get(0).getName());
assertEquals(false, methods.get(0).isAbstract());
assertEquals(1, methods.get(0).getNumberOfParams());
assertEquals("int", methods.get(0).getParam(0).getType().describe());
assertEquals("concat", methods.get(6).getName());
assertEquals(false, methods.get(6).isAbstract());
assertEquals(1, methods.get(6).getNumberOfParams());
assertEquals("java.lang.String", methods.get(6).getParam(0).getType().describe());
}
示例2: testGetFieldForExistingField
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
@Test
public void testGetFieldForExistingField() {
JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
ResolvedFieldDeclaration fieldDeclaration = null;
// declared field
fieldDeclaration = constructorDeclaration.getField("modifiers");
assertEquals("modifiers", fieldDeclaration.getName());
assertEquals("java.util.EnumSet", fieldDeclaration.getType().asReferenceType().getQualifiedName());
assertEquals(AccessSpecifier.PRIVATE, fieldDeclaration.accessSpecifier());
assertEquals(false, fieldDeclaration.isStatic());
// inherited field
fieldDeclaration = constructorDeclaration.getField("annotations");
assertEquals("annotations", fieldDeclaration.getName());
assertEquals("java.util.List", fieldDeclaration.getType().asReferenceType().getQualifiedName());
assertEquals(AccessSpecifier.PRIVATE, fieldDeclaration.accessSpecifier());
}
示例3: getAccessSpecifier
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
public static AccessSpecifier getAccessSpecifier(int modifiers) {
if (isPublic(modifiers)){
return AccessSpecifier.PUBLIC;
} else if (isProtected(modifiers)){
return AccessSpecifier.PROTECTED;
} else if (isPrivate(modifiers)){
return AccessSpecifier.PRIVATE;
} else {
return AccessSpecifier.DEFAULT;
}
}
示例4: getDeclarationAsString
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
/**
* The declaration returned has this schema:
*
* [accessSpecifier] className ([paramType [paramName]])
* [throws exceptionsList]
*/
@Override
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows,
boolean includingParameterName) {
StringBuilder sb = new StringBuilder();
if (includingModifiers) {
AccessSpecifier accessSpecifier = Modifier.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.getElementType().toStringWithoutComments());
}
}
sb.append(")");
if (includingThrows) {
boolean firstThrow = true;
for (ReferenceType thr : getThrows()) {
if (firstThrow) {
firstThrow = false;
sb.append(" throws ");
} else {
sb.append(", ");
}
sb.append(thr.toStringWithoutComments());
}
}
return sb.toString();
}
示例5: modifiersToAccessLevel
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
static AccessSpecifier modifiersToAccessLevel(final int modifiers) {
if (Modifier.isPublic(modifiers)) {
return AccessSpecifier.PUBLIC;
} else if (Modifier.isProtected(modifiers)) {
return AccessSpecifier.PROTECTED;
} else if (Modifier.isPrivate(modifiers)) {
return AccessSpecifier.PRIVATE;
} else {
return AccessSpecifier.DEFAULT;
}
}
示例6: modifiersToAccessLevel
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
static AccessSpecifier modifiersToAccessLevel(final int modifiers) {
if (Modifier.isPublic(modifiers)) {
return AccessSpecifier.PUBLIC;
} else if (Modifier.isProtected(modifiers)) {
return AccessSpecifier.PROTECTED;
} else if (Modifier.isPrivate(modifiers)) {
return AccessSpecifier.PRIVATE;
} else {
return AccessSpecifier.DEFAULT;
}
}
示例7: getAllFields
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
@Override
public List<ResolvedFieldDeclaration> getAllFields() {
List<ResolvedFieldDeclaration> fields = javaParserTypeAdapter.getFieldsForDeclaredVariables();
getAncestors().forEach(ancestor -> ancestor.getTypeDeclaration().getAllFields().forEach(f -> {
fields.add(new ResolvedFieldDeclaration() {
@Override
public AccessSpecifier accessSpecifier() {
return f.accessSpecifier();
}
@Override
public String getName() {
return f.getName();
}
@Override
public ResolvedType getType() {
return ancestor.useThisTypeParametersOnTheGivenType(f.getType());
}
@Override
public boolean isStatic() {
return f.isStatic();
}
@Override
public ResolvedTypeDeclaration declaringType() {
return f.declaringType();
}
});
}));
return fields;
}
示例8: getDeclarationAsString
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
/**
* 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();
}
示例9: getDeclarationAsString
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
/**
* 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 (ReferenceType thr : getThrows()) {
if (firstThrow) {
firstThrow = false;
sb.append(" throws ");
} else {
sb.append(", ");
}
sb.append(thr.toStringWithoutComments());
}
}
return sb.toString();
}
示例10: accessSpecifier
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
@Override
public AccessSpecifier accessSpecifier() {
throw new UnsupportedOperationException();
}
示例11: getDeclarationAsString
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
/**
* 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) {
StringBuilder sb = new StringBuilder();
if (includingModifiers) {
AccessSpecifier accessSpecifier = Modifier.getAccessSpecifier(getModifiers());
sb.append(accessSpecifier.getCodeRepresenation());
sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " ");
if (getModifiers().contains(Modifier.STATIC)) {
sb.append("static ");
}
if (getModifiers().contains(Modifier.ABSTRACT)) {
sb.append("abstract ");
}
if (getModifiers().contains(Modifier.FINAL)) {
sb.append("final ");
}
if (getModifiers().contains(Modifier.NATIVE)) {
sb.append("native ");
}
if (getModifiers().contains(Modifier.SYNCHRONIZED)) {
sb.append("synchronized ");
}
}
// TODO verify it does not print comments connected to the type
sb.append(getElementType().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.getElementType().toStringWithoutComments());
if (param.isVarArgs()) {
sb.append("...");
}
}
}
sb.append(")");
if (includingThrows) {
boolean firstThrow = true;
for (ReferenceType thr : getThrows()) {
if (firstThrow) {
firstThrow = false;
sb.append(" throws ");
} else {
sb.append(", ");
}
sb.append(thr.toStringWithoutComments());
}
}
return sb.toString();
}
示例12: getDeclarationAsString
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
/**
* 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();
}
示例13: accessSpecifier
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
@Override
public AccessSpecifier accessSpecifier() {
return JavassistFactory.modifiersToAccessLevel(ctClass.getModifiers());
}
示例14: accessSpecifier
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
@Override
public AccessSpecifier accessSpecifier() {
return JavassistFactory.modifiersToAccessLevel(ctField.getModifiers());
}
示例15: accessSpecifier
import com.github.javaparser.ast.AccessSpecifier; //导入依赖的package包/类
@Override
public AccessSpecifier accessSpecifier() {
return JavassistFactory.modifiersToAccessLevel(ctConstructor.getModifiers());
}