Search in sources :

Example 1 with CompilationUnit

use of org.eclipse.jdt.internal.core.CompilationUnit in project che by eclipse.

the class RefactoringSession method prepareChangesInfo.

/**
     * Prepare the information about changes which were applied.
     *
     * @param changes array of the applied changes
     * @param changesInfo prepared list of {@link ChangeInfo}
     */
public void prepareChangesInfo(Change[] changes, List<ChangeInfo> changesInfo) {
    for (Change ch : changes) {
        if (ch instanceof DynamicValidationStateChange) {
            prepareChangesInfo(((DynamicValidationStateChange) ch).getChildren(), changesInfo);
        } else {
            ChangeInfo changeInfo = DtoFactory.newDto(ChangeInfo.class);
            String refactoringName = ch.getName();
            if (ch instanceof UndoTextFileChange) {
                changeInfo.setName(ChangeInfo.ChangeName.UPDATE);
                changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
            }
            if (refactoringName.startsWith("Rename")) {
                if (ch instanceof RenameCompilationUnitChange) {
                    prepareRenameCompilationUnitChange(changeInfo, ch);
                } else if (ch instanceof RenamePackageChange) {
                    prepareRenamePackageChange(changesInfo, changeInfo, ch);
                }
            }
            if (refactoringName.startsWith("Move")) {
                prepareMoveChange(changeInfo, ch);
            }
            changesInfo.add(changeInfo);
        }
    }
}
Also used : CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) MoveCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange) UndoTextFileChange(org.eclipse.ltk.core.refactoring.UndoTextFileChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) UndoTextFileChange(org.eclipse.ltk.core.refactoring.UndoTextFileChange) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)

Example 2 with CompilationUnit

use of org.eclipse.jdt.internal.core.CompilationUnit in project bndtools by bndtools.

the class ComponentDecorator method decorate.

@Override
public void decorate(Object element, IDecoration decoration) {
    try {
        if (element instanceof CompilationUnit) {
            CompilationUnit unit = (CompilationUnit) element;
            if (!isComponentInImports(unit)) {
                return;
            }
            IPackageDeclaration[] decs = unit.getPackageDeclarations();
            if (decs != null && decs.length > 0) {
                IPackageDeclaration dec = decs[0];
                if (dec != null) {
                    boolean found = false;
                    String customText = null;
                    for (IMarker marker : unit.getResource().findMarkers(BndtoolsConstants.MARKER_COMPONENT, true, IResource.DEPTH_ONE)) {
                        found = true;
                        customText = marker.getAttribute(IMarker.MESSAGE).toString();
                    }
                    if (found) {
                        decoration.addOverlay(componentIcon);
                        if (customText != null) {
                            if (customText.equals("OSGi Component")) {
                                decoration.addSuffix(" [Component]");
                            } else {
                                decoration.addSuffix(" [" + customText + "]");
                            }
                        }
                    }
                }
            }
        } else if (element instanceof SourceType) {
            SourceType type = (SourceType) element;
            if (!isComponentInImports(type.getCompilationUnit())) {
                return;
            }
            boolean found = false;
            String customText = null;
            for (IMarker marker : type.getCompilationUnit().getResource().findMarkers(BndtoolsConstants.MARKER_COMPONENT, true, IResource.DEPTH_ONE)) {
                found = true;
                customText = marker.getAttribute(IMarker.MESSAGE).toString();
            }
            if (found) {
                decoration.addOverlay(componentIcon);
                if (customText != null) {
                    if (customText.equals("OSGi Component")) {
                        decoration.addSuffix(" [Component]");
                    } else {
                        decoration.addSuffix(" [" + customText + "]");
                    }
                }
            }
        } else if (element instanceof IPackageFragment) {
            IPackageFragment frag = (IPackageFragment) element;
            IResource resource = (IResource) frag.getAdapter(IResource.class);
            if (resource != null && countComponents(resource)) {
                decoration.addOverlay(componentIcon);
            }
        }
    } catch (CoreException e) {
        logger.logError("Component Decorator error", e);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CoreException(org.eclipse.core.runtime.CoreException) SourceType(org.eclipse.jdt.internal.core.SourceType) IMarker(org.eclipse.core.resources.IMarker) IPackageDeclaration(org.eclipse.jdt.core.IPackageDeclaration) IResource(org.eclipse.core.resources.IResource)

Example 3 with CompilationUnit

use of org.eclipse.jdt.internal.core.CompilationUnit in project che by eclipse.

the class RefactoringSession method prepareMoveChange.

private void prepareMoveChange(ChangeInfo changeInfo, Change ch) {
    changeInfo.setName(ChangeInfo.ChangeName.MOVE);
    if (ch instanceof MoveCompilationUnitChange) {
        MoveCompilationUnitChange moveChange = (MoveCompilationUnitChange) ch;
        String className = moveChange.getCu().getPath().lastSegment();
        changeInfo.setOldPath(moveChange.getDestinationPackage().getPath().append(className).toString());
        changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
    }
}
Also used : CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) MoveCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)

Example 4 with CompilationUnit

use of org.eclipse.jdt.internal.core.CompilationUnit in project che by eclipse.

the class RefactoringSession method prepareRenameCompilationUnitChange.

private void prepareRenameCompilationUnitChange(ChangeInfo changeInfo, Change ch) {
    changeInfo.setName(ChangeInfo.ChangeName.RENAME_COMPILATION_UNIT);
    changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
    RenameCompilationUnitChange renameChange = (RenameCompilationUnitChange) ch;
    changeInfo.setOldPath(renameChange.getResourcePath().removeLastSegments(1).append(renameChange.getNewName()).toString());
}
Also used : CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)

Example 5 with CompilationUnit

use of org.eclipse.jdt.internal.core.CompilationUnit in project dsl-devkit by dsldevkit.

the class NewCheckCatalogWizardPage method getPackageFragment.

/**
 * Ensures that the project creation is done with the current package fragment.
 * Especially when the package name is changed.
 *
 * @return the current package fragment.
 */
@Override
public IPackageFragment getPackageFragment() {
    IPackageFragment packageFragment = super.getPackageFragment();
    if (previousPageIsProjectPage()) {
        if (getPackageText() == null || getPackageText().length() == 0) {
            packageFragment = createInitialFragment(((NewCheckProjectWizardPage) getPreviousPage()).getProjectName());
        } else {
            packageFragment = createInitialFragment(getPackageText());
        }
    } else if (this.element instanceof IPackageFragment && packageFragment.getElementName().length() == 0) {
        // initially, get the selected package (if selected).
        packageFragment = (IPackageFragment) this.element;
    } else if (this.element instanceof CompilationUnit && packageFragment.getElementName().length() == 0) {
        // This happens if a Java file is selected
        if (((CompilationUnit) this.element).getParent() instanceof IPackageFragment) {
            // NOPMD
            packageFragment = (IPackageFragment) ((CompilationUnit) this.element).getParent();
        }
    }
    // update projectInfo with current package fragment
    projectInfo.setPackageFragment(packageFragment);
    return packageFragment;
}
Also used : CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment)

Aggregations

CompilationUnit (org.eclipse.jdt.internal.core.CompilationUnit)5 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 MoveCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)2 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)2 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageDeclaration (org.eclipse.jdt.core.IPackageDeclaration)1 SourceType (org.eclipse.jdt.internal.core.SourceType)1 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)1 RenamePackageChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange)1 Change (org.eclipse.ltk.core.refactoring.Change)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1 UndoTextFileChange (org.eclipse.ltk.core.refactoring.UndoTextFileChange)1