1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 13:25:45 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2009-04-25 23:44:29 +00:00
parent f39bda4cad
commit 5b8602978d

View file

@ -104,7 +104,6 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
public boolean isStandard() { public boolean isStandard() {
return isStandard; return isStandard;
} }
} }
public AddIncludeOnSelectionAction(ITextEditor editor) { public AddIncludeOnSelectionAction(ITextEditor editor) {
@ -127,7 +126,6 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Do nothing. Operation has been canceled. // Do nothing. Operation has been canceled.
} }
} }
protected ITranslationUnit getTranslationUnit () { protected ITranslationUnit getTranslationUnit () {
@ -156,8 +154,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
try { try {
extractIncludes(fEditor, index); extractIncludes(fEditor, index);
addInclude(tu); addInclude(tu);
} } finally {
finally {
index.releaseReadLock(); index.releaseReadLock();
} }
} catch (CoreException e) { } catch (CoreException e) {
@ -173,8 +170,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
* To be used by ElementListSelectionDialog for user to choose which declarations/ * To be used by ElementListSelectionDialog for user to choose which declarations/
* definitions for "add include" when there are more than one to choose from. * definitions for "add include" when there are more than one to choose from.
*/ */
private static class DisplayName extends Object private static class DisplayName extends Object {
{
private IIndexName name; private IIndexName name;
private IIndexBinding binding; private IIndexBinding binding;
@ -184,8 +180,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
} }
@Override @Override
public String toString() public String toString() {
{
try { try {
if (binding != null) { if (binding != null) {
return getBindingQualifiedName(binding) + " - " + name.getFileLocation().getFileName(); //$NON-NLS-1$ return getBindingQualifiedName(binding) + " - " + name.getFileLocation().getFileName(); //$NON-NLS-1$
@ -204,9 +199,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
public IIndexBinding getBinding() { public IIndexBinding getBinding() {
return binding; return binding;
} }
} }
/** /**
* Extract the includes for the given selection. This can be both used to perform * Extract the includes for the given selection. This can be both used to perform
@ -243,13 +236,14 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
fRequiredIncludes = fs.getIncludes(); fRequiredIncludes = fs.getIncludes();
String ns = fs.getNamespace(); String ns = fs.getNamespace();
if (ns != null && ns.length() > 0) { if (ns != null && ns.length() > 0) {
fUsings = new String[] {fs.getNamespace()}; fUsings = new String[] { fs.getNamespace() };
} }
} }
try { try {
IndexFilter filter= IndexFilter.ALL_DECLARED_OR_IMPLICIT; IndexFilter filter= IndexFilter.ALL_DECLARED_OR_IMPLICIT;
IIndexBinding[] bindings= index.findBindings(name.toCharArray(), false, filter, new NullProgressMonitor()); IIndexBinding[] bindings= index.findBindings(name.toCharArray(), false, filter,
new NullProgressMonitor());
ArrayList<DisplayName> pdomNames= new ArrayList<DisplayName>(); ArrayList<DisplayName> pdomNames= new ArrayList<DisplayName>();
for (int i = 0; i < bindings.length; ++i) { for (int i = 0; i < bindings.length; ++i) {
IIndexBinding binding= bindings[i]; IIndexBinding binding= bindings[i];
@ -257,8 +251,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
// class, struct union, enumeration // class, struct union, enumeration
if (binding instanceof ICompositeType || binding instanceof IEnumeration) { if (binding instanceof ICompositeType || binding instanceof IEnumeration) {
defs= index.findDefinitions(binding); defs= index.findDefinitions(binding);
} } else if (binding instanceof ITypedef || binding instanceof IFunction) {
else if (binding instanceof ITypedef || binding instanceof IFunction) {
defs= index.findDeclarations(binding); defs= index.findDeclarations(binding);
} }
if (defs != null) { if (defs != null) {
@ -268,8 +261,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
} }
} }
if (pdomNames.size() > 1) if (pdomNames.size() > 1) {
{
ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_NAME_ONLY)); ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_NAME_ONLY));
dialog.setElements(pdomNames.toArray()); dialog.setElements(pdomNames.toArray());
dialog.setTitle(CEditorMessages.AddIncludeOnSelection_label); dialog.setTitle(CEditorMessages.AddIncludeOnSelection_label);
@ -281,7 +273,8 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
fRequiredIncludes = new IRequiredInclude[selects.length]; fRequiredIncludes = new IRequiredInclude[selects.length];
List<String> usings = new ArrayList<String>(selects.length); List<String> usings = new ArrayList<String>(selects.length);
for (int i = 0; i < fRequiredIncludes.length; i++) { for (int i = 0; i < fRequiredIncludes.length; i++) {
IRequiredInclude include = getRequiredInclude(((DisplayName)selects[i]).getName().getFileLocation().getFileName(), getTranslationUnit()); IRequiredInclude include = getRequiredInclude(
((DisplayName)selects[i]).getName().getFileLocation().getFileName(), getTranslationUnit());
if (include != null) { if (include != null) {
fRequiredIncludes[i] = include; fRequiredIncludes[i] = include;
IIndexBinding binding = ((DisplayName)selects[i]).getBinding(); IIndexBinding binding = ((DisplayName)selects[i]).getBinding();
@ -295,7 +288,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
} }
} }
} }
if(usings.size() > 0) if (usings.size() > 0)
{ {
fUsings = new String[usings.size()]; fUsings = new String[usings.size()];
for (int i = 0; i < usings.size(); i++) for (int i = 0; i < usings.size(); i++)
@ -304,9 +297,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
} }
} }
} }
} } else if (pdomNames.size() == 1) {
else if (pdomNames.size() == 1)
{
// we should use the IIndexName.getLocation here rather than getFileLocation // we should use the IIndexName.getLocation here rather than getFileLocation
String fileName = (pdomNames.get(0)).getName().getFileLocation().getFileName(); String fileName = (pdomNames.get(0)).getName().getFileLocation().getFileName();
fRequiredIncludes = new IRequiredInclude[] {getRequiredInclude(fileName, getTranslationUnit())}; fRequiredIncludes = new IRequiredInclude[] {getRequiredInclude(fileName, getTranslationUnit())};
@ -332,9 +323,9 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
if (fRequiredIncludes == null && fUsings == null) { if (fRequiredIncludes == null && fUsings == null) {
} }
} catch (BadLocationException e) { } catch (BadLocationException e) {
MessageDialog.openError(getShell(), CEditorMessages.AddIncludeOnSelection_error_message3, CEditorMessages.AddIncludeOnSelection_error_message4 + e.getMessage()); MessageDialog.openError(getShell(), CEditorMessages.AddIncludeOnSelection_error_message3,
CEditorMessages.AddIncludeOnSelection_error_message4 + e.getMessage());
} }
} }
private IFunctionSummary findContribution (final String name) { private IFunctionSummary findContribution (final String name) {
@ -436,12 +427,11 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
* @return binding's fully qualified name * @return binding's fully qualified name
* @throws CoreException * @throws CoreException
*/ */
private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException {
{
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
String[] qname= binding.getQualifiedName(); String[] qname= binding.getQualifiedName();
for (int i = 0; i < qname.length; i++) { for (int i = 0; i < qname.length; i++) {
if (i>0) { if (i > 0) {
buf.append("::"); //$NON-NLS-1$ buf.append("::"); //$NON-NLS-1$
} }
buf.append(qname[i]); buf.append(qname[i]);