Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java41
1 files changed, 18 insertions, 23 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
index 656f115c8b0..59635208853 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,11 +10,9 @@
* Institute for Software - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.dom.rewrite.util;
import java.io.IOException;
-import java.io.InputStream;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -39,41 +37,38 @@ public class FileHelper {
IPath implPath = new Path(node.getContainingFilename());
return ResourceLookup.selectFileForLocation(implPath, null);
}
-
- public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){
-
+
+ public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2) {
+
boolean isEquals = true;
-
+
isEquals &= loc1.getFileName().equals(loc2.getFileName());
isEquals &= loc1.getNodeOffset() >= loc2.getNodeOffset();
- isEquals &= loc1.getNodeOffset()+loc1.getNodeLength() <= loc2.getNodeOffset() + loc2.getNodeLength();
-
+ isEquals &= loc1.getNodeOffset() + loc1.getNodeLength() <= loc2.getNodeOffset()
+ + loc2.getNodeLength();
+
return isEquals;
}
public static String determineLineDelimiter(IFile file) {
- StringBuilder fileContent = new StringBuilder();
+ String fileContent = ""; //$NON-NLS-1$
+
try {
- InputStream fis = file.getContents();
- byte[] buffer = new byte[1024];
- int read;
- while ((read = fis.read(buffer)) >= 0)
- fileContent.append(new String(buffer, 0, read));
+ fileContent = FileContentHelper.getContent(file, 0);
} catch (CoreException e) {
} catch (IOException e) {
- } catch (NullPointerException e){
}
-
+
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject();
IScopeContext[] scopeContext;
- if(project != null){
- scopeContext = new IScopeContext[] { new ProjectScope(project)};
- }
- else{
- scopeContext = new IScopeContext[] { new InstanceScope()};
+ if (project != null) {
+ scopeContext = new IScopeContext[] { new ProjectScope(project) };
+ } else {
+ scopeContext = new IScopeContext[] { new InstanceScope() };
}
String platformDefaultLineDelimiter = System.getProperty("line.separator", DEFAULT_LINE_DELIMITTER); //$NON-NLS-1$
- String defaultLineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefaultLineDelimiter, scopeContext);
+ String defaultLineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME,
+ Platform.PREF_LINE_SEPARATOR, platformDefaultLineDelimiter, scopeContext);
return TextUtilities.determineLineDelimiter(fileContent.toString(), defaultLineDelimiter);
}
}

Back to the top