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);
}
}
}
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);
}
}
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());
}
}
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());
}
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;
}
Aggregations