Commit 59c49db0 authored by Elemer Lelik's avatar Elemer Lelik
Browse files

Last sync 20160408

parent fcfa4a7b
No preview for this file type
###############################################################################
# Copyright (c) 2000-2016 Ericsson Telecom AB
# Copyright (c) 2000-2015 Ericsson Telecom AB
# 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
......
......@@ -25,7 +25,7 @@ public final class Activator extends AbstractUIPlugin {
public static final String PLUGIN_ID = ProductConstants.PRODUCT_ID_COMMON;
/** The shared instance */
private static Activator plugin = null;
private static Activator plugin;
private WorkspaceJob usageStatSenderJob;
public Activator() {
......
......@@ -81,7 +81,7 @@ public final class FormatLog extends AbstractHandler implements IWorkbenchWindow
final File source = new File(file.getLocationURI());
final long fileSize = source.length();
IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
final IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
internalMonitor.beginTask("formatting " + file.getName(), (int) (fileSize / LogFormatter.TICK_SIZE));
FileChannel inChannel = null;
......@@ -108,12 +108,12 @@ public final class FormatLog extends AbstractHandler implements IWorkbenchWindow
return Status.OK_STATUS;
}
private FileChannel openOutputFile(URI targetPath) throws FileNotFoundException {
private FileChannel openOutputFile(final URI targetPath) throws FileNotFoundException {
FileOutputStream outfile = null;
try {
outfile = new FileOutputStream(new File(targetPath), false);
} catch (FileNotFoundException e) {
String message = "Error while opening " + targetPath + " for writing";
final String message = "Error while opening " + targetPath + " for writing";
ErrorReporter.logExceptionStackTrace(message, e);
throw new FileNotFoundException(message);
}
......@@ -135,28 +135,28 @@ public final class FormatLog extends AbstractHandler implements IWorkbenchWindow
/** This is needed because AbstractHandler does not deal with selection, and
* selectionChanged is not called.
*/
IWorkbenchPage iwPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ISelection selection = iwPage.getSelection();
final IWorkbenchPage iwPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final ISelection selection = iwPage.getSelection();
files = SelectionUtils.getAccessibleFilesFromSelection(selection);
doFormat();
return null;
}
public void formatFiles(List<IFile> files) {
for (IFile file : files) {
public void formatFiles(final List<IFile> files) {
for (final IFile file : files) {
final URI targetPath = getTargetPath(file.getLocationURI());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IFile[] targetFiles = root.findFilesForLocationURI(targetPath);
internalFormatter(null, file, targetPath, targetFiles);
}
}
private static URI getTargetPath(URI original) {
String originalFileName = URIUtil.lastSegment(URIUtil.removeFileExtension(original));
URI path = TitanURIUtil.removeLastSegment(original);
private static URI getTargetPath(final URI original) {
final String originalFileName = URIUtil.lastSegment(URIUtil.removeFileExtension(original));
final URI path = TitanURIUtil.removeLastSegment(original);
String newFilename = originalFileName + "_formatted.log";
final String newFilename = originalFileName + "_formatted.log";
return URIUtil.append(path, newFilename);
}
......@@ -164,10 +164,10 @@ public final class FormatLog extends AbstractHandler implements IWorkbenchWindow
for (final IFile file : files) {
final URI targetPath = getTargetPath(file.getLocationURI());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IFile[] targetFiles = root.findFilesForLocationURI(targetPath);
WorkspaceJob saveJob = new WorkspaceJob("Formatting log file") {
final WorkspaceJob saveJob = new WorkspaceJob("Formatting log file") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) {
return internalFormatter(monitor, file, targetPath, targetFiles);
......@@ -182,11 +182,11 @@ public final class FormatLog extends AbstractHandler implements IWorkbenchWindow
}
}
private ISchedulingRule createRuleFromResources(IFile file, IFile[] targetFiles) {
IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule rule1 = ruleFactory.createRule(file);
private ISchedulingRule createRuleFromResources(final IFile file, final IFile[] targetFiles) {
final IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
final ISchedulingRule rule1 = ruleFactory.createRule(file);
ISchedulingRule combinedRule = MultiRule.combine(rule1, null);
for (IFile targetFile : targetFiles) {
for (final IFile targetFile : targetFiles) {
combinedRule = MultiRule.combine(ruleFactory.createRule(targetFile), combinedRule);
}
return combinedRule;
......
......@@ -169,7 +169,7 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
handleFileExists(originalFile);
}
private IPath createMergedFileName(IFile originalFile) {
private IPath createMergedFileName(final IFile originalFile) {
// original loc
IPath temp = originalFile.getLocation();
// original ext
......@@ -205,12 +205,12 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
});
}
private void askUserToCreateOrOverwrite(IPreferenceStore prefStore, IFile originalFile) {
private void askUserToCreateOrOverwrite(final IPreferenceStore prefStore, final IFile originalFile) {
final String[] buttonLabels = new String[] {
"Create a new file",
"Overwrite" };
MessageDialogWithToggle msgDialog = new MessageDialogWithToggle(
final MessageDialogWithToggle msgDialog = new MessageDialogWithToggle(
null,
"File already exists",
null,
......@@ -268,15 +268,16 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
* the original log file
*/
private File createNewFileWithUniqueName(final IFile originalFile) {
final String outputFileNamePrefix;
String temp;
if (originalFile.getName().endsWith(LOG_FILE_EXTENSION)) {
outputFileNamePrefix = originalFile.getName().substring(0, originalFile.getName().length() - LOG_FILE_EXTENSION.length())
temp = originalFile.getName().substring(0, originalFile.getName().length() - LOG_FILE_EXTENSION.length())
+ MERGED_FILENAME_SUFFIX;
} else {
outputFileNamePrefix = originalFile.getName() + MERGED_FILENAME_SUFFIX;
temp = originalFile.getName() + MERGED_FILENAME_SUFFIX;
}
File[] files = outputFile.getParentFile().listFiles(new FilenameFilter() {
final String outputFileNamePrefix = temp;
final File[] files = outputFile.getParentFile().listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.startsWith(outputFileNamePrefix);
......@@ -290,7 +291,7 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
suffix = suffix.substring(0, suffix.length() - LOG_FILE_EXTENSION.length());
try {
int number = Integer.parseInt(suffix);
final int number = Integer.parseInt(suffix);
if (number > max) {
max = number;
}
......@@ -305,7 +306,7 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
IWorkbenchPage iwPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IWorkbenchPage iwPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
selection = iwPage.getSelection();
final List<IFile> filesToMerge = SelectionUtils.getAccessibleFilesFromSelection(selection);
doMerge(filesToMerge, false);
......@@ -320,7 +321,7 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
* @param sync true if the function should wait for the merge to finish,
* false if the function should just start the parallel thread.
* */
private void doMerge(final List<IFile> files, boolean sync) {
private void doMerge(final List<IFile> files, final boolean sync) {
if (files.size() < 2) {
return;
}
......@@ -368,10 +369,10 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
}
}
private ISchedulingRule createSchedulingRule(List<IFile> files) {
private ISchedulingRule createSchedulingRule(final List<IFile> files) {
final IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule combinedRule = null;
for (IFile file : files) {
for (final IFile file : files) {
combinedRule = MultiRule.combine(ruleFactory.createRule(file), combinedRule);
}
return combinedRule;
......@@ -394,7 +395,7 @@ public final class MergeLog extends AbstractHandler implements IWorkbenchWindowA
final IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule combinedRule = null;
for (IFile file : outputFiles) {
for (final IFile file : outputFiles) {
combinedRule = MultiRule.combine(ruleFactory.createRule(file), combinedRule);
}
......
......@@ -206,8 +206,8 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
dialog.setMessage("Select a variable to constrain your search.");
final List<EnvironmentVariable> variables = new ArrayList<EnvironmentVariable>(envVariables.size());
for (Iterator<?> i = envVariables.keySet().iterator(); i.hasNext();) {
EnvironmentVariable variable = new EnvironmentVariable();
for (final Iterator<?> i = envVariables.keySet().iterator(); i.hasNext();) {
final EnvironmentVariable variable = new EnvironmentVariable();
variable.name = (String) i.next();
variable.value = (String) envVariables.get(variable.name);
......@@ -283,8 +283,7 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
resolvedPathLabelText.setVisible(false);
return;
}
//TODO: To change the next lines for this one:
//final URI uri1 = TITANPathUtilities.getURI(target, rootPath);
final IPath path = new Path(target);
final IPath resolvedPath = TITANPathUtilities.resolvePath(target, rootPath);
final URI uri = URIUtil.toURI(resolvedPath);
......
......@@ -16,7 +16,7 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
*
* @author Kristof Szabados
* */
public class ImageCache {
public final class ImageCache {
private static final String ICONS_SUBDIR = "icons/";
private ImageCache() {
......
......@@ -51,7 +51,7 @@ public class LogFormatter {
private int indentationLevel;
private boolean insideString;
public LogFormatter(IProgressMonitor internalMonitor, FileChannel inChannel, FileChannel outChannel) {
public LogFormatter(final IProgressMonitor internalMonitor, final FileChannel inChannel, final FileChannel outChannel) {
this.internalMonitor = internalMonitor;
this.inChannel = inChannel;
this.outChannel = outChannel;
......@@ -63,8 +63,8 @@ public class LogFormatter {
insideString = false;
boolean cancelled = false;
lastToken = LastTokenTypes.OTHER;
ByteBuffer inBuf = ByteBuffer.allocateDirect(IN_BUFFER_SIZE);
ByteBuffer outBuffer = ByteBuffer.allocate(OUT_BUFFER_SIZE);
final ByteBuffer inBuf = ByteBuffer.allocateDirect(IN_BUFFER_SIZE);
final ByteBuffer outBuffer = ByteBuffer.allocate(OUT_BUFFER_SIZE);
inBuf.clear();
while (!cancelled && inChannel.read(inBuf) != -1) {
if (internalMonitor.isCanceled()) {
......@@ -89,7 +89,7 @@ public class LogFormatter {
}
}
private void processBuffer(ByteBuffer inBuf, ByteBuffer outBuffer) throws IOException {
private void processBuffer(final ByteBuffer inBuf, final ByteBuffer outBuffer) throws IOException {
byte temp;
while (inBuf.hasRemaining()) {
temp = inBuf.get();
......@@ -107,7 +107,7 @@ public class LogFormatter {
}
}
private void outsideString(ByteBuffer inBuf, ByteBuffer outBuffer, byte temp) {
private void outsideString(final ByteBuffer inBuf, final ByteBuffer outBuffer, final byte temp) {
switch (temp) {
case '{':
if (indentationLevel > 0) {
......@@ -170,7 +170,7 @@ public class LogFormatter {
break;
case '\r':
if (inBuf.remaining() > 0) {
byte temp2 = inBuf.get();
final byte temp2 = inBuf.get();
if ('\n' == temp2) {
if (indentationLevel > 0) {
if (LastTokenTypes.OTHER.equals(lastToken)) {
......@@ -208,7 +208,7 @@ public class LogFormatter {
}
}
private void processInsideString(ByteBuffer inBuf, ByteBuffer outBuffer, byte temp) {
private void processInsideString(final ByteBuffer inBuf, final ByteBuffer outBuffer, final byte temp) {
outBuffer.put(temp);
switch (temp) {
case '\"':
......@@ -216,7 +216,7 @@ public class LogFormatter {
break;
case '\\':
if (inBuf.hasRemaining()) {
byte temp2 = inBuf.get();
final byte temp2 = inBuf.get();
outBuffer.put(temp2);
}
break;
......
......@@ -43,7 +43,7 @@ public class LogMerger {
* @param monitor the progress monitor
* @return {@code true} if the operation completed successfully, {@code false} otherwise
*/
public boolean merge(List<IFile> files, File outputFile, IProgressMonitor monitor) {
public boolean merge(final List<IFile> files, final File outputFile, final IProgressMonitor monitor) {
isErroneous = false;
FileUtils.deleteQuietly(outputFile);
......@@ -72,11 +72,11 @@ public class LogMerger {
boolean dataProcessed = true;
long nofProcessedBytes = 0;
while (dataProcessed && !internalMonitor.isCanceled()) {
MergeAble earliestMergeable = getEarliestMergeAble(mergeAbles);
final MergeAble earliestMergeable = getEarliestMergeAble(mergeAbles);
dataProcessed = false;
if (earliestMergeable != null) {
String text = appendRecord(writer, earliestMergeable);
final String text = appendRecord(writer, earliestMergeable);
nofProcessedBytes += text.length();
if (nofProcessedBytes > tickSize) {
......@@ -100,14 +100,14 @@ public class LogMerger {
return !isErroneous;
}
private String appendRecord(PrintWriter writer, MergeAble earliestMergeable) {
LogRecord record = earliestMergeable.getActualRecord();
private String appendRecord(final PrintWriter writer, final MergeAble earliestMergeable) {
final LogRecord record = earliestMergeable.getActualRecord();
writer.print(record.getTimestamp());
if (earliestMergeable.getComponentID() != null) {
writer.print(' ');
writer.print(earliestMergeable.getComponentID());
}
String text = record.getText();
final String text = record.getText();
writer.print(text);
if (text.charAt(text.length() - 1) != '\n') {
// If it does not end on a new line, than extend it to do so.
......@@ -116,12 +116,12 @@ public class LogMerger {
return text;
}
private List<MergeAble> collectMergeAbles(List<IFile> files, File outputFile) {
private List<MergeAble> collectMergeAbles(final List<IFile> files, final File outputFile) {
final List<MergeAble> mergeAbles = new ArrayList<MergeAble>(files.size());
TimestampFormat commonFormat = null;
// try to open each file, and check if their timestamp format is the same.
final IPath outputPath = new Path(outputFile.getAbsolutePath());
for (IFile file : files) {
for (final IFile file : files) {
if (outputPath.equals(file.getLocation())) {
continue;
}
......@@ -135,7 +135,7 @@ public class LogMerger {
isErroneous = true;
continue;
}
MergeAble mergeAble = new MergeAble(file, reader, true);
final MergeAble mergeAble = new MergeAble(file, reader, true);
if (mergeAble.hasNext()) {
if (commonFormat == null) {
commonFormat = mergeAble.getTimestampFormat();
......@@ -174,7 +174,7 @@ public class LogMerger {
String smallestTimestamp = null;
MergeAble smallestMergeable = null;
for (MergeAble mergeAble : mergeAbles) {
for (final MergeAble mergeAble : mergeAbles) {
if (mergeAble.hasNext()) {
if (smallestTimestamp == null) {
smallestTimestamp = mergeAble.getActualRecord().getTimestamp();
......
......@@ -80,7 +80,7 @@ final class MergeAble implements Closeable {
private String getComponentID(final String fileName) {
int idStart = 0;
int idEnd = fileName.length() - 1;
int dashLoc = fileName.lastIndexOf('-');
final int dashLoc = fileName.lastIndexOf('-');
if (dashLoc == -1) {
int temp = fileName.lastIndexOf('.');
if (temp != -1) {
......@@ -92,7 +92,7 @@ final class MergeAble implements Closeable {
}
} else {
idStart = dashLoc + 1;
int temp = fileName.indexOf('.', dashLoc);
final int temp = fileName.indexOf('.', dashLoc);
if (temp != -1) {
idEnd = temp;
}
......@@ -148,7 +148,7 @@ final class MergeAble implements Closeable {
processLines(m, timestamp);
}
private void processLines(Matcher m, String timestamp) {
private void processLines(final Matcher m, final String timestamp) {
String text = null;
boolean found = false;
......@@ -205,7 +205,7 @@ final class MergeAble implements Closeable {
return componentID;
}
public void setComponentID(String componentID) {
public void setComponentID(final String componentID) {
this.componentID = componentID;
}
......
......@@ -119,8 +119,8 @@ public final class ErrorReporter {
* @return the string form of the stack trace.
* */
public static String stackTraceToString(final StackTraceElement[] elements) {
StringBuilder builder = new StringBuilder();
for (StackTraceElement element : elements) {
final StringBuilder builder = new StringBuilder();
for (final StackTraceElement element : elements) {
builder.append(element).append("\n");
}
return builder.toString();
......@@ -139,7 +139,7 @@ public final class ErrorReporter {
* Can be used when the default logger of the platform is not available. (e.g. when unit testing)
* @param newLog The logger
*/
public static void setLog(ILog newLog) {
public static void setLog(final ILog newLog) {
log = newLog;
}
......
......@@ -7,25 +7,13 @@
******************************************************************************/
package org.eclipse.titan.common.parsers;
import org.antlr.v4.runtime.Token;
public class CommonHiddenStreamToken {
private String mText;
private int mTokenType = Token.INVALID_TYPE;
private CommonHiddenStreamToken mHiddenBefore;
private CommonHiddenStreamToken mHiddenAfter;
/**
* @param aTokenType token type according to CfgLexer.java (for example: CfgLexer.WS)
* @param aText
*/
public CommonHiddenStreamToken(int aTokenType, String aText) {
mTokenType = aTokenType;
mText = aText;
}
private CommonHiddenStreamToken mHiddenBefore;
private CommonHiddenStreamToken mHiddenAfter;
public CommonHiddenStreamToken(String aText) {
public CommonHiddenStreamToken(final String aText) {
mText = aText;
}
......
......@@ -256,7 +256,7 @@ public class Interval {
return -1;
}
private int findPairInSubIntervals(int offset) {
private int findPairInSubIntervals(final int offset) {
int lowLimit = 0;
int highLimit = subIntervals.size();
int middle;
......
......@@ -22,23 +22,23 @@ public class LocationAST {
private CommonHiddenStreamToken mHiddenAfter;
private CommonHiddenStreamToken mHiddenBefore;
public LocationAST(String aText) {
public LocationAST(final String aText) {
mRule = new ParserRuleContext();
setText( aText );
}
public LocationAST(ParserRuleContext aRule) {
public LocationAST(final ParserRuleContext aRule) {
mRule = aRule;
}
public LocationAST(Token aToken) {
public LocationAST(final Token aToken) {
mRule = new ParserRuleContext();
mRule.addChild(aToken);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
sb.append("{ ");
sb.append(mText+", ");
if ( mRule != null ) {
......@@ -60,11 +60,11 @@ public class LocationAST {
if ( mText != null ) {
return mText;
}
String text = mRule != null ? mRule.getText() : null;
return text;
return mRule != null ? mRule.getText() : null;
}
public void setText(String aText) {
public void setText(final String aText) {
mText = aText;
}
......@@ -73,7 +73,8 @@ public class LocationAST {
}
public LocationAST getParent() {
ParserRuleContext parentRule = mRule != null ? mRule.getParent() : null;
final ParserRuleContext parentRule = mRule != null ? mRule.getParent() : null;
return new LocationAST( parentRule );
}
......@@ -93,11 +94,11 @@ public class LocationAST {
}
final ParserRuleContext firstRule = (ParserRuleContext) firstParseTree;
LocationAST la = new LocationAST( firstRule );
return la;
return new LocationAST( firstRule );
}
public void setFirstChild(LocationAST aNode) {
public void setFirstChild(final LocationAST aNode) {
if ( mRule == null ) {
return;
}
......@@ -105,7 +106,8 @@ public class LocationAST {
if ( mRule.children == null ) {
mRule.children = new ArrayList<ParseTree>();
}
List<ParseTree> children = mRule.children;
final List<ParseTree> children = mRule.children;
children.set(0, aNode.getRule());
}
......@@ -128,23 +130,23 @@ public class LocationAST {
}
final ParserRuleContext nextRule = (ParserRuleContext) nextParseTree;
LocationAST la = new LocationAST( nextRule );
return la;
return new LocationAST( nextRule );
}
public void setNextSibling( LocationAST aNode ) {
public void setNextSibling(final LocationAST aNode ) {
final int childIndex = getChildIndex();
if ( childIndex < 0 ) {
// mRule or mRule.getParent() or mRule.getParent().children is null
return;
}
List<ParseTree> children = mRule.getParent().children;
final List<ParseTree> children = mRule.getParent().children;
children.set(childIndex + 1, aNode.getRule());
}
public void addChild(LocationAST aNode) {
public void addChild(final LocationAST aNode) {
if ( mRule == null ) {
return;