sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.util/src/com/nokia/carbide/cpp/pi/util/SourceLookup.java
changeset 12 ae255c9aa552
parent 2 b9ab3b238396
equal deleted inserted replaced
11:5b9d4d8641ce 12:ae255c9aa552
    17 
    17 
    18 package com.nokia.carbide.cpp.pi.util;
    18 package com.nokia.carbide.cpp.pi.util;
    19 
    19 
    20 import java.util.ArrayList;
    20 import java.util.ArrayList;
    21 import java.util.List;
    21 import java.util.List;
       
    22 import java.util.logging.Logger;
    22 import java.util.regex.Pattern;
    23 import java.util.regex.Pattern;
    23 
    24 
    24 import org.eclipse.cdt.core.CCorePlugin;
    25 import org.eclipse.cdt.core.CCorePlugin;
    25 import org.eclipse.cdt.core.dom.ILinkage;
    26 import org.eclipse.cdt.core.dom.ILinkage;
    26 import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
    27 import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
    61 
    62 
    62 public class SourceLookup {
    63 public class SourceLookup {
    63 	private static SourceLookup instance = null;
    64 	private static SourceLookup instance = null;
    64 	
    65 	
    65 	public static SourceLookup getInstance() {
    66 	public static SourceLookup getInstance() {
    66 		if (instance == null)
    67 		if (instance == null){
    67 			instance = new SourceLookup();
    68 			instance = new SourceLookup();
       
    69 		}
    68 		return instance;
    70 		return instance;
    69 	}
    71 	}
    70 	
    72 	
    71 	private SourceLookup () {
    73 	private SourceLookup () {
    72 		// singleton
    74 		// singleton
    73 	}
    75 	}
    74 	
    76 	
    75 	public void lookupAndopenEditorWithHighlight(String symbolName, String binaryName) {
    77 	public void lookupAndopenEditorWithHighlight(final String symbolName, final String binaryName) {
    76 		IASTFileLocation[] locations = lookupLocations(symbolName, binaryName);
    78 		final IASTFileLocation[] locations = lookupLocations(symbolName, binaryName);
    77 		final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    79 		final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    78 		if (locations.length <= 0) {
    80 		if (locations.length <= 0) {
    79 			GeneralMessages.showErrorMessage(Messages.getString("SourceLookup.notfound") + "\n" + symbolName); //$NON-NLS-1$	//$NON-NLS-2$
    81 			GeneralMessages.showErrorMessage(Messages.getString("SourceLookup.notfound") + "\n" + symbolName); //$NON-NLS-1$	//$NON-NLS-2$
    80 			return;
    82 			return;
    81 		}
    83 		}
    82 		
    84 		
    83 		if (locations.length > 1) {
    85 		if (locations.length > 1) {
    84 			SourceLookupFileChooserDialog dialog = new SourceLookupFileChooserDialog(shell, locations);
    86 			final SourceLookupFileChooserDialog dialog = new SourceLookupFileChooserDialog(shell, locations);
    85 			if (dialog.open() == Window.OK && dialog.getLocation() != null) {
    87 			if (dialog.open() == Window.OK && dialog.getLocation() != null) {
    86 				openEditorWithHighlight(dialog.getLocation());
    88 				openEditorWithHighlight(dialog.getLocation());
    87 			}
    89 			}
    88 		} else {
    90 		} else {
    89 			openEditorWithHighlight(locations[0]);
    91 			openEditorWithHighlight(locations[0]);
    90 		}
    92 		}
    91 	}
    93 	}
    92 	
    94 	
    93 	private void openEditorWithHighlight(IASTFileLocation location) {
    95 	private void openEditorWithHighlight(final IASTFileLocation location) {
    94 		IPath path = new Path(location.getFileName());
    96 		final IPath path = new Path(location.getFileName());
    95 		IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
    97 		final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
    96 
    98 
    97 		if (file == null) {
    99 		if (file == null) {
    98 			return;
   100 			return;
    99 		}
   101 		}
   100 		
   102 		
   105 		} catch (PartInitException e) {
   107 		} catch (PartInitException e) {
   106 			e.printStackTrace();
   108 			e.printStackTrace();
   107 		}
   109 		}
   108 
   110 
   109 		if (editor != null && editor instanceof ITextEditor) {
   111 		if (editor != null && editor instanceof ITextEditor) {
   110 			ITextEditor textEditor = (ITextEditor)editor;
   112 			final ITextEditor textEditor = (ITextEditor)editor;
   111 			int nodeOffset = location.getNodeOffset();
   113 			int nodeOffset = location.getNodeOffset();
   112 			int nodeLength = location.getNodeLength();
   114 			int nodeLength = location.getNodeLength();
   113 			int offset;
   115 			int offset;
   114 			int length;
   116 			int length;
   115 			if (nodeLength == -1) {
   117 			if (nodeLength == -1) {
   129 		
   131 		
   130 			textEditor.selectAndReveal(offset, length);
   132 			textEditor.selectAndReveal(offset, length);
   131 		}
   133 		}
   132 	}
   134 	}
   133 	
   135 	
   134 	private boolean typeEqual(String param, IType type) {
   136 	private boolean typeEqual(final String param, final IType type) {
   135 
   137 
   136 		class TypeAttribute {
   138 		class TypeAttribute {
   137 			boolean isSigned = true;	// Symbian still default to signed
   139 			private transient boolean isSigned = true;	// Symbian still default to signed
   138 			boolean isConst = true;
   140 			private transient boolean isConst = true;
   139 			String typeWithoutModifier = "";	//$NON-NLS-1$
   141 			private transient String typeWithoutModifier = "";	//$NON-NLS-1$
   140 			
   142 			
   141 			TypeAttribute(String typeString) {
   143 			TypeAttribute(final String typeString) {
   142 				// In general we don't not have to care about too much, just trim out
   144 				// In general we don't not have to care about too much, just trim out
   143 				// signed/unsigned/const modifier and take note. We take the rest of them
   145 				// signed/unsigned/const modifier and take note. We take the rest of them
   144 				// and compare them after removing spaces
   146 				// and compare them after removing spaces
   145 				String[] typeStringSplit = typeString.split("[\t ]");	 //$NON-NLS-1$
   147 				String[] typeStringSplit = typeString.split("[\t ]");	 //$NON-NLS-1$
   146 				int index = 0;
   148 				int index = 0;
   157 				}
   159 				}
   158 				
   160 				
   159 				typeWithoutModifier = typeWithoutModifier.replaceAll("long int", "long"); //$NON-NLS-1$ //$NON-NLS-2$
   161 				typeWithoutModifier = typeWithoutModifier.replaceAll("long int", "long"); //$NON-NLS-1$ //$NON-NLS-2$
   160 			}
   162 			}
   161 			
   163 			
   162 			boolean isSameType(TypeAttribute attribute) {
   164 			private boolean isSameType(TypeAttribute attribute) {
   163 				if (isSigned == attribute.isSigned &&
   165 				if (isSigned == attribute.isSigned &&
   164 						isConst == attribute.isConst &&
   166 						isConst == attribute.isConst &&
   165 						typeWithoutModifier != null &&
   167 						typeWithoutModifier != null &&
   166 						attribute.typeWithoutModifier != null &&
   168 						attribute.typeWithoutModifier != null &&
   167 						typeWithoutModifier.equals(attribute.typeWithoutModifier)) {
   169 						typeWithoutModifier.equals(attribute.typeWithoutModifier)) {
   181 		ArrayList<String> signaturesArrayList = new ArrayList<String>();
   183 		ArrayList<String> signaturesArrayList = new ArrayList<String>();
   182 		IIndexBinding[] bindings = null;
   184 		IIndexBinding[] bindings = null;
   183 		boolean needMatchingArg = true;
   185 		boolean needMatchingArg = true;
   184 		
   186 		
   185 		// drop everything after )
   187 		// drop everything after )
   186 		if (Signature.indexOf(")") > 0 ) {	//$NON-NLS-1$
   188 		if (Signature.indexOf(')') > 0 ) {	//$NON-NLS-1$
   187 			Signature = Signature.substring(0, Signature.indexOf(")"));	//$NON-NLS-1$
   189 			Signature = Signature.substring(0, Signature.indexOf(')'));	//$NON-NLS-1$
   188 		}
   190 		}
   189 		
   191 		
   190 		String[] signatureSplit = Signature.split("[(),]"); //$NON-NLS-1$
   192 		String[] signatureSplit = Signature.split("[(),]"); //$NON-NLS-1$
   191 		for (String chunks: signatureSplit) {
   193 		for (String chunks: signatureSplit) {
   192 			chunks = chunks.trim();
   194 			chunks = chunks.trim();
   272 		if (binaryName != null)
   274 		if (binaryName != null)
   273 		{
   275 		{
   274 			IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
   276 			IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
   275 			
   277 			
   276 			for (IProject project: projects) {
   278 			for (IProject project: projects) {
   277 				if (CarbideBuilderPlugin.getBuildManager().isCarbideProject(project) == false) {
   279 				if (!CarbideBuilderPlugin.getBuildManager().isCarbideProject(project)) {
   278 					continue;
   280 					continue;
   279 				}
   281 				}
   280 				
   282 				
   281 				ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
   283 				ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
   282 				if (cpi == null)
   284 				if (cpi == null){
   283 					continue;
   285 					continue;
       
   286 				}
   284 				
   287 				
   285 				List<ICarbideBuildConfiguration> allConfig = cpi.getBuildConfigurations();
   288 				List<ICarbideBuildConfiguration> allConfig = cpi.getBuildConfigurations();
   286 				
   289 				
   287 				if (allConfig == null)
   290 				if (allConfig == null){
   288 					continue;
   291 					continue;
       
   292 				}
   289 				
   293 				
   290 				boolean isEligibleProject = false;
   294 				boolean isEligibleProject = false;
   291 				for (ICarbideBuildConfiguration config : allConfig) {
   295 				for (ICarbideBuildConfiguration config : allConfig) {
   292 					String projectExePath = EpocEngineHelper.getPathToMainExecutable(config);
   296 					String projectExePath = EpocEngineHelper.getPathToMainExecutable(config);
   293 					if (projectExePath != null && projectExePath.length() > 0) {
   297 					if (projectExePath != null && projectExePath.length() > 0) {
   294 						String projectFileName = new java.io.File(projectExePath).getName().toLowerCase();
   298 						String projectFileName = new java.io.File(projectExePath).getName().toLowerCase();
   295 						String binaryFileName = new java.io.File(binaryName).getName().toLowerCase();
   299 						String binaryFileName = new java.io.File(binaryName).getName().toLowerCase();
   296 
   300 
   297 						if (projectFileName.equals(binaryFileName) == true) {
   301 						if (projectFileName.equals(binaryFileName)) {
   298 							isEligibleProject = true;
   302 							isEligibleProject = true;
   299 						}
   303 						}
   300 					}
   304 					}
   301 				}
   305 				}
   302 				
   306 				
   342 		}
   346 		}
   343 		
   347 		
   344 		return locations.toArray(new IASTFileLocation[0]);
   348 		return locations.toArray(new IASTFileLocation[0]);
   345 	}
   349 	}
   346 	
   350 	
   347 	IASTFileLocation[] lookupLocationsFromIndex(String symbolName, IIndex index) {
   351 	private IASTFileLocation[] lookupLocationsFromIndex(String symbolName, IIndex index) {
   348 		IIndexBinding[] bindings = new IIndexBinding[0];
   352 		IIndexBinding[] bindings = new IIndexBinding[0];
   349 		ArrayList<IASTFileLocation> locations = new ArrayList<IASTFileLocation>();
   353 		ArrayList<IASTFileLocation> locations = new ArrayList<IASTFileLocation>();
   350 		
   354 		
   351 		// split by scoping operating ::, we will look for namespace and class later
   355 		// split by scoping operating ::, we will look for namespace and class later
   352 		String[] scopingOperatorSplit = symbolName.split ("::"); //$NON-NLS-1$
   356 		String[] scopingOperatorSplit = symbolName.split ("::"); //$NON-NLS-1$