Search in sources :

Example 1 with IInitializer

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;
}
Also used : Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) IInitializer(org.eclipse.jdt.core.IInitializer)

Example 2 with IInitializer

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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ModifierKeyword(org.eclipse.jdt.core.dom.Modifier.ModifierKeyword) IInitializer(org.eclipse.jdt.core.IInitializer) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IMember(org.eclipse.jdt.core.IMember) IType(org.eclipse.jdt.core.IType)

Example 3 with IInitializer

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IInitializer(org.eclipse.jdt.core.IInitializer) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IMember(org.eclipse.jdt.core.IMember) IType(org.eclipse.jdt.core.IType)

Example 4 with IInitializer

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;
}
Also used : Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) IInitializer(org.eclipse.jdt.core.IInitializer) IInitializer(org.eclipse.jdt.core.IInitializer) ArrayList(java.util.ArrayList)

Example 5 with IInitializer

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IInitializer(org.eclipse.jdt.core.IInitializer) ArrayList(java.util.ArrayList) Method(org.eclipse.che.ide.ext.java.shared.dto.model.Method) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) IField(org.eclipse.jdt.core.IField) JarEntryType(org.eclipse.che.ide.ext.java.shared.JarEntry.JarEntryType) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) IInitializer(org.eclipse.jdt.core.IInitializer) IMethod(org.eclipse.jdt.core.IMethod)

Aggregations

IInitializer (org.eclipse.jdt.core.IInitializer)6 IType (org.eclipse.jdt.core.IType)4 Initializer (org.eclipse.che.ide.ext.java.shared.dto.model.Initializer)3 IField (org.eclipse.jdt.core.IField)3 IJavaElement (org.eclipse.jdt.core.IJavaElement)3 IMethod (org.eclipse.jdt.core.IMethod)3 ArrayList (java.util.ArrayList)2 IMember (org.eclipse.jdt.core.IMember)2 JarEntryType (org.eclipse.che.ide.ext.java.shared.JarEntry.JarEntryType)1 Field (org.eclipse.che.ide.ext.java.shared.dto.model.Field)1 Method (org.eclipse.che.ide.ext.java.shared.dto.model.Method)1 Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)1 JavaElement (org.eclipse.jdt.internal.core.JavaElement)1