Java Code Examples for spoon.reflect.declaration.CtModifiable

The following examples show how to use spoon.reflect.declaration.CtModifiable. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: nopol   Source File: SpoonReferenceLibrary.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean isVisibleFrom(CtTypeReference<?> accessingClass, CtModifiable modifiable, CtTypeReference<?> declaringClass, CtTypeReference<?> actualClass) {
    if (hasPublicModifier(modifiable)) {
        return true;
    }
    if ((isNestedIn(accessingClass, actualClass) || isNestedIn(actualClass, accessingClass)) && areSameClass(declaringClass, actualClass)) {
        return true;
    }
    if (hasNoVisibilityModifier(modifiable) && areFromSamePackage(declaringClass, actualClass) && areFromSamePackage(actualClass, accessingClass)) {
        return true;
    }
    if (hasPrivateModifier(modifiable) && areSameClass(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && areFromSamePackage(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && isSubclassOf(declaringClass, accessingClass) && areSameClass(actualClass, accessingClass)) {
        return true;
    }
    return false;
}
 
Example 2
Source Project: spoon-examples   Source File: DocProcessor.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void process(CtElement element) {
	if (element instanceof CtType || element instanceof CtField || element instanceof CtExecutable) {
		Set<ModifierKind> modifiers = ((CtModifiable) element).getModifiers();
		if (modifiers.contains(PUBLIC) || modifiers.contains(PROTECTED)) {
			String docComment = element.getDocComment();
			if (docComment == null || docComment.equals("")) {
				System.out.println("undocumented element at " + element.getPosition());
				undocumentedElements.add(element);
			}
		}
	}
}
 
Example 3
Source Project: gumtree-spoon-ast-diff   Source File: NodeCreator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void scanCtModifiable(CtModifiable m) {

	if (m.getModifiers().isEmpty())
		return;

	// We add the type of modifiable element
	String type = MODIFIERS + getClassName(m.getClass().getSimpleName());
	ITree modifiers = builder.createNode(type, "");

	// We create a virtual node
	modifiers.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, new CtVirtualElement(type, m, m.getModifiers()));

	// ensuring an order (instead of hashset)
	// otherwise some flaky tests in CI
	Set<ModifierKind> modifiers1 = new TreeSet<>(new Comparator<ModifierKind>() {
		@Override
		public int compare(ModifierKind o1, ModifierKind o2) {
			return o1.name().compareTo(o2.name());
		}
	});
	modifiers1.addAll(m.getModifiers());

	for (ModifierKind kind : modifiers1) {
		ITree modifier = builder.createNode("Modifier", kind.toString());
		modifiers.addChild(modifier);
		// We wrap the modifier (which is not a ctelement)
		modifier.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, new CtWrapper(kind, m));
	}
	builder.addSiblingNode(modifiers);

}