Skip to content

Commit

Permalink
567070: Optimize progress monitor calculation
Browse files Browse the repository at this point in the history
Better handle OQL when parsing command line

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=567070

Change-Id: I1f3ef5533de829146f6ded6546536fe70e63d584
  • Loading branch information
ajohnson1 committed Sep 20, 2020
1 parent 2650deb commit bdedfe8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2010 SAP AG and others.
* Copyright (c) 2008, 2020 SAP AG 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
Expand All @@ -25,7 +25,14 @@
public final class ArgumentParser
{
private static final Pattern ADDRESS_PATTERN = Pattern.compile("^0x\\p{XDigit}+$"); //$NON-NLS-1$

/** matches definition of INTEGER_LITERAL and FLOATING_POINT_LITERAL in OQLParser.jj */
private static final Pattern OQL_NUMBER_PATTERN = Pattern.compile("^[+-]?((\\p{Digit}+[lL]?)" //$NON-NLS-1$
+ "|(\\p{Digit}+\\.\\p{Digit}*([eE][+-]?\\p{Digit}+)?[fFdD]?)" //$NON-NLS-1$
+ "|(\\.\\p{Digit}*([eE][+-]?\\p{Digit}+)?[fFdD]?)" //$NON-NLS-1$
+ "|(\\p{Digit}+([eE][+-]?\\p{Digit}+)[fFdD]?)" //$NON-NLS-1$
+ "|(\\p{Digit}+([eE][+-]?\\p{Digit}+)?[fFdD])" //$NON-NLS-1$
+ ")$"); //$NON-NLS-1$

public static HeapObjectParamArgument consumeHeapObjects(ISnapshot snapshot, String line) throws SnapshotException
{
String[] args = CommandLine.tokenize(line);
Expand Down Expand Up @@ -124,9 +131,12 @@ else if ("select".equalsIgnoreCase(arg)) //$NON-NLS-1$
pos.setIndex(pos.getIndex() + 1);
break;
}
else if (arg.charAt(0) == '-')
else if (arg.charAt(0) == '-' && arg.length() > 1)
{
break;
// Already excluded OQL '-' operator
// OQL numbers look a bit like another flag argument
if (!OQL_NUMBER_PATTERN.matcher(arg).matches())
break;
}
query.append(" ").append(arg); //$NON-NLS-1$
pos.setIndex(pos.getIndex() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,27 @@ public void testFindStrings2() throws SnapshotException
assertThat("Total work should match", listener.work, equalTo(1000000));
}

/**
* Test find Strings and also parsing of OQL with leading minus.
* @throws SnapshotException
*/
@Test
public void testFindStrings3() throws SnapshotException
{
// 3 object arguments
SnapshotQuery query = SnapshotQuery.parse("find_strings select * from java.lang.String s" +
" where s.@objectId != -1 - -123 + -123L + -1.0 + 1. + -.1 + -1.0f + -1.0F + -1.0d + -1.0E12d + -1.0e-1f + -0.1E-2d + -1e5 ;"
+ " java.lang.String select * from java.lang.String -pattern p0", snapshot);
CheckedWorkProgressListener listener = new CheckedWorkProgressListener(collector);
IResultTree t = (IResultTree)query.execute(listener);
assertTrue(t != null);
assertThat(t.getElements().size(), equalTo(28 * 3));
assertThat("Total work should match", listener.work, equalTo(listener.total));
assertThat("Should be some work done", listener.work, greaterThan(0));
// As we have an OQL query, the total work is unknown and so set to this
assertThat("Total work should match", listener.work, equalTo(1000000));
}

/**
* Test parsing of class pattern argument
* @throws SnapshotException
Expand Down

0 comments on commit bdedfe8

Please sign in to comment.