@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getSuperclass()))); }
@Override public CtTypeReference<?> getSuperclass() { CtType<T> t = getTypeDeclaration(); if (t != null) { return t.getSuperclass(); } return null; }
public void writeExtendsClause(CtType<?> type) { if (type.getSuperclass() != null) { printer.writeSpace().writeKeyword("extends").writeSpace(); prettyPrinter.scan(type.getSuperclass()); } }
/** * adds all {@link MetamodelProperty}s of `ctType` * @param mmConcept the owner of to be created fields * @param ctType to be scanned {@link CtType} */ private void addFieldsOfType(MetamodelConcept mmConcept, CtType<?> ctType) { ctType.getTypeMembers().forEach(typeMember -> { if (typeMember instanceof CtMethod<?>) { CtMethod<?> method = (CtMethod<?>) typeMember; CtRole role = getRoleOfMethod(method); if (role != null) { MetamodelProperty field = mmConcept.getOrCreateMMField(role); field.addMethod(method); } else { mmConcept.otherMethods.add(method); } } }); addFieldsOfSuperType(mmConcept, ctType.getSuperclass()); ctType.getSuperInterfaces().forEach(superIfaceRef -> addFieldsOfSuperType(mmConcept, superIfaceRef)); }
public static boolean isAssertionClass(CtType klass) { return klass != null && ("org.junit.Assert".equals(klass.getQualifiedName()) || "junit.framework.Assert".equals(klass.getQualifiedName())) && klass.getSuperclass() != null && isAssertionClass(klass.getSuperclass().getDeclaration()); }
public CtMethod getMethod(CtType<?> ctClass) { if ("none".equals(this.simpleNameMethod)) { return null; } else { if (this.testCase == null) { List<CtMethod<?>> methodsByName = ctClass.getMethodsByName(this.simpleNameMethod); if (methodsByName.isEmpty()) { if (ctClass.getSuperclass() != null) { return getMethod(ctClass.getSuperclass().getDeclaration()); } else { return null; } } this.testCase = methodsByName.get(0); } return this.testCase; } } }
public static String ctTypeToFullQualifiedName(CtType<?> testClass) { if (testClass.getModifiers().contains(ModifierKind.ABSTRACT)) { CtTypeReference<?> referenceOfSuperClass = testClass.getReference(); return testClass.getFactory().Class().getAll().stream() .filter(ctType -> referenceOfSuperClass.equals(ctType.getSuperclass())) .map(CtType::getQualifiedName).collect(Collectors.joining(",")); } else { return testClass.getQualifiedName(); } }
@Override protected boolean isATest(CtMethod<?> candidate) { // checkEnum that the current test class inherit from TestCase final CtType<?> testClass = candidate.getParent(CtType.class); if (testClass == null) { return false; } final CtTypeReference<?> superclassReference = testClass.getSuperclass(); if (superclassReference == null) { return false; } return superclassReference.getQualifiedName().equals(this.qualifiedNameOfAssertClass) && candidate.getAnnotations().isEmpty() && candidate.getSimpleName().startsWith("test"); }
public static TestListener runSubClassesForAbstractTestClass(CtType<?> testClass, List<CtMethod<?>> testsToRun, String classPath) throws AmplificationException { try { return testClass.getFactory().Type() .getAll() .stream() .filter(ctType -> ctType.getSuperclass() != null && testClass.getReference().equals(ctType.getSuperclass())) .map(CtType::getQualifiedName) .map(testClassName -> { try { return EntryPoint.runTests( classPath + AmplificationHelper.PATH_SEPARATOR + DSpotUtils.getAbsolutePathToDSpotDependencies(), testClassName, testsToRun.stream() .map(CtMethod::getSimpleName) .toArray(String[]::new)); } catch (TimeoutException e) { throw new RuntimeException(e); } }).reduce(TestListener::aggregate) .orElse(null); } catch (Exception e) { LOGGER.warn("Errors during execution of {}: {}", testClass.getQualifiedName(), testsToRun.stream() .map(CtMethod::getSimpleName) .collect(Collectors.joining(",")) ); throw new AmplificationException(e); } }
@Deprecated private Set<CtMethod<?>> getAllMethods(CtType<?> type) { try { return type.getAllMethods(); } catch (StackOverflowError e) { LOGGER.error("Overflow!"); final Set<CtMethod<?>> methods = new HashSet<>(type.getMethods()); CtTypeReference<?> currentSuperClass = type.getSuperclass(); while (currentSuperClass != null) { methods.addAll(currentSuperClass.getTypeDeclaration().getMethods()); currentSuperClass = currentSuperClass.getSuperclass(); } return methods; } }
@Override public CtTypeReference<?> getSuperclass() { CtType<T> t = getDeclaration(); if (t != null) { return t.getSuperclass(); } else { Class<T> c = getActualClass(); Class<?> sc = c.getSuperclass(); if (sc == null) { return null; } return getFactory().Type().createReference(sc); } }
public NGrams calculateGrams4Class(CtType type) throws JSAPException { Boolean mustCloneOriginalValue = ConfigurationProperties.getPropertyBool("duplicateingredientsinspace"); // Forcing to duplicate ConfigurationProperties.setProperty("duplicateingredientsinspace", "true"); NGrams gramsFromClass = new NGrams(); CodeParserLauncher ingp = new CodeParserLauncher<>(ingredientProcessor); int allElements = 0; CtType typeToProcess = type; while (typeToProcess != null // && // !ngramsStore.containsKey(typeToProcess.getQualifiedName()) ) { logger.debug("Extracting Ngram from " + typeToProcess.getQualifiedName()); allElements += getNGramsFromCodeElements(typeToProcess, gramsFromClass, ingp); if (typeToProcess.getSuperclass() != null) typeToProcess = typeToProcess.getSuperclass().getDeclaration(); else typeToProcess = null; } // reset property clone ConfigurationProperties.setProperty("duplicateingredientsinspace", Boolean.toString(mustCloneOriginalValue)); return gramsFromClass; }