當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassOrInterfaceDeclaration類代碼示例

本文整理匯總了Java中com.github.javaparser.ast.body.ClassOrInterfaceDeclaration的典型用法代碼示例。如果您正苦於以下問題:Java ClassOrInterfaceDeclaration類的具體用法?Java ClassOrInterfaceDeclaration怎麽用?Java ClassOrInterfaceDeclaration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClassOrInterfaceDeclaration類屬於com.github.javaparser.ast.body包,在下文中一共展示了ClassOrInterfaceDeclaration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTypeName

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
protected String getTypeName(CompilationUnit compilationUnit, int index) {
    ClassOrInterfaceDeclaration type = (ClassOrInterfaceDeclaration) compilationUnit.getType(0);
    NodeList<ClassOrInterfaceType> extendedTypes = type.getExtendedTypes();
    ClassOrInterfaceType extendedType = extendedTypes.get(index);
    String typeSimpleName = extendedType.getName().getIdentifier();
    Optional<ClassOrInterfaceType> scope = extendedType.getScope();
    String typeName;
    if (scope.isPresent()) {
        String typePackageName = scope.get().toString();
        typeName = String.format("%s.%s", typePackageName, typeSimpleName);
    } else {
        typeName = typeSimpleName;
    }
    return typeName;
}
 
開發者ID:paypal,項目名稱:butterfly,代碼行數:17,代碼來源:Extends.java

示例2: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
public Node visit(ClassOrInterfaceDeclaration _n, Object _arg) {
	List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
	List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
	List<ClassOrInterfaceType> extendsList = visit(_n.getExtends(), _arg);
	List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg);
       List<BodyDeclaration<?>> members = visit(_n.getMembers(), _arg);
	Comment comment = cloneNodes(_n.getComment(), _arg);

	ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration(
			_n.getRange(),
			_n.getModifiers(), annotations, _n.isInterface(), _n.getName(), typeParameters, extendsList, implementsList, members
	);
	r.setComment(comment);
	return r;
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:17,代碼來源:CloneVisitor.java

示例3: matches

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
public boolean matches(Object item) {
    Optional<ClassOrInterfaceDeclaration> referenceClass = compilationUnit.getClassByName(className);
    Optional<ClassOrInterfaceDeclaration> actualClass = ((CompilationUnit) item).getClassByName(className);

    if (referenceClass.isPresent() && actualClass.isPresent()) {
        Optional<ConstructorDeclaration> referenceConstructor = referenceClass.get().getConstructorByParameterTypes(params);
        Optional<ConstructorDeclaration> actualConstructor = actualClass.get().getConstructorByParameterTypes(params);

        return referenceConstructor.isPresent()
                && actualConstructor.isPresent()
                && referenceConstructor.get().equals(actualConstructor.get());
    }

    return false;
}
 
開發者ID:alek-sys,項目名稱:dataj,代碼行數:17,代碼來源:ConstructorDeclarationMatcher.java

示例4: getClassNameFromMethod

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
public String getClassNameFromMethod(MethodDeclaration n) {
    Optional<ClassOrInterfaceDeclaration> methodClazzNode;
    String methodClazzName = null;

    logger.debug("Getting class name");

    // Get the name of the class this method belongs to
    methodClazzNode = n.getAncestorOfType(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.class);
    if (methodClazzNode.isPresent()) {
        methodClazzName = methodClazzNode.get().getNameAsString();
    }

    if (methodClazzName != null) {
        logger.debug("Found class: " + methodClazzName);
    } else {
        logger.debug("Did not find class name.");
    }

    return methodClazzName;
}
 
開發者ID:kevinfealey,項目名稱:API_Endpoint_Identifier,代碼行數:21,代碼來源:SpringAnnotationAnalyzer.java

示例5: testGetClassNameFromMethod

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Test
public void testGetClassNameFromMethod() {
    //Code from: https://github.com/javaparser/javaparser/wiki/Manual
    CompilationUnit cu = new CompilationUnit();
    // set the package
    cu.setPackageDeclaration(new PackageDeclaration(Name.parse("com.aspectsecurity.example")));

    // or a shortcut
    cu.setPackageDeclaration("com.aspectsecurity.example");

    // create the type declaration
    ClassOrInterfaceDeclaration type = cu.addClass("GeneratedClass");

    // create a method
    EnumSet<Modifier> modifiers = EnumSet.of(Modifier.PUBLIC);
    MethodDeclaration method = new MethodDeclaration(modifiers, new VoidType(), "main");
    modifiers.add(Modifier.STATIC);
    method.setModifiers(modifiers);
    type.addMember(method);

    assertEquals("GeneratedClass", saa.getClassNameFromMethod(method));
}
 
開發者ID:kevinfealey,項目名稱:API_Endpoint_Identifier,代碼行數:23,代碼來源:SpringAnnotationAnalyzerUnitTest.java

示例6: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
public void visit(final NormalAnnotationExpr expr, final Void arg) {
    final String fqcn = expr.getName().toString();
    if (fqcn.equals(Description.class.getCanonicalName())) {
        final Node parent = expr.getParentNode();
        final String value = expr.getPairs().get(0).toString();
        if (parent instanceof ClassOrInterfaceDeclaration) {
            descriptionAnotValue = value;
        } else if (parent instanceof MethodDeclaration) {
            methodDescriptions.put(((MethodDeclaration) parent).getName(), value);
        }
    } else if (fqcn.equals(ServiceInterfaceAnnotation.class.getCanonicalName())) {
        String text1 = expr.getPairs().get(0).toString();
        String text2 = expr.getPairs().get(1).toString();
        if (text1.contains("value")) {
            sieAnnotValue = text1;
            sieAnnotOsgiRegistrationType = text2;
        } else {
            sieAnnotValue = text2;
            sieAnnotOsgiRegistrationType = text1;
        }
    }

    super.visit(expr, arg);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:26,代碼來源:SieASTVisitor.java

示例7: calculate

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) {
    List<AnnotationExpr> annotations = classOrInterfaceDeclaration.getAnnotations();
    for (AnnotationExpr annotation : annotations) {
        String annotationName = annotation.getNameAsString();
        String annotationPackageName = annotation
                .findCompilationUnit()
                .flatMap(CompilationUnit::getPackageDeclaration)
                .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???");

        if (typeDao.exist(annotationName, annotationPackageName)) { // JDK annotations are not indexed
            int annotationId = typeDao.getId(annotationName, annotationPackageName);
            int typeId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), compilationUnit.getPackageDeclaration().get().getNameAsString());
            annotatedWithDao.save(new AnnotatedWith(typeId, annotationId));
        }
    }
}
 
開發者ID:benas,項目名稱:jql,代碼行數:17,代碼來源:AnnotatedWithCalculator.java

示例8: calculate

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) {
    List<ClassOrInterfaceType> implementedInterfaces = classOrInterfaceDeclaration.getImplementedTypes();
    for (ClassOrInterfaceType implementedInterface : implementedInterfaces) {
        String implementedInterfaceName = implementedInterface.getNameAsString();
        String implementedInterfacePackageName = implementedInterface
                .findCompilationUnit()
                .flatMap(CompilationUnit::getPackageDeclaration)
                .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???");
        if (typeDao.exist(implementedInterfaceName, implementedInterfacePackageName)) { // JDK interfaces are not indexed
            int interfaceId = typeDao.getId(implementedInterfaceName, implementedInterfacePackageName);
            String cuPackageName = compilationUnit.getPackageDeclaration().get().getNameAsString();
            int nbClasses = typeDao.count(classOrInterfaceDeclaration.getNameAsString(), cuPackageName);
            if (nbClasses > 1) {
                System.err.println("More than one class having the same name '" + classOrInterfaceDeclaration.getName() + "' and package '" + cuPackageName + "'");
            } else {
                int classId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), cuPackageName);
                implementsDao.save(new Implements(classId, interfaceId));
            }
        }
    }
}
 
開發者ID:benas,項目名稱:jql,代碼行數:22,代碼來源:ImplementsRelationCalculator.java

示例9: calculate

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) {
    List<ClassOrInterfaceType> extendedTypes = classOrInterfaceDeclaration.getExtendedTypes();
    for (ClassOrInterfaceType extendedType : extendedTypes) {
        String extendedTypeName = extendedType.getNameAsString();
        String extendedTypePackageName = extendedType
                .findCompilationUnit()
                .flatMap(CompilationUnit::getPackageDeclaration)
                .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???");

        if (typeDao.exist(extendedTypeName, extendedTypePackageName)) { // JDK interfaces are not indexed
            int extendedInterfaceId = typeDao.getId(extendedTypeName, extendedTypePackageName);
            int interfaceId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), compilationUnit.getPackageDeclaration().get().getNameAsString());
            extendsDao.save(new Extends(interfaceId, extendedInterfaceId));
        }
    }
}
 
開發者ID:benas,項目名稱:jql,代碼行數:17,代碼來源:ExtendsRelationCalculator.java

示例10: ClassWrapper

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
public ClassWrapper(AbstractGenerator generator, File file, CompilationUnit unit) {
	m_generator = generator;
	m_file = file;
	m_unit = unit;
	String name = m_file.getName();
	m_simpleName = name.substring(0, name.indexOf("."));                // Strip any suffix
	m_fullClassName = calculateClassName();

	ClassOrInterfaceDeclaration rootType = null;
	Optional<ClassOrInterfaceDeclaration> o = m_unit.getClassByName(getSimpleName());
	if(! o.isPresent()) {
		error("Cannot locate class type");
	} else {
		rootType = o.get();
	}
	m_rootType = rootType;
	m_isNew = false;
}
 
開發者ID:fjalvingh,項目名稱:domui,代碼行數:19,代碼來源:ClassWrapper.java

示例11: isValidVoltProcedure

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
public boolean isValidVoltProcedure() {
  final Optional<ClassOrInterfaceDeclaration> storedProc = getClassExtendingVoltProcedure();
  final Optional<MethodDeclaration> runMethod = getRunMethod();

  if(!storedProc.isPresent()) {
    return false;
  }

  if(!runMethod.isPresent()) {
    return false;
  }

  final Optional<String> returnType = getRunMethodReturnTypeAsString();
  if(!returnType.isPresent() || !ProcReturnType.isValidJavaType(getRunMethodReturnTypeAsString().get())) {
    return false;
  }

  // TODO - checks to do, eg throws the wrong type of chcekced exception, that class extending voltproc isn't abstract

  return true;
}
 
開發者ID:raffishquartan,項目名稱:vpt,代碼行數:23,代碼來源:JavaparserSourceFile.java

示例12: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
public void visit(ClassOrInterfaceDeclaration clazz, Object arg) {
    for (BodyDeclaration member : clazz.getMembers()) {
        if (member instanceof ClassOrInterfaceDeclaration)
            visit((ClassOrInterfaceDeclaration)member, arg);
        else if (member instanceof FieldDeclaration) {
            FieldDeclaration field = (FieldDeclaration)member;
            String type = null != field.getType() ? field.getType().toString() : "";
            if (type.equals("int")) {
                VariableDeclarator variable = field.getVariables().stream().findFirst().get();
                String name = variable.getId().toString();
                Integer value = null != variable.getInit() ? Integer.parseInt(variable.getInit().toString()) : 0;
                // decimal value of 0x7f000000, which is what AAPT starts numbering at - http://stackoverflow.com/a/6646113/311304
                if (value >= 2130706432) {
                    name = "R." + ((ClassOrInterfaceDeclaration)field.getParentNode()).getName() + "." + name;
                    transform.put(value, name);
                }
            }
        }
    }
}
 
開發者ID:justingarrick,項目名稱:android-reverse-r,代碼行數:22,代碼來源:Reverser.java

示例13: getClassDeclaration

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
private static ClassOrInterfaceDeclaration getClassDeclaration(File file) throws ParseException, IOException {
    final CompilationUnit compilationUnit = JavaParser.parse(file);
    final String filename = file.getName();
    final String className = filename.replaceAll("(.*)\\.java$", "$1");

    if (className.length() == file.getName().length()) {
        throw new IllegalStateException("Couldn't extract [Java] class name from filename: " + filename);
    }

    Optional<ClassOrInterfaceDeclaration> classDeclaration = compilationUnit.getTypes().stream()
            .filter(ClassOrInterfaceDeclaration.class::isInstance)
            .map(ClassOrInterfaceDeclaration.class::cast)
            .filter(declaration -> declaration.getName().equals(className))
            .findFirst();

    assertThat("class " + className + " generated", classDeclaration.isPresent(), is(true));

    return classDeclaration.get();
}
 
開發者ID:hubrick,項目名稱:raml-maven-plugin,代碼行數:20,代碼來源:SpringWebGeneratorMojoTest.java

示例14: visit

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
public Type visit(ThisExpr node, Boolean solveLambdas) {
    // If 'this' is prefixed by a class eg. MyClass.this
    if (node.getClassExpr().isPresent()){
        // Get the class name
        String className = node.getClassExpr().get().toString();
        // Attempt to resolve using a typeSolver
        SymbolReference<ReferenceTypeDeclaration> clazz = typeSolver.tryToSolveType(className);
        if (clazz.isSolved()){
            return new ReferenceTypeImpl(clazz.getCorrespondingDeclaration(),typeSolver);
        }
        // Attempt to resolve locally in Compilation unit
        Optional<CompilationUnit> cu = node.getAncestorOfType(CompilationUnit.class);
        if (cu.isPresent()){
            Optional<ClassOrInterfaceDeclaration> classByName = cu.get().getClassByName(className);
            if (classByName.isPresent()){
                return new ReferenceTypeImpl(facade.getTypeDeclaration(classByName.get()), typeSolver);
            }
        }

    }
    return new ReferenceTypeImpl(facade.getTypeDeclaration(facade.findContainingTypeDecl(node)), typeSolver);
}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:24,代碼來源:TypeExtractor.java

示例15: doMerge

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; //導入依賴的package包/類
@Override
public ClassOrInterfaceDeclaration doMerge(ClassOrInterfaceDeclaration first, ClassOrInterfaceDeclaration second) {

  ClassOrInterfaceDeclaration declaration = new ClassOrInterfaceDeclaration();

  declaration.setInterface(first.isInterface());
  declaration.setName(first.getName());

  declaration.setModifiers(mergeModifiers(first.getModifiers(), second.getModifiers()));
  declaration.setJavaDoc(mergeSingle(first.getJavaDoc(), second.getJavaDoc()));
  declaration.setTypeParameters(mergeCollections(first.getTypeParameters(), second.getTypeParameters()));

  declaration.setImplements(mergeCollections(first.getImplements(), second.getImplements()));
  declaration.setExtends(mergeCollections(first.getExtends(), second.getExtends()));

  declaration.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations()));
  declaration.setMembers(mergeCollections(first.getMembers(), second.getMembers()));

  return declaration;
}
 
開發者ID:beihaifeiwu,項目名稱:dolphin,代碼行數:21,代碼來源:ClassOrInterfaceDeclarationMerger.java


注:本文中的com.github.javaparser.ast.body.ClassOrInterfaceDeclaration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。