use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class MemberVisibilityAdjustor method thresholdTypeToType.
/**
* Returns the visibility threshold from a type to another type.
*
* @param referencing the referencing type
* @param referenced the referenced type
* @param monitor the progress monitor to use
* @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
* @throws JavaModelException if the java elements could not be accessed
*/
private ModifierKeyword thresholdTypeToType(final IType referencing, final IType referenced, final IProgressMonitor monitor) throws JavaModelException {
ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
final ICompilationUnit referencedUnit = referenced.getCompilationUnit();
if (referencing.equals(referenced.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else {
final ITypeHierarchy hierarchy = getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
final IType[] types = hierarchy.getSupertypes(referencing);
IType superType = null;
for (int index = 0; index < types.length; index++) {
superType = types[index];
if (superType.equals(referenced)) {
keyword = null;
return keyword;
}
}
}
final ICompilationUnit typeUnit = referencing.getCompilationUnit();
if (referencedUnit != null && referencedUnit.equals(typeUnit)) {
if (referenced.getDeclaringType() != null)
keyword = null;
else
keyword = ModifierKeyword.PRIVATE_KEYWORD;
} else if (referencedUnit != null && typeUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
keyword = null;
return keyword;
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project flux by eclipse.
the class ModifierCorrectionSubProcessor method findVisibilityModifier.
private static Modifier findVisibilityModifier(List<IExtendedModifier> modifiers) {
for (int i = 0; i < modifiers.size(); i++) {
IExtendedModifier curr = modifiers.get(i);
if (curr instanceof Modifier) {
Modifier modifier = (Modifier) curr;
ModifierKeyword keyword = modifier.getKeyword();
if (keyword == ModifierKeyword.PUBLIC_KEYWORD || keyword == ModifierKeyword.PROTECTED_KEYWORD || keyword == ModifierKeyword.PRIVATE_KEYWORD) {
return modifier;
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project lombok by rzwitserloot.
the class PatchValEclipse method addFinalAndValAnnotationToModifierList.
public static void addFinalAndValAnnotationToModifierList(Object converter, List<IExtendedModifier> modifiers, AST ast, LocalDeclaration in) {
// First check that 'in' has the final flag on, and a @val / @lombok.val annotation.
if ((in.modifiers & ClassFileConstants.AccFinal) == 0)
return;
if (in.annotations == null)
return;
boolean found = false;
Annotation valAnnotation = null;
for (Annotation ann : in.annotations) {
if (couldBeVal(ann.type)) {
found = true;
valAnnotation = ann;
break;
}
}
if (!found)
return;
// This is null only if the project is 1.4 or less. Lombok doesn't work in that.
if (modifiers == null)
return;
boolean finalIsPresent = false;
boolean valIsPresent = false;
for (Object present : modifiers) {
if (present instanceof Modifier) {
ModifierKeyword keyword = ((Modifier) present).getKeyword();
if (keyword == null)
continue;
if (keyword.toFlagValue() == Modifier.FINAL)
finalIsPresent = true;
}
if (present instanceof org.eclipse.jdt.core.dom.Annotation) {
Name typeName = ((org.eclipse.jdt.core.dom.Annotation) present).getTypeName();
if (typeName != null) {
String fullyQualifiedName = typeName.getFullyQualifiedName();
if ("val".equals(fullyQualifiedName) || "lombok.val".equals(fullyQualifiedName)) {
valIsPresent = true;
}
}
}
}
if (!finalIsPresent) {
modifiers.add(createModifier(ast, ModifierKeyword.FINAL_KEYWORD, valAnnotation.sourceStart, valAnnotation.sourceEnd));
}
if (!valIsPresent) {
MarkerAnnotation newAnnotation = createValAnnotation(ast, valAnnotation, valAnnotation.sourceStart, valAnnotation.sourceEnd);
try {
Reflection.astConverterRecordNodes.invoke(converter, newAnnotation, valAnnotation);
Reflection.astConverterRecordNodes.invoke(converter, newAnnotation.getTypeName(), valAnnotation.type);
} catch (IllegalAccessException e) {
throw Lombok.sneakyThrow(e);
} catch (InvocationTargetException e) {
throw Lombok.sneakyThrow(e.getCause());
}
modifiers.add(newAnnotation);
}
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class MemberVisibilityAdjustor method needsVisibilityAdjustments.
/**
* Does the specified member need further visibility adjustment?
*
* @param member the member to test
* @param threshold the visibility threshold to test for
* @param adjustments the map of members to visibility adjustments
* @return <code>true</code> if the member needs further adjustment, <code>false</code> otherwise
*/
public static boolean needsVisibilityAdjustments(final IMember member, final int threshold, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments) {
Assert.isNotNull(member);
Assert.isTrue(isVisibilityModifier(threshold));
Assert.isNotNull(adjustments);
final IncomingMemberVisibilityAdjustment adjustment = adjustments.get(member);
if (adjustment != null) {
final ModifierKeyword keyword = adjustment.getKeyword();
return hasLowerVisibility(keyword == null ? Modifier.NONE : keyword.toFlagValue(), threshold);
}
return true;
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class MemberVisibilityAdjustor method thresholdTypeToMethod.
/**
* Returns the visibility threshold from a type to a method.
*
* @param referencing the referencing type
* @param referenced the referenced method
* @param monitor the progress monitor to use
* @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
* @throws JavaModelException if the java elements could not be accessed
*/
private ModifierKeyword thresholdTypeToMethod(final IType referencing, final IMethod referenced, final IProgressMonitor monitor) throws JavaModelException {
final ICompilationUnit referencedUnit = referenced.getCompilationUnit();
ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
if (referenced.getDeclaringType().equals(referencing))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else {
final ITypeHierarchy hierarchy = getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
final IType[] types = hierarchy.getSupertypes(referencing);
IType superType = null;
for (int index = 0; index < types.length; index++) {
superType = types[index];
if (superType.equals(referenced.getDeclaringType())) {
keyword = ModifierKeyword.PROTECTED_KEYWORD;
return keyword;
}
}
}
final ICompilationUnit typeUnit = referencing.getCompilationUnit();
if (referencedUnit != null && referencedUnit.equals(typeUnit)) {
if (referenced.getDeclaringType().getDeclaringType() != null)
keyword = null;
else
keyword = ModifierKeyword.PRIVATE_KEYWORD;
} else if (referencedUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
keyword = null;
return keyword;
}
Aggregations