Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ds/org.eclipse.pde.ds.annotations/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.pde.ds.annotations;singleton:=true
Bundle-Version: 1.4.0.qualifier
Bundle-Version: 1.4.100.qualifier
Bundle-Activator: org.eclipse.pde.ds.internal.annotations.Activator
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.ui;bundle-version="[3.105.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ public String getReadableName(TextEdit edit) {
try {
latch.await();
} catch (InterruptedException e) {
if (debug.isDebugging())
if (debug.isDebugging()) {
debug.trace("Interrupted while waiting for edits to complete on display thread.", e); //$NON-NLS-1$
}
}

if (ex[0] != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,58 @@ public class ComponentPropertyTester extends PropertyTester {

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!"containsComponentWithImplicitName".equals(property)) //$NON-NLS-1$
if (!"containsComponentWithImplicitName".equals(property)) { //$NON-NLS-1$
return false;
}

if (!(receiver instanceof IType) && !(receiver instanceof IPackageFragment))
if (!(receiver instanceof IType) && !(receiver instanceof IPackageFragment)) {
return false;
}

IJavaElement element = (IJavaElement) receiver;
IJavaProject javaProject = element.getJavaProject();

boolean enabled = Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, Activator.PREF_ENABLED, false, new IScopeContext[] { new ProjectScope(javaProject.getProject()), InstanceScope.INSTANCE, DefaultScope.INSTANCE });
if (!enabled)
if (!enabled) {
return false;
}

try {
return element.getElementType() == IJavaElement.TYPE ? containsImplicitName((IType) receiver) : containsImplicitName((IPackageFragment) receiver);
} catch (JavaModelException e) {
if (debug.isDebugging())
if (debug.isDebugging()) {
debug.trace(String.format("Error searching for components with implicit names in element: %s", element), e); //$NON-NLS-1$
}
}

return false;
}

private boolean containsImplicitName(IPackageFragment fragment) throws JavaModelException {
if (!fragment.containsJavaResources())
if (!fragment.containsJavaResources()) {
return false;
}

for (ICompilationUnit cu : fragment.getCompilationUnits()) {
for (IType type : cu.getAllTypes()) {
if (hasImplicitName(type))
if (hasImplicitName(type)) {
return true;
}
}
}

return false;
}

private boolean containsImplicitName(IType type) throws JavaModelException {
if (hasImplicitName(type))
if (hasImplicitName(type)) {
return true;
}

for (IType child : type.getTypes()) {
if (hasImplicitName(child))
if (hasImplicitName(child)) {
return true;
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ public boolean initialize(Object element) {
}

private RefactoringArguments getArguments() {
if (participant instanceof RenameParticipant)
if (participant instanceof RenameParticipant) {
return ((RenameParticipant) participant).getArguments();
}

if (participant instanceof MoveParticipant)
if (participant instanceof MoveParticipant) {
return ((MoveParticipant) participant).getArguments();
}

return null;
}
Expand All @@ -110,19 +112,22 @@ public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditio
ResourceChangeChecker checker = context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
for (Map.Entry<Object, RefactoringArguments> entry : elements.entrySet()) {
if (progress.isCanceled())
if (progress.isCanceled()) {
throw new OperationCanceledException();
}

progress.worked(1);

RefactoringArguments args = entry.getValue();
if (!getUpdateReferences(args))
if (!getUpdateReferences(args)) {
continue;
}

IJavaElement element = (IJavaElement) entry.getKey();
IJavaProject javaProject = element.getJavaProject();
if (unmanaged.contains(javaProject))
if (unmanaged.contains(javaProject)) {
continue;
}

ProjectState state = states.get(javaProject);
if (state == null) {
Expand All @@ -136,10 +141,11 @@ public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditio

states.put(javaProject, state);

if (element.getElementType() == IJavaElement.TYPE)
if (element.getElementType() == IJavaElement.TYPE) {
createRenames((IType) element, args, state, deltaFactory);
else if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
} else if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
createRenames((IPackageFragment) element, args, state, deltaFactory);
}
}

return new RefactoringStatus();
Expand All @@ -150,11 +156,13 @@ else if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
}

private boolean getUpdateReferences(RefactoringArguments args) {
if (args instanceof RenameArguments)
if (args instanceof RenameArguments) {
return ((RenameArguments) args).getUpdateReferences();
}

if (args instanceof MoveArguments)
if (args instanceof MoveArguments) {
return ((MoveArguments) args).getUpdateReferences();
}

return false;
}
Expand Down Expand Up @@ -228,20 +236,23 @@ public Change createChange(IProgressMonitor monitor) throws CoreException, Opera
CompositeChange compositeChange = new CompositeChange(Messages.ComponentRefactoringHelper_topLevelChangeLabel);

for (Map.Entry<Object, RefactoringArguments> entry : elements.entrySet()) {
if (progress.isCanceled())
if (progress.isCanceled()) {
throw new OperationCanceledException();
}

progress.worked(1);

RefactoringArguments args = entry.getValue();
if (!getUpdateReferences(args))
if (!getUpdateReferences(args)) {
continue;
}

IJavaElement element = (IJavaElement) entry.getKey();
if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
collectChanges((IPackageFragment) element, compositeChange);
else if (element.getElementType() == IJavaElement.TYPE)
} else if (element.getElementType() == IJavaElement.TYPE) {
collectChanges((IType) element, compositeChange);
}
}

return compositeChange;
Expand All @@ -257,8 +268,9 @@ private void collectChanges(IPackageFragment fragment, CompositeChange composite

private void collectChanges(IType type, CompositeChange compositeChange) throws CoreException {
Change change = createChange(type);
if (change != null)
if (change != null) {
compositeChange.add(change);
}

for (IType child : type.getTypes()) {
collectChanges(child, compositeChange);
Expand All @@ -267,28 +279,33 @@ private void collectChanges(IType type, CompositeChange compositeChange) throws

private Change createChange(IType type) throws CoreException {
IFile modelFile = modelFiles.get(type);
if (modelFile == null)
if (modelFile == null) {
return null;
}

String componentName = componentNames.get(modelFile);
if (componentName == null)
if (componentName == null) {
return null;
}

IFile newModelFile = renames.get(modelFile);
if (newModelFile == null)
if (newModelFile == null) {
return null;
}

if (debug.isDebugging())
if (debug.isDebugging()) {
debug.trace(String.format("Changing %s from %s to %s.", type.getFullyQualifiedName(), modelFile.getFullPath(), newModelFile.getFullPath())); //$NON-NLS-1$
}

ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(modelFile.getFullPath(), LocationKind.IFILE, null);
DSModel model = null;
IDocumentAttributeNode attrName, attrClass;
try {
ITextFileBuffer buf = manager.getTextFileBuffer(modelFile.getFullPath(), LocationKind.IFILE);
if (buf == null)
if (buf == null) {
return null;
}

IDocument doc = buf.getDocument();
model = new DSModel(doc, false);
Expand All @@ -300,8 +317,9 @@ private Change createChange(IType type) throws CoreException {
attrName = component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_NAME);
attrClass = component.getImplementation().getDocumentAttribute(IDSConstants.ATTRIBUTE_IMPLEMENTATION_CLASS);
} finally {
if (model != null)
if (model != null) {
model.dispose();
}

manager.disconnect(modelFile.getFullPath(), LocationKind.IFILE, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,26 @@ public boolean isAnnotationProcessor() {
public boolean isActive(IJavaProject project) {
IPreferencesService prefs = Platform.getPreferencesService();
boolean enabled = prefs.getBoolean(Activator.PLUGIN_ID, Activator.PREF_ENABLED, false, new IScopeContext[] { new ProjectScope(project.getProject()), InstanceScope.INSTANCE, DefaultScope.INSTANCE });
if (!enabled)
if (!enabled) {
return false;
}

IProject iproject = project.getProject();
if (!iproject.isOpen() || !PluginProject.isPluginProject(iproject))
if (!iproject.isOpen() || !PluginProject.isPluginProject(iproject)) {
return false;
}

if (WorkspaceModelManager.isBinaryProject(project.getProject()))
if (WorkspaceModelManager.isBinaryProject(project.getProject())) {
return false;
}
return true;
}

@Override
public int aboutToBuild(IJavaProject project) {
if (debug.isDebugging())
if (debug.isDebugging()) {
debug.trace(String.format("About to build project: %s", project.getElementName())); //$NON-NLS-1$
}

int result = READY_FOR_BUILD;

Expand Down Expand Up @@ -220,8 +224,9 @@ private static ProjectState getState(IJavaProject project, int[] result) {

if (state == null) {
state = new ProjectState();
if (result != null && result.length > 0)
if (result != null && result.length > 0) {
result[0] = NEEDS_FULL_BUILD;
}
}

try {
Expand All @@ -237,8 +242,9 @@ private static ProjectState getState(IJavaProject project, int[] result) {
private static ProjectState loadState(IProject project) throws IOException {
File stateFile = getStateFile(project);
if (!stateFile.canRead()) {
if (debug.isDebugging())
if (debug.isDebugging()) {
debug.trace(String.format("Missing or invalid project state file: %s", stateFile)); //$NON-NLS-1$
}

return null;
}
Expand All @@ -248,8 +254,9 @@ private static ProjectState loadState(IProject project) throws IOException {

if (debug.isDebugging()) {
debug.trace(String.format("Loaded state for project: %s", project.getName())); //$NON-NLS-1$
for (String cuKey : state.getCompilationUnits())
for (String cuKey : state.getCompilationUnits()) {
debug.trace(String.format("%s -> %s", cuKey, state.getModelFiles(cuKey))); //$NON-NLS-1$
}
}

return state;
Expand All @@ -274,28 +281,32 @@ public void buildFinished(IJavaProject project) {
IResource file;
if (cu != null && cu.getElementType() == IJavaElement.COMPILATION_UNIT
&& (file = cu.getResource()) != null && file.exists()
&& file.getProject().equals(project.getProject()))
&& file.getProject().equals(project.getProject())) {
exists = true;
}
} catch (JavaModelException e) {
Activator.log(e);
}

if (!exists) {
if (debug.isDebugging())
if (debug.isDebugging()) {
debug.trace(String.format("Mapped CU %s no longer exists.", cuKey)); //$NON-NLS-1$
}

Collection<String> dsKeys = state.removeMappings(cuKey);
if (dsKeys != null)
if (dsKeys != null) {
abandoned.addAll(dsKeys);
}
}
}

// retain abandoned files that are still mapped elsewhere
HashSet<String> retained = new HashSet<>();
for (String cuKey : state.getCompilationUnits()) {
Collection<String> dsKeys = state.getModelFiles(cuKey);
if (dsKeys != null)
if (dsKeys != null) {
retained.addAll(dsKeys);
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ private Link createLink(Composite composite, String text) {
link.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
if (PreferencesUtil.createPreferenceDialogOn(getShell(), Activator.PLUGIN_ID, new String[] { Activator.PLUGIN_ID }, null).open() == Window.OK)
if (PreferencesUtil.createPreferenceDialogOn(getShell(), Activator.PLUGIN_ID, new String[] { Activator.PLUGIN_ID }, null).open() == Window.OK) {
refreshWidgets();
}
}

@Override
Expand Down
Loading
Loading