use of org.eclipse.jdt.core.IInitializer in project che by eclipse.
the class JavaNavigation method convertToDTOInitializer.
private Initializer convertToDTOInitializer(IInitializer iInitializer) throws JavaModelException {
Initializer initializer = DtoFactory.newDto(Initializer.class);
initializer.setFileRegion(convertToDTORegion(iInitializer.getSourceRange()));
initializer.setElementName(iInitializer.getElementName());
initializer.setHandleIdentifier(iInitializer.getHandleIdentifier());
initializer.setFlags(iInitializer.getFlags());
initializer.setLabel(org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(iInitializer, org.eclipse.jdt.ui.JavaElementLabels.ALL_DEFAULT));
return initializer;
}
use of org.eclipse.jdt.core.IInitializer in project che by eclipse.
the class MemberVisibilityAdjustor method getVisibilityThreshold.
/**
* Computes the visibility threshold for the referenced element.
*
* @param referencing the referencing element
* @param referenced the referenced element
* @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
*/
public ModifierKeyword getVisibilityThreshold(final IJavaElement referencing, final IMember referenced, final IProgressMonitor monitor) throws JavaModelException {
Assert.isTrue(!(referencing instanceof IInitializer));
Assert.isTrue(!(referenced instanceof IInitializer));
ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
try {
//$NON-NLS-1$
monitor.beginTask("", 1);
monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
final int referencingType = referencing.getElementType();
final int referencedType = referenced.getElementType();
switch(referencedType) {
case IJavaElement.TYPE:
{
final IType typeReferenced = (IType) referenced;
final ICompilationUnit referencedUnit = typeReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.TYPE:
{
keyword = thresholdTypeToType((IType) referencing, typeReferenced, monitor);
break;
}
case IJavaElement.FIELD:
case IJavaElement.METHOD:
{
final IMember member = (IMember) referencing;
if (typeReferenced.equals(member.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.equals(member.getCompilationUnit()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (typeReferenced.getPackageFragment().equals(member.getDeclaringType().getPackageFragment()))
keyword = null;
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (typeReferenced.getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
case IJavaElement.FIELD:
{
final IField fieldReferenced = (IField) referenced;
final ICompilationUnit referencedUnit = fieldReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.TYPE:
{
keyword = thresholdTypeToField((IType) referencing, fieldReferenced, monitor);
break;
}
case IJavaElement.FIELD:
case IJavaElement.METHOD:
{
final IMember member = (IMember) referencing;
if (fieldReferenced.getDeclaringType().equals(member.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.equals(member.getCompilationUnit()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (fieldReferenced.getDeclaringType().getPackageFragment().equals(member.getDeclaringType().getPackageFragment()))
keyword = null;
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (fieldReferenced.getDeclaringType().getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
case IJavaElement.METHOD:
{
final IMethod methodReferenced = (IMethod) referenced;
final ICompilationUnit referencedUnit = methodReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.TYPE:
{
keyword = thresholdTypeToMethod((IType) referencing, methodReferenced, monitor);
break;
}
case IJavaElement.FIELD:
case IJavaElement.METHOD:
{
final IMember member = (IMember) referencing;
if (methodReferenced.getDeclaringType().equals(member.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.equals(member.getCompilationUnit()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (methodReferenced.getDeclaringType().getPackageFragment().equals(member.getDeclaringType().getPackageFragment()))
keyword = null;
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (methodReferenced.getDeclaringType().getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
default:
Assert.isTrue(false);
}
} finally {
monitor.done();
}
return keyword;
}
use of org.eclipse.jdt.core.IInitializer in project che by eclipse.
the class RefactoringHandleTransplanter method convertElements.
private IMember[] convertElements(IMember[] oldElements) {
final IMember[] newElements = new IMember[oldElements.length];
final IMember first = oldElements[0];
Assert.isTrue(first instanceof IType);
if (first.equals(fOldType))
// We renamed a top level type.
newElements[0] = fNewType;
else
newElements[0] = first;
for (int i = 1; i < oldElements.length; i++) {
final IJavaElement newParent = newElements[i - 1];
final IJavaElement currentElement = oldElements[i];
switch(newParent.getElementType()) {
case IJavaElement.TYPE:
{
switch(currentElement.getElementType()) {
case IJavaElement.TYPE:
{
final String newName = resolveTypeName((IType) currentElement);
newElements[i] = ((IType) newParent).getType(newName);
break;
}
case IJavaElement.METHOD:
{
final String newName = resolveElementName(currentElement);
final String[] newParameterTypes = resolveParameterTypes((IMethod) currentElement);
newElements[i] = ((IType) newParent).getMethod(newName, newParameterTypes);
break;
}
case IJavaElement.INITIALIZER:
{
final IInitializer initializer = (IInitializer) currentElement;
newElements[i] = ((IType) newParent).getInitializer(initializer.getOccurrenceCount());
break;
}
case IJavaElement.FIELD:
{
final String newName = resolveElementName(currentElement);
newElements[i] = ((IType) newParent).getField(newName);
break;
}
}
break;
}
case IJavaElement.METHOD:
{
switch(currentElement.getElementType()) {
case IJavaElement.TYPE:
{
newElements[i] = resolveTypeInMember((IMethod) newParent, (IType) currentElement);
break;
}
}
break;
}
case IJavaElement.INITIALIZER:
{
switch(currentElement.getElementType()) {
case IJavaElement.TYPE:
{
newElements[i] = resolveTypeInMember((IInitializer) newParent, (IType) currentElement);
break;
}
}
break;
}
case IJavaElement.FIELD:
{
switch(currentElement.getElementType()) {
case IJavaElement.TYPE:
{
// anonymous type in field declaration
newElements[i] = resolveTypeInMember((IField) newParent, (IType) currentElement);
break;
}
}
break;
}
}
}
return newElements;
}
use of org.eclipse.jdt.core.IInitializer in project che by eclipse.
the class JavaElementToDtoConverter method getInitializes.
private List<Initializer> getInitializes(Object parent) throws JavaModelException {
List<Initializer> result = new ArrayList<>();
Set<Object> objects = childrens.get(parent);
if (objects == null) {
return result;
}
for (Object object : objects) {
if (object instanceof IInitializer) {
IInitializer initializer = (IInitializer) object;
Initializer init = DtoFactory.newDto(Initializer.class);
init.setElementName(initializer.getElementName());
init.setHandleIdentifier(initializer.getHandleIdentifier());
init.setFlags(initializer.getFlags());
init.setLabel(JavaElementLabels.getElementLabel(initializer, JavaElementLabels.ALL_DEFAULT));
result.add(init);
}
}
return result;
}
use of org.eclipse.jdt.core.IInitializer in project che by eclipse.
the class JavaNavigation method convertToDTOType.
private Type convertToDTOType(IType iType) throws JavaModelException {
List<Type> types = new ArrayList<>();
List<Method> methods = new ArrayList<>();
List<Field> fields = new ArrayList<>();
List<Initializer> initializers = new ArrayList<>();
Type type = DtoFactory.newDto(Type.class);
setRootPath(iType, type);
type.setElementName(iType.getElementName());
type.setLabel(org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(iType, org.eclipse.jdt.ui.JavaElementLabels.ALL_DEFAULT));
type.setHandleIdentifier(iType.getHandleIdentifier());
type.setFlags(iType.getFlags());
type.setFileRegion(convertToDTORegion(iType.getNameRange()));
if (!iType.hasChildren()) {
type.setTypes(types);
return type;
}
IJavaElement[] children = iType.getChildren();
for (IJavaElement child : children) {
switch(child.getElementType()) {
case //type
7:
types.add(convertToDTOType((IType) child));
break;
case //field
8:
fields.add(convertToDTOField((IField) child));
break;
case //method
9:
methods.add(convertToDTOMethod((IMethod) child));
break;
case //initializer
10:
initializers.add(convertToDTOInitializer((IInitializer) child));
break;
default:
break;
}
}
type.setFields(fields);
type.setMethods(methods);
type.setInitializers(initializers);
type.setTypes(types);
return type;
}
Aggregations