diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java index 1415840cd71..94daa372971 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java @@ -49,7 +49,7 @@ public class NamespaceTests extends PDOMTestBase { protected void setUp() throws Exception { if (pdom == null) { project = createProject("namespaceTests", true); - pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project); + pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); } pdom.acquireReadLock(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java index 4d200c290b8..692885ef7b6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Markus Schorn (Wind River Systems) + * Copyright (c) 2007, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -39,8 +39,8 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; /** - * Test the correctness of C/C++ searches - * + * Test the correctness of C/C++ searches. + * * @author Vivian Kong */ public class PDOMSearchTest extends PDOMTestBase { @@ -48,7 +48,8 @@ public class PDOMSearchTest extends PDOMTestBase { @Override public int compare(IBinding o1, IBinding o2) { return o1.getName().compareTo(o2.getName()); - }}; + } + }; protected ICProject project; protected PDOM pdom; @@ -58,14 +59,14 @@ public class PDOMSearchTest extends PDOMTestBase { public static Test suite() { return suite(PDOMSearchTest.class); } - + @Override protected void setUp() throws Exception { project = createProject("searchTests", true); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - + @Override protected void tearDown() throws Exception { pdom.releaseReadLock(); @@ -75,7 +76,7 @@ public class PDOMSearchTest extends PDOMTestBase { } /** - * Test the members inside namespaces + * Tests the members inside namespaces */ public void testNamespaces() throws Exception { /* Members in the namespace */ @@ -98,17 +99,17 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals(1, namespaces.length); assertTrue(namespaces[0] instanceof ICPPNamespace); assertEquals(namespace2, namespaces[0]); - + /* Namespace references */ IName[] refs = pdom.findNames(namespace1,IIndex.FIND_REFERENCES); assertEquals(3, refs.length); IASTFileLocation loc = refs[0].getFileLocation(); - assertEquals(offset("main.cpp","namespace1::Class1"), loc.getNodeOffset()); //character offset + assertEquals(offset("main.cpp", "namespace1::Class1"), loc.getNodeOffset()); //character offset loc = refs[1].getFileLocation(); - assertEquals(offset("Class1.cpp","namespace1::Class1::~Class1()"), loc.getNodeOffset()); //character offset + assertEquals(offset("Class1.cpp", "namespace1::Class1::~Class1()"), loc.getNodeOffset()); //character offset loc = refs[2].getFileLocation(); - assertEquals(offset("Class1.cpp","namespace1::Class1::Class1()"), loc.getNodeOffset()); //character offset - + assertEquals(offset("Class1.cpp", "namespace1::Class1::Class1()"), loc.getNodeOffset()); //character offset + /* Namespace declaration */ IName[] decls = pdom.findNames(namespace1, IIndex.FIND_DECLARATIONS); assertEquals(0, decls.length); @@ -117,11 +118,10 @@ public class PDOMSearchTest extends PDOMTestBase { IName[] defs = pdom.findNames(namespace1, IIndex.FIND_DEFINITIONS); assertEquals(1, defs.length); loc = defs[0].getFileLocation(); - assertEquals(offset("Class1.h","namespace namespace1") + 10, loc.getNodeOffset()); //character offset + assertEquals(offset("Class1.h", "namespace namespace1") + 10, loc.getNodeOffset()); //character offset } - public void testClasses() throws Exception { - // Bugzilla 160913 + public void testClasses_160913() throws Exception { // classes and nested classes /* Search for "Class1" */ @@ -148,7 +148,7 @@ public class PDOMSearchTest extends PDOMTestBase { methods = class2.getDeclaredMethods(); assertEquals(2, methods.length); if (methods[0].getName().equals("~Class1")) { - IBinding h= methods[1]; methods[1]= methods[0]; methods[0]=h; + IBinding h= methods[1]; methods[1]= methods[0]; methods[0]= h; } assertEquals("Class1", methods[0].getName()); assertEquals("~Class1", methods[1].getName()); @@ -206,11 +206,11 @@ public class PDOMSearchTest extends PDOMTestBase { /** result #3 * */ ICPPClassType cls4 = (ICPPClassType) class2s[2]; assertEquals("namespace1::Class2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(cls4))); - + /* Nested class references - namespace1::Class1::Class2 */ IName[] refs = pdom.findNames(cls3, IIndex.FIND_REFERENCES); assertEquals(0, refs.length); - + /* Nested class declaration */ IName[] decls = pdom.findNames(cls3, IIndex.FIND_DECLARATIONS); assertEquals(0, decls.length); @@ -219,7 +219,7 @@ public class PDOMSearchTest extends PDOMTestBase { IName[] defs = pdom.findNames(cls3, IIndex.FIND_DEFINITIONS); assertEquals(1, defs.length); IASTFileLocation loc = defs[0].getFileLocation(); - assertEquals(offset("Class1.h","class Class2 { //namespace1::Class1::Class2") + 6, loc.getNodeOffset()); //character offset + assertEquals(offset("Class1.h", "class Class2 { //namespace1::Class1::Class2") + 6, loc.getNodeOffset()); //character offset } public void testFunction() throws Exception { @@ -227,7 +227,7 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals(1, functions.length); assertTrue(functions[0] instanceof ICPPFunction); assertEquals("foo2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(functions[0]))); - + functions = pdom.findBindings(Pattern.compile("main"), false, INDEX_FILTER, NULL_MONITOR); assertEquals(1, functions.length); assertTrue(functions[0] instanceof ICPPFunction); @@ -258,39 +258,40 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals(1, variables.length); assertTrue(variables[0] instanceof ICPPVariable); assertEquals("var", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(variables[0]))); - + /* Variable references */ IName[] refs = pdom.findNames(variables[0], IIndex.FIND_REFERENCES); assertEquals(1, refs.length); IASTFileLocation loc = refs[0].getFileLocation(); - assertEquals(offset("main.cpp","var = 0;"), loc.getNodeOffset()); //character offset - + assertEquals(offset("main.cpp", "var = 0;"), loc.getNodeOffset()); // character offset + /* Variable declaration */ IName[] decls = pdom.findNames(variables[0], IIndex.FIND_DECLARATIONS_DEFINITIONS); assertEquals(1, decls.length); loc = decls[0].getFileLocation(); - assertEquals(offset("main.cpp","int var;") + 4, loc.getNodeOffset()); //character offset + assertEquals(offset("main.cpp", "int var;") + 4, loc.getNodeOffset()); // character offset /* Variable definition */ IName[] defs = pdom.findNames(variables[0], IIndex.FIND_DEFINITIONS); assertEquals(1, defs.length); loc = defs[0].getFileLocation(); - assertEquals(offset("main.cpp","int var;") + 4, loc.getNodeOffset()); //character offset + assertEquals(offset("main.cpp", "int var;") + 4, loc.getNodeOffset()); // character offset } /** - * Get the fully qualified name for a given PDOMBinding - * + * Returns the fully qualified name for a given PDOMBinding + * * @param pdomBinding * @return binding's fully qualified name * @throws CoreException */ - private String getBindingQualifiedName(PDOMBinding pdomBinding) throws CoreException { - StringBuffer buf = new StringBuffer(pdomBinding.getName()); + private static String getBindingQualifiedName(PDOMBinding pdomBinding) throws CoreException { + StringBuilder buf = new StringBuilder(pdomBinding.getName()); PDOMNode parent = pdomBinding.getParentNode(); while (parent != null) { if (parent instanceof PDOMBinding) { - buf.insert(0, ((PDOMBinding) parent).getName() + "::"); + String name = ((PDOMBinding) parent).getName(); + buf.insert(0, name + "::"); } parent = parent.getParentNode(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index 9b61ced1aed..c55f0b00875 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -91,7 +91,7 @@ public class PDOMTestBase extends BaseTestCase { try { importOp.run(monitor); } catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, 0, "Import Interrupted", e)); + throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, 0, "Import interrupted", e)); } cprojects[0] = cproject; diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeReference.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeReference.java index 1704fcffc5e..ed827c1934f 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeReference.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/ITypeReference.java @@ -22,7 +22,6 @@ import org.eclipse.core.runtime.IPath; * @noimplement This interface is not intended to be implemented by clients. */ public interface ITypeReference { - /** * Returns the full, absolute path of this reference * relative to the workspace, or null if no path can be @@ -30,7 +29,7 @@ public interface ITypeReference { */ public IPath getPath(); - /** + /** * Returns the absolute path in the local file system * to this reference, or null if no path can be * determined. diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java index 76c201a9858..f0a29e9e90c 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java @@ -85,14 +85,12 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { try { elementType = IndexModelUtil.getElementType(binding); if (binding instanceof ICPPBinding) { - fqn= ((ICPPBinding)binding).getQualifiedName(); - } - else if (binding instanceof IField) { + fqn= ((ICPPBinding) binding).getQualifiedName(); + } else if (binding instanceof IField) { IField field= (IField) binding; ICompositeType owner= field.getCompositeTypeOwner(); fqn= new String[] {owner.getName(), field.getName()}; - } - else { + } else { fqn= new String[] {binding.getName()}; } try { @@ -109,7 +107,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { return new IndexTypeInfo(fqn, flsq, elementType, index, paramTypes, returnType, null); } } catch (DOMException e) { - // index bindings don't throw DOMExceptions. + // Index bindings don't throw DOMExceptions. throw new AssertionError(); } @@ -128,12 +126,12 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { String[] params= null; if (ps != null) { params= new String[ps.length]; - int i=-1; + int i= -1; for (char[] p : ps) { params[++i]= new String(p); } } - return new IndexTypeInfo(new String[] {new String(name)}, ICElement.C_MACRO, params, null, index); + return new IndexTypeInfo(new String[] { new String(name) }, ICElement.C_MACRO, params, null, index); } /** @@ -143,7 +141,8 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { return new IndexTypeInfo(rhs, ref); } - private IndexTypeInfo(String[] fqn, IIndexFileLocation fileLocal, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) { + private IndexTypeInfo(String[] fqn, IIndexFileLocation fileLocal, int elementType, IIndex index, + String[] params, String returnType, ITypeReference reference) { Assert.isTrue(index != null); this.fqn= fqn; this.fileLocal= fileLocal; @@ -169,9 +168,9 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { @Override public ICProject getEnclosingProject() { - if(getResolvedReference()!=null) { + if (getResolvedReference() != null) { IProject project = reference.getProject(); - if(project!=null) { + if (project != null) { return CCorePlugin.getDefault().getCoreModel().getCModel().getCProject(project.getName()); } } @@ -180,7 +179,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { @Override public String getName() { - return fqn[fqn.length-1]; + return fqn[fqn.length - 1]; } @Override @@ -188,17 +187,11 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { return new QualifiedTypeName(fqn); } - /* - * @see org.eclipse.cdt.internal.core.browser.IFunctionInfo#getParameters() - */ @Override public String[] getParameters() { return params; } - /* - * @see org.eclipse.cdt.internal.core.browser.IFunctionInfo#getReturnType() - */ @Override public String getReturnType() { return returnType; @@ -232,8 +225,9 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { if (fileLocal == null) { if (other.fileLocal != null) return false; - } else if (!fileLocal.equals(other.fileLocal)) + } else if (!fileLocal.equals(other.fileLocal)) { return false; + } if (!Arrays.equals(fqn, other.fqn)) return false; if (!Arrays.equals(params, other.params)) @@ -250,7 +244,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { @Override public ITypeReference getResolvedReference() { - if(reference==null) { + if (reference == null) { if (elementType == ICElement.C_MACRO) { return createMacroReference(); } @@ -262,7 +256,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { } try { IIndexBinding[] ibs = findBindings(); - if(ibs.length>0) { + if (ibs.length > 0) { IIndexName[] names; names= index.findNames(ibs[0], IIndex.FIND_DEFINITIONS); if (names.length == 0) { @@ -275,8 +269,8 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { } } } - } catch(CoreException ce) { - CCorePlugin.log(ce); + } catch(CoreException e) { + CCorePlugin.log(e); } finally { index.releaseReadLock(); } @@ -286,13 +280,14 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { private IIndexBinding[] findBindings() throws CoreException { char[][] cfqn = new char[fqn.length][]; - for(int i=0; i0) { + if (macros.length > 0) { for (IIndexMacro macro : macros) { reference= createReference(macro); if (reference != null) { @@ -341,8 +333,8 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { } } } - } catch(CoreException ce) { - CCorePlugin.log(ce); + } catch(CoreException e) { + CCorePlugin.log(e); } finally { index.releaseReadLock(); } @@ -382,7 +374,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { return getMacroReferences(); } - List references= new ArrayList(); + List references= new ArrayList<>(); try { index.acquireReadLock(); } catch (InterruptedException ie) { @@ -391,7 +383,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { } try { IIndexBinding[] ibs= findBindings(); - HashMap iflMap= new HashMap(); + HashMap iflMap= new HashMap<>(); for (IIndexBinding binding : ibs) { IIndexName[] names; names= index.findNames(binding, IIndex.FIND_DEFINITIONS); @@ -415,9 +407,8 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { return references.toArray(new IndexTypeReference[references.size()]); } - private ITypeReference[] getMacroReferences() { - List references= new ArrayList(); + List references= new ArrayList<>(); try { index.acquireReadLock(); } catch (InterruptedException e) { @@ -429,7 +420,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { IIndexMacro[] ibs = index.findMacros(cfn, IndexFilter.ALL_DECLARED, new NullProgressMonitor()); // in case a file is represented multiple times in the index then we take references from // one of those, only. - HashMap iflMap= new HashMap(); + HashMap iflMap= new HashMap<>(); for (IIndexMacro macro : ibs) { if (checkParameters(macro.getParameterList())) { if (checkFile(iflMap, macro.getFile())) { @@ -440,8 +431,8 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { } } } - } catch(CoreException ce) { - CCorePlugin.log(ce); + } catch (CoreException e) { + CCorePlugin.log(e); } finally { index.releaseReadLock(); } @@ -566,7 +557,6 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { throw new UnsupportedOperationException(); } - /** * @deprecated * @noreference This method is not intended to be referenced by clients. @@ -588,7 +578,6 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { throw new UnsupportedOperationException(); } - /** * @deprecated * @noreference This method is not intended to be referenced by clients. diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/IndexModelUtil.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/IndexModelUtil.java index eeeb4b3d474..1df5c1a718f 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/IndexModelUtil.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/IndexModelUtil.java @@ -43,26 +43,27 @@ public class IndexModelUtil { /** * Returns whether the binding is of any of the specified CElement type constants + * * @param binding * @param kinds * @return whether the binding is of any of the specified CElement type constants */ public static boolean bindingHasCElementType(IBinding binding, int[] kinds) { for (int kind : kinds) { - switch(kind) { + switch (kind) { case ICElement.C_STRUCT: if (binding instanceof ICompositeType - && ((ICompositeType)binding).getKey() == ICompositeType.k_struct) + && ((ICompositeType) binding).getKey() == ICompositeType.k_struct) return true; break; case ICElement.C_UNION: if (binding instanceof ICompositeType - && ((ICompositeType)binding).getKey() == ICompositeType.k_union) + && ((ICompositeType) binding).getKey() == ICompositeType.k_union) return true; break; case ICElement.C_CLASS: if (binding instanceof ICompositeType - && ((ICompositeType)binding).getKey() == ICPPClassType.k_class) + && ((ICompositeType) binding).getKey() == ICPPClassType.k_class) return true; break; case ICElement.C_NAMESPACE: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 7ba7a545bc8..2798bc7cbd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -877,7 +877,8 @@ public class PDOM extends PlatformObject implements IPDOM { return findBindings(names, true, filter, monitor); } - public IIndexFragmentBinding[] findBindings(char[][] names, boolean caseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException { + public IIndexFragmentBinding[] findBindings(char[][] names, boolean caseSensitive, IndexFilter filter, + IProgressMonitor monitor) throws CoreException { if (names.length == 0) { return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; } @@ -885,7 +886,7 @@ public class PDOM extends PlatformObject implements IPDOM { return findBindings(names[0], true, caseSensitive, filter, monitor); } - IIndexFragmentBinding[] candidates = findBindings(names[names.length-1], false, caseSensitive, filter, monitor); + IIndexFragmentBinding[] candidates = findBindings(names[names.length - 1], false, caseSensitive, filter, monitor); int j= 0; for (int i = 0; i < candidates.length; i++) { IIndexFragmentBinding cand = candidates[i]; @@ -893,12 +894,11 @@ public class PDOM extends PlatformObject implements IPDOM { candidates[j++]= cand; } } - return ArrayUtil.trimAt(IIndexFragmentBinding.class, candidates, j-1); + return ArrayUtil.trimAt(IIndexFragmentBinding.class, candidates, j - 1); } private boolean matches(IIndexFragmentBinding cand, char[][] names, boolean caseSensitive) { - int i= names.length-1; - while(i >= 0) { + for (int i= names.length; --i >= 0; cand= cand.getOwner()) { if (cand == null) return false; @@ -913,8 +913,6 @@ public class PDOM extends PlatformObject implements IPDOM { return false; } } - cand= cand.getOwner(); - i--; } return cand == null; } @@ -1210,8 +1208,7 @@ public class PDOM extends PlatformObject implements IPDOM { names.add(name); } } - IPDOMIterator iterator = pdomBinding.getExternalReferences(); - while(iterator.hasNext()) { + for (IPDOMIterator iterator = pdomBinding.getExternalReferences(); iterator.hasNext();) { name = iterator.next(); if (isCommitted(name)) names.add(name); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMIterator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMIterator.java index f9e5143a273..30db3eadb8e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMIterator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMIterator.java @@ -18,7 +18,6 @@ import org.eclipse.core.runtime.CoreException; * a way to remove elements. */ public interface IPDOMIterator { - /** * Return true if the next call to #next will yield a value and false otherwise. * diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java index a99d230af20..893d9cfb11d 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java @@ -70,7 +70,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { * The last used prefix to query the index. null means * the query result should be empty. */ - private volatile char[] fCurrentPrefix = null; + private volatile char[] fCurrentPrefix; public UpdateElementsJob(String name) { super(name); @@ -134,7 +134,8 @@ public class ElementSelectionDialog extends TypeSelectionDialog { if (!shell.isDisposed() && fDone) { fMonitor.done(); } - }}; + } + }; shell.getDisplay().asyncExec(update); } } @@ -150,7 +151,8 @@ public class ElementSelectionDialog extends TypeSelectionDialog { if (!shell.isDisposed() && !fDone) { fMonitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN); } - }}; + } + }; shell.getDisplay().asyncExec(update); } } @@ -164,7 +166,8 @@ public class ElementSelectionDialog extends TypeSelectionDialog { @Override public boolean isConflicting(ISchedulingRule rule) { return rule == this; - }}; + } + }; private UpdateElementsJob fUpdateJob; private boolean fAllowEmptyPrefix= true; @@ -175,6 +178,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { /** * Constructs an instance of OpenTypeDialog. + * * @param parent the parent shell. */ public ElementSelectionDialog(Shell parent) { @@ -185,9 +189,6 @@ public class ElementSelectionDialog extends TypeSelectionDialog { fUpdateJob.setRule(SINGLE_INSTANCE_RULE); } - /* - * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#create() - */ @Override public void create() { super.create(); @@ -195,9 +196,6 @@ public class ElementSelectionDialog extends TypeSelectionDialog { scheduleUpdate(getFilter()); } - /* - * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#close() - */ @Override public boolean close() { fUpdateJob.cancel(); @@ -205,7 +203,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { } /** - * Configure the help context id for this dialog. + * Configures the help context id for this dialog. * * @param helpContextId */ @@ -214,9 +212,6 @@ public class ElementSelectionDialog extends TypeSelectionDialog { setHelpAvailable(fHelpContextId != null); } - /* - * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#setMatchEmptyString(boolean) - */ @Override public void setMatchEmptyString(boolean matchEmptyString) { super.setMatchEmptyString(matchEmptyString); @@ -227,7 +222,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { } /** - * Set whether an empty prefix should be allowed for queries. + * Sets whether an empty prefix should be allowed for queries. * * @param allowEmptyPrefix */ @@ -235,27 +230,18 @@ public class ElementSelectionDialog extends TypeSelectionDialog { fAllowEmptyPrefix = allowEmptyPrefix; } - /* - * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#showLowLevelFilter() - */ @Override protected boolean showLowLevelFilter() { - // the low-level filter is useless for us + // The low-level filter is useless for us. return false; } - /* - * @see org.eclipse.ui.dialogs.TwoPaneElementSelector#createDialogArea(org.eclipse.swt.widgets.Composite) - */ @Override public Control createDialogArea(Composite parent) { PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, fHelpContextId); return super.createDialogArea(parent); } - /* - * @see org.eclipse.ui.dialogs.TwoPaneElementSelector#createLowerList(org.eclipse.swt.widgets.Composite) - */ @Override protected Table createLowerList(Composite parent) { Table table= super.createLowerList(parent); @@ -264,8 +250,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { } /** - * Create the control for progress reporting. - * @param parent + * Creates the control for progress reporting. */ private void createProgressMonitorPart(Composite parent) { fProgressMonitorPart= new ProgressMonitorPart(parent, new GridLayout(2, false)); @@ -281,16 +266,13 @@ public class ElementSelectionDialog extends TypeSelectionDialog { } /** - * Query the elements for the given prefix. - * - * @param prefix - * @param monitor + * Queries the elements for the given prefix. */ protected ITypeInfo[] getElementsByPrefix(char[] prefix, IProgressMonitor monitor) { if (monitor.isCanceled()) { return null; } - HashSet types = new HashSet(); + HashSet types = new HashSet<>(); if (prefix != null) { final IndexFilter filter= new IndexFilter() { @Override @@ -327,9 +309,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { } finally { index.releaseReadLock(); } - } catch (CoreException e) { - CUIPlugin.log(e); - } catch (InterruptedException e) { + } catch (CoreException | InterruptedException e) { CUIPlugin.log(e); } } @@ -345,9 +325,6 @@ public class ElementSelectionDialog extends TypeSelectionDialog { throw new UnsupportedOperationException(); } - /* (non-Javadoc) - * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#handleElementsChanged() - */ @Override protected void handleElementsChanged() { updateOkState(); diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java index ba6d7896852..1c40fcf7214 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java @@ -41,18 +41,12 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility; * @noextend This class is not intended to be subclassed by clients. */ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { - private IWorkbenchWindow fWorkbenchWindow; public OpenTypeAction() { super(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ @Override public void run(IAction action) { ElementSelectionDialog dialog = new ElementSelectionDialog(getShell()); @@ -67,12 +61,12 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { ITypeReference location = info.getResolvedReference(); if (location == null) { - // could not resolve location + // Could not resolve location. String title = OpenTypeMessages.OpenTypeAction_errorTitle; String message = NLS.bind(OpenTypeMessages.OpenTypeAction_errorTypeNotFound, info.getQualifiedTypeName().toString()); MessageDialog.openError(getShell(), title, message); } else if (!openTypeInEditor(location)) { - // error opening editor + // Error opening editor. String title = OpenTypeMessages.OpenTypeAction_errorTitle; String message = NLS.bind(OpenTypeMessages.OpenTypeAction_errorOpenEditor, location.getPath().toString()); MessageDialog.openError(getShell(), title, message); @@ -91,7 +85,7 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { ISelection sel= ((ITextEditor) part).getSelectionProvider().getSelection(); if (sel instanceof ITextSelection) { String txt= ((ITextSelection) sel).getText(); - if (txt.length() > 0 && txt.length() < 80) { + if (!txt.isEmpty() && txt.length() < 80) { dialog.setFilter(txt, true); } } @@ -108,7 +102,7 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { * Opens an editor and displays the selected type. * * @param info Type to display. - * @return true if succesfully displayed. + * @return true if successfully displayed. */ private boolean openTypeInEditor(ITypeReference location) { ICElement[] cElements= location.getCElements(); @@ -124,11 +118,11 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { if (unit != null) editorPart = EditorUtility.openInEditor(unit); if (editorPart == null) { - // open as external file + // Open as external file. editorPart = EditorUtility.openInEditor(location.getLocation(), null); } - // highlight the type in the editor + // Highlight the type in the editor. if (editorPart != null && editorPart instanceof ITextEditor) { ITextEditor editor = (ITextEditor) editorPart; if( location.isLineNumber() ) @@ -160,32 +154,16 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { return false; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() - */ @Override public void dispose() { fWorkbenchWindow= null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) - */ @Override public void init(IWorkbenchWindow window) { fWorkbenchWindow= window; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, - * org.eclipse.jface.viewers.ISelection) - */ @Override public void selectionChanged(IAction action, ISelection selection) { } diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java index 63cb95af127..5f76eb63e0b 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java @@ -15,7 +15,6 @@ package org.eclipse.cdt.internal.ui.browser.opentype; import org.eclipse.swt.widgets.Shell; - /** * A dialog to select a type from a list of types. * @@ -25,7 +24,6 @@ import org.eclipse.swt.widgets.Shell; */ @Deprecated public class OpenTypeDialog extends ElementSelectionDialog { - /** * Constructs an instance of OpenTypeDialog. * @param parent the parent shell. diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.java index 5241f2a463b..574ea7660fa 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.java @@ -17,9 +17,6 @@ import org.eclipse.osgi.util.NLS; * @noinstantiate This class is not intended to be instantiated by clients. */ public final class OpenTypeMessages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages";//$NON-NLS-1$ - private OpenTypeMessages() { // Do not instantiate } @@ -33,6 +30,6 @@ public final class OpenTypeMessages extends NLS { public static String ElementSelectionDialog_UpdateElementsJob_inProgress; static { - NLS.initializeMessages(BUNDLE_NAME, OpenTypeMessages.class); + NLS.initializeMessages(OpenTypeMessages.class.getName(), OpenTypeMessages.class); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java index 24d8faf239f..0d2cd5506a0 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java @@ -56,19 +56,15 @@ import org.eclipse.cdt.internal.ui.util.StringMatcher; public class TypeSelectionDialog extends TwoPaneElementSelector { private static class TypeFilterMatcher implements FilteredList.FilterMatcher { - private static final char END_SYMBOL = '<'; private static final char ANY_STRING = '*'; - private StringMatcher fNameMatcher = null; - private StringMatcher[] fSegmentMatchers = null; - private boolean fMatchGlobalNamespace = false; + private StringMatcher fNameMatcher; + private StringMatcher[] fSegmentMatchers; + private boolean fMatchGlobalNamespace; private Collection fVisibleTypes = new HashSet(); - private boolean fShowLowLevelTypes = false; + private boolean fShowLowLevelTypes; - /* - * @see FilteredList.FilterMatcher#setFilter(String, boolean) - */ @Override public void setFilter(String pattern, boolean ignoreCase, boolean ignoreWildCards) { // parse pattern into segments @@ -77,7 +73,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { int length = segments.length; // append wildcard to innermost segment - segments[length-1] = adjustPattern(segments[length-1]); + segments[length - 1] = adjustPattern(segments[length - 1]); fMatchGlobalNamespace = false; fSegmentMatchers = new StringMatcher[length]; @@ -121,9 +117,6 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { return fShowLowLevelTypes; } - /* - * @see FilteredList.FilterMatcher#match(Object) - */ @Override public boolean match(Object element) { if (!(element instanceof ITypeInfo)) @@ -151,7 +144,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { if (fMatchGlobalNamespace) { // must match global namespace (eg ::foo) - if (qualifiedName.segment(0).length() > 0) + if (!qualifiedName.segment(0).isEmpty()) return false; } @@ -172,10 +165,10 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { int length = pattern.length(); if (length > 0) { switch (pattern.charAt(length - 1)) { - case END_SYMBOL: - return pattern.substring(0, length - 1); - case ANY_STRING: - return pattern; + case END_SYMBOL: + return pattern.substring(0, length - 1); + case ANY_STRING: + return pattern; } } return pattern + ANY_STRING; @@ -289,10 +282,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { public void setDialogSettings(String section) { fDialogSection = section + "Settings"; //$NON-NLS-1$ } - - /* (non-Javadoc) - * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilterText(org.eclipse.swt.widgets.Composite) - */ + @Override protected Text createFilterText(Composite parent) { fTextWidget = super.createFilterText(parent); @@ -303,9 +293,6 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { return fTextWidget; } - /* (non-Javadoc) - * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilteredList(org.eclipse.swt.widgets.Composite) - */ @Override protected FilteredList createFilteredList(Composite parent) { fNewFilteredList = super.createFilteredList(parent); @@ -325,9 +312,6 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { return fNewFilteredList; } - /* (non-Javadoc) - * @see org.eclipse.jface.window.Window#create() - */ @Override public void create() { super.create(); @@ -335,18 +319,12 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { fTextWidget.selectAll(); } - /* - * @see Window#close() - */ @Override public boolean close() { writeSettings(getDialogSettings()); return super.close(); } - /* - * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite) - */ @Override protected Control createContents(Composite parent) { readSettings(getDialogSettings()); @@ -360,38 +338,38 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { String name; int type = typeObject.intValue(); switch (type) { - case ICElement.C_NAMESPACE: - name = TypeInfoMessages.TypeSelectionDialog_filterNamespaces; + case ICElement.C_NAMESPACE: + name = TypeInfoMessages.TypeSelectionDialog_filterNamespaces; break; - case ICElement.C_CLASS: - name = TypeInfoMessages.TypeSelectionDialog_filterClasses; + case ICElement.C_CLASS: + name = TypeInfoMessages.TypeSelectionDialog_filterClasses; break; - case ICElement.C_STRUCT: - name = TypeInfoMessages.TypeSelectionDialog_filterStructs; + case ICElement.C_STRUCT: + name = TypeInfoMessages.TypeSelectionDialog_filterStructs; break; - case ICElement.C_TYPEDEF: - name = TypeInfoMessages.TypeSelectionDialog_filterTypedefs; + case ICElement.C_TYPEDEF: + name = TypeInfoMessages.TypeSelectionDialog_filterTypedefs; break; - case ICElement.C_ENUMERATION: - name = TypeInfoMessages.TypeSelectionDialog_filterEnums; + case ICElement.C_ENUMERATION: + name = TypeInfoMessages.TypeSelectionDialog_filterEnums; break; - case ICElement.C_UNION: - name = TypeInfoMessages.TypeSelectionDialog_filterUnions; + case ICElement.C_UNION: + name = TypeInfoMessages.TypeSelectionDialog_filterUnions; break; - case ICElement.C_FUNCTION: - name = TypeInfoMessages.TypeSelectionDialog_filterFunctions; + case ICElement.C_FUNCTION: + name = TypeInfoMessages.TypeSelectionDialog_filterFunctions; break; - case ICElement.C_VARIABLE: - name = TypeInfoMessages.TypeSelectionDialog_filterVariables; + case ICElement.C_VARIABLE: + name = TypeInfoMessages.TypeSelectionDialog_filterVariables; break; - case ICElement.C_ENUMERATOR: - name = TypeInfoMessages.TypeSelectionDialog_filterEnumerators; + case ICElement.C_ENUMERATOR: + name = TypeInfoMessages.TypeSelectionDialog_filterEnumerators; break; - case ICElement.C_MACRO: - name = TypeInfoMessages.TypeSelectionDialog_filterMacros; + case ICElement.C_MACRO: + name = TypeInfoMessages.TypeSelectionDialog_filterMacros; break; - default: - return; + default: + return; } Image icon = TypeInfoLabelProvider.getTypeIcon(type); @@ -625,9 +603,6 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { return true; } - /* (non-Cdoc) - * @see org.eclipse.jface.window.Window#getInitialSize() - */ @Override protected Point getInitialSize() { Point result = super.getInitialSize(); @@ -641,9 +616,6 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { return result; } - /* (non-Cdoc) - * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) - */ @Override protected Point getInitialLocation(Point initialSize) { Point result = super.getInitialLocation(initialSize); @@ -663,23 +635,20 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { return result; } - /* - * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult() - */ @Override protected void computeResult() { ITypeInfo selection = (ITypeInfo) getLowerSelectedElement(); if (selection == null) return; - List result = new ArrayList(1); + List result = new ArrayList<>(1); result.add(selection); setResult(result); } @Override public Object[] getFoldedElements(int index) { - ArrayList result= new ArrayList(); + ArrayList result= new ArrayList<>(); Object[] typeInfos= super.getFoldedElements(index); if (typeInfos != null) { for (Object typeInfo : typeInfos) {