1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2013-09-30 14:07:01 -07:00
parent 830c09b3be
commit 1e598a2202
3 changed files with 52 additions and 57 deletions

View file

@ -9,7 +9,6 @@
* Andrew Gvozdev - Initial API and implementation * Andrew Gvozdev - Initial API and implementation
* James Blackburn (Broadcom Corp.) * James Blackburn (Broadcom Corp.)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin; package org.eclipse.cdt.core.testplugin;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -27,8 +26,6 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import junit.framework.Assert;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@ -54,6 +51,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.junit.Assert;
/** /**
* This class contains utility methods for creating resources * This class contains utility methods for creating resources
@ -66,7 +64,6 @@ import org.eclipse.core.runtime.jobs.Job;
* *
* @since 6.0 * @since 6.0
*/ */
public class ResourceHelper { public class ResourceHelper {
private final static IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); private final static IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
private static final int MAX_RETRY= 5; private static final int MAX_RETRY= 5;
@ -112,7 +109,7 @@ public class ResourceHelper {
prjDescription.setLocation(absoluteLocation); prjDescription.setLocation(absoluteLocation);
} }
if (configurationIds!=null && configurationIds.length>0) { if (configurationIds != null && configurationIds.length > 0) {
ICProjectDescriptionManager prjDescManager = cdtCorePlugin.getProjectDescriptionManager(); ICProjectDescriptionManager prjDescManager = cdtCorePlugin.getProjectDescriptionManager();
project.create(NULL_MONITOR); project.create(NULL_MONITOR);
@ -122,7 +119,7 @@ public class ResourceHelper {
ICConfigurationDescription baseConfiguration = cdtCorePlugin.getPreferenceConfiguration(TestCfgDataProvider.PROVIDER_ID); ICConfigurationDescription baseConfiguration = cdtCorePlugin.getPreferenceConfiguration(TestCfgDataProvider.PROVIDER_ID);
for (String cfgId : configurationIds) { for (String cfgId : configurationIds) {
icPrjDescription.createConfiguration(cfgId, cfgId+" Name", baseConfiguration); icPrjDescription.createConfiguration(cfgId, cfgId + " Name", baseConfiguration);
} }
prjDescManager.setProjectDescription(project, icPrjDescription); prjDescManager.setProjectDescription(project, icPrjDescription);
} }
@ -193,7 +190,7 @@ public class ResourceHelper {
} }
/** /**
* Create a plain Eclipse project. * Creates a plain Eclipse project.
* *
* @param projectName * @param projectName
* @return the project handle * @return the project handle
@ -202,10 +199,11 @@ public class ResourceHelper {
public static IProject createProject(String projectName) throws CoreException { public static IProject createProject(String projectName) throws CoreException {
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IProject project= root.getProject(projectName); IProject project= root.getProject(projectName);
if (!project.exists()) if (!project.exists()) {
project.create(NULL_MONITOR); project.create(NULL_MONITOR);
else } else {
project.refreshLocal(IResource.DEPTH_INFINITE, null); project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
if (!project.isOpen()) if (!project.isOpen())
project.open(NULL_MONITOR); project.open(NULL_MONITOR);
@ -215,7 +213,7 @@ public class ResourceHelper {
} }
/** /**
* Delete project by name. * Deletes project by name.
* *
* @param projectName * @param projectName
* @throws CoreException * @throws CoreException
@ -228,7 +226,7 @@ public class ResourceHelper {
} }
/** /**
* Delete given project with content. * Deletes given project with content.
* *
* @param project * @param project
* @throws CoreException * @throws CoreException
@ -238,7 +236,7 @@ public class ResourceHelper {
} }
/** /**
* Delete project. * Deletes project.
* *
* @param project * @param project
* @param deleteContent whether to delete project content * @param deleteContent whether to delete project content
@ -377,7 +375,7 @@ public class ResourceHelper {
* @throws IOException if something goes wrong. * @throws IOException if something goes wrong.
*/ */
public static IPath createTemporaryFolder() throws CoreException, IOException { public static IPath createTemporaryFolder() throws CoreException, IOException {
return ResourceHelper.createWorkspaceFolder("tmp/"+System.currentTimeMillis()+'.'+UUID.randomUUID()); return ResourceHelper.createWorkspaceFolder("tmp/" + System.currentTimeMillis() + '.' + UUID.randomUUID());
} }
/** /**
@ -541,13 +539,12 @@ public class ResourceHelper {
* @throws CoreException... * @throws CoreException...
*/ */
public static IResource createSymbolicLink(IProject project, String linkName, IPath realPath) public static IResource createSymbolicLink(IProject project, String linkName, IPath realPath)
throws IOException, CoreException, UnsupportedOperationException { throws IOException, CoreException, UnsupportedOperationException {
if (!isSymbolicLinkSupported()) { if (!isSymbolicLinkSupported()) {
throw new UnsupportedOperationException("Windows links .lnk are not supported."); throw new UnsupportedOperationException("Windows links .lnk are not supported.");
} }
Assert.assertTrue("Path for symbolic link does not exist: [" + realPath.toOSString() +"]", Assert.assertTrue("Path for symbolic link does not exist: [" + realPath.toOSString() + "]",
new File(realPath.toOSString()).exists()); new File(realPath.toOSString()).exists());
IPath linkedPath = project.getLocation().append(linkName); IPath linkedPath = project.getLocation().append(linkName);
@ -589,16 +586,16 @@ public class ResourceHelper {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
try { try {
Assert.assertTrue("ln process exited with non-zero status", process.waitFor() == 0); Assert.assertTrue("ln process exited with non-zero status", process.waitFor() == 0);
// If exitValue succeeded, then the process has exitted successfully. // If exitValue succeeded, then the process has exited successfully.
break; break;
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Clear interrupted state, see Java bug http://bugs.sun.com/view_bug.do?bug_id=6420270 // Clear interrupted state, see Java bug http://bugs.sun.com/view_bug.do?bug_id=6420270
Thread.interrupted(); Thread.interrupted();
} }
// wait for a 500ms before checking again // Wait for a 500ms before checking again.
try { Thread.sleep(500); } catch (InterruptedException e) {/*don't care*/} try { Thread.sleep(500); } catch (InterruptedException e) {/*don't care*/}
} }
Assert.assertTrue("Symbolic link not created, command=[" + command +"]", linkPath.toFile().exists()); Assert.assertTrue("Symbolic link not created, command=[" + command + "]", linkPath.toFile().exists());
} }
/** /**
@ -616,8 +613,7 @@ public class ResourceHelper {
* @throws CoreException... * @throws CoreException...
*/ */
public static IResource createSymbolicLink(IProject project, String linkName, String realPath) public static IResource createSymbolicLink(IProject project, String linkName, String realPath)
throws IOException, CoreException, UnsupportedOperationException { throws IOException, CoreException, UnsupportedOperationException {
return createSymbolicLink(project, linkName, new Path(realPath)); return createSymbolicLink(project, linkName, new Path(realPath));
} }
@ -701,12 +697,13 @@ public class ResourceHelper {
// Remove IResources created by this helper // Remove IResources created by this helper
for (IResource r : resourcesCreated) { for (IResource r : resourcesCreated) {
if (r.exists()) if (r.exists()) {
try { try {
r.delete(true, NULL_MONITOR); r.delete(true, NULL_MONITOR);
} catch (CoreException e) { } catch (CoreException e) {
// Ignore // Ignore
} }
}
} }
resourcesCreated.clear(); resourcesCreated.clear();
} }
@ -732,13 +729,16 @@ public class ResourceHelper {
private static final void deleteRecursive(File f) throws IllegalArgumentException { private static final void deleteRecursive(File f) throws IllegalArgumentException {
// Ensure that the file being deleted is a child of the workspace // Ensure that the file being deleted is a child of the workspace
// root to prevent anything nasty happening // root to prevent anything nasty happening
if (! f.getAbsolutePath().startsWith( if (!f.getAbsolutePath().startsWith(
ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getAbsolutePath())) ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getAbsolutePath())) {
throw new IllegalArgumentException("File must exist within the workspace!"); throw new IllegalArgumentException("File must exist within the workspace!");
}
if (f.isDirectory()) if (f.isDirectory()) {
for (File f1 : f.listFiles()) for (File f1 : f.listFiles()) {
deleteRecursive(f1); deleteRecursive(f1);
}
}
f.delete(); f.delete();
} }
} }

View file

@ -6,12 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - Initial API and implementation * Markus Schorn - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.browser; package org.eclipse.cdt.internal.core.browser;
import java.util.Arrays;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.IFunctionInfo; import org.eclipse.cdt.core.browser.IFunctionInfo;
import org.eclipse.cdt.core.browser.IQualifiedTypeName; import org.eclipse.cdt.core.browser.IQualifiedTypeName;
@ -39,28 +37,19 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import java.util.Arrays;
/** /**
* Type info object needed to support search for local variables. * Type info object needed to support search for local variables.
* @since 5.0 * @since 5.0
*/ */
public class ASTTypeInfo implements ITypeInfo, IFunctionInfo { public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
private static int hashCode(String[] array) {
int prime = 31;
if (array == null)
return 0;
int result = 1;
for (String element : array) {
result = prime * result + (element == null ? 0 : element.hashCode());
}
return result;
}
private final String[] fqn; private final String[] fqn;
private final int elementType; private final int elementType;
private final String[] params; private final String[] params;
private final String returnType; private final String returnType;
private ASTTypeReference reference; private ASTTypeReference reference;
/** /**
* Creates a type info suitable for the binding. * Creates a type info suitable for the binding.
* @param name the name to create the type info object for. * @param name the name to create the type info object for.
@ -74,13 +63,11 @@ public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
elementType = IndexModelUtil.getElementType(binding); elementType = IndexModelUtil.getElementType(binding);
if (binding instanceof ICPPBinding) { if (binding instanceof ICPPBinding) {
fqn= ((ICPPBinding)binding).getQualifiedName(); fqn= ((ICPPBinding)binding).getQualifiedName();
} } else if (binding instanceof IField) {
else if (binding instanceof IField) {
IField field= (IField) binding; IField field= (IField) binding;
ICompositeType owner= field.getCompositeTypeOwner(); ICompositeType owner= field.getCompositeTypeOwner();
fqn= new String[] {owner.getName(), field.getName()}; fqn= new String[] {owner.getName(), field.getName()};
} } else {
else {
fqn= new String[] {binding.getName()}; fqn= new String[] {binding.getName()};
} }
if (binding instanceof IFunction) { if (binding instanceof IFunction) {
@ -106,7 +93,18 @@ public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
this.returnType= returnType; this.returnType= returnType;
this.reference= reference; this.reference= reference;
} }
private static int hashCode(String[] array) {
int prime = 31;
if (array == null)
return 0;
int result = 1;
for (String element : array) {
result = prime * result + (element == null ? 0 : element.hashCode());
}
return result;
}
@Override @Override
public int getCElementType() { public int getCElementType() {
return elementType; return elementType;
@ -114,7 +112,7 @@ public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
@Override @Override
public String getName() { public String getName() {
return fqn[fqn.length-1]; return fqn[fqn.length - 1];
} }
@Override @Override
@ -134,9 +132,9 @@ public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
@Override @Override
public ICProject getEnclosingProject() { public ICProject getEnclosingProject() {
if(getResolvedReference()!=null) { if (getResolvedReference()!=null) {
IProject project = reference.getProject(); IProject project = reference.getProject();
if(project!=null) { if (project != null) {
return CCorePlugin.getDefault().getCoreModel().getCModel().getCProject(project.getName()); return CCorePlugin.getDefault().getCoreModel().getCModel().getCProject(project.getName());
} }
} }
@ -148,9 +146,6 @@ public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
return params; return params;
} }
/*
* @see org.eclipse.cdt.internal.core.browser.IFunctionInfo#getReturnType()
*/
@Override @Override
public String getReturnType() { public String getReturnType() {
return returnType; return returnType;
@ -200,7 +195,7 @@ public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
if (fullPath != null) { if (fullPath != null) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath)); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath));
if (file != null) { if (file != null) {
return new ASTTypeReference(ifl, name.resolveBinding(), file, return new ASTTypeReference(ifl, name.resolveBinding(), file,
floc.getNodeOffset(), floc.getNodeLength()); floc.getNodeOffset(), floc.getNodeLength());
} }
} else { } else {
@ -213,7 +208,7 @@ public class ASTTypeInfo implements ITypeInfo, IFunctionInfo {
} }
return null; return null;
} }
@Override @Override
@Deprecated @Deprecated
public void addDerivedReference(ITypeReference location) { public void addDerivedReference(ITypeReference location) {

View file

@ -117,7 +117,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
} }
@Override @Override
public int visit( IASTDeclaration declaration ){ public int visit(IASTDeclaration declaration) {
if (declaration instanceof ICPPASTLinkageSpecification) if (declaration instanceof ICPPASTLinkageSpecification)
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
return PROCESS_SKIP; return PROCESS_SKIP;