Java cleanup - reduce use of global fields

This field does not need to be global, it is returned from the relevant
methods

Change-Id: Ic53eec4a699d6acc4410e71dde385e6a49ded745
Reviewed-on: https://gerrit.libreoffice.org/3567
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
This commit is contained in:
Noel Grandin 2013-04-23 09:08:33 +02:00 committed by Fridrich Strba
parent 68b9fb0aae
commit ada0298167
22 changed files with 46 additions and 91 deletions

View File

@ -32,13 +32,11 @@ import java.io.PrintWriter;
public class AccessibilityTools {
public static XAccessibleContext SearchedContext = null;
public static XAccessible SearchedAccessible = null;
private static boolean debug = false;
public AccessibilityTools() {
//done = false;
SearchedContext = null;
}
public static XAccessible getAccessibleObject(XInterface xObject) {
@ -93,35 +91,29 @@ public class AccessibilityTools {
public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc,
short role) {
SearchedContext = null;
SearchedAccessible = null;
getAccessibleObjectForRole_(xacc, role);
return SearchedContext;
return getAccessibleObjectForRole_(xacc, role);
}
public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc,
short role,
boolean ignoreShowing) {
SearchedContext = null;
SearchedAccessible = null;
if (ignoreShowing) {
getAccessibleObjectForRoleIgnoreShowing_(xacc, role);
return getAccessibleObjectForRoleIgnoreShowing_(xacc, role);
} else {
getAccessibleObjectForRole_(xacc, role);
return getAccessibleObjectForRole_(xacc, role);
}
return SearchedContext;
}
public static void getAccessibleObjectForRoleIgnoreShowing_(XAccessible xacc,
public static XAccessibleContext getAccessibleObjectForRoleIgnoreShowing_(XAccessible xacc,
short role) {
XAccessibleContext ac = xacc.getAccessibleContext();
if (ac.getAccessibleRole() == role) {
SearchedContext = ac;
SearchedAccessible = xacc;
return ac;
} else {
int k = ac.getAccessibleChildCount();
@ -131,28 +123,29 @@ public class AccessibilityTools {
for (int i = 0; i < k; i++) {
try {
getAccessibleObjectForRoleIgnoreShowing_(
XAccessibleContext ac2 = getAccessibleObjectForRoleIgnoreShowing_(
ac.getAccessibleChild(i), role);
if (SearchedContext != null) {
return;
if (ac2 != null) {
return ac2;
}
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
System.out.println("Couldn't get Child");
}
}
return null;
}
}
public static void getAccessibleObjectForRole_(XAccessible xacc,
public static XAccessibleContext getAccessibleObjectForRole_(XAccessible xacc,
short role) {
XAccessibleContext ac = xacc.getAccessibleContext();
boolean isShowing = ac.getAccessibleStateSet()
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
if ((ac.getAccessibleRole() == role) && isShowing) {
SearchedContext = ac;
SearchedAccessible = xacc;
return ac;
} else {
int k = ac.getAccessibleChildCount();
@ -162,15 +155,16 @@ public class AccessibilityTools {
for (int i = 0; i < k; i++) {
try {
getAccessibleObjectForRole_(ac.getAccessibleChild(i), role);
XAccessibleContext ac2 = getAccessibleObjectForRole_(ac.getAccessibleChild(i), role);
if (SearchedContext != null) {
return;
if (ac2 != null) {
return ac2;
}
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
System.out.println("Couldn't get Child");
}
}
return null;
}
}
@ -238,7 +232,7 @@ public class AccessibilityTools {
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
// hotfix for i91828:
// if role to serach is 0 then ignore the role.
// if role to search is 0 then ignore the role.
if ( (role == 0 || ac.getAccessibleRole() == role) &&
(ac.getAccessibleName().indexOf(name) > -1) &&
(utils.getImplName(ac).indexOf(implName) > -1) &&
@ -297,7 +291,7 @@ public class AccessibilityTools {
cellIndex= cellIndex+ (bytes[0]-65);
} else {
String sNumb = cellName.substring(n, cellName.length());
int iNumb = new Integer(0).valueOf(sNumb).intValue();
int iNumb = Integer.valueOf(sNumb).intValue();
cellIndex += (iNumb-1) * 256;
System.out.println("numb:" + (iNumb-1) * 256);
}

View File

@ -176,9 +176,9 @@ public class _XRangeSelection extends MultiMethodTest {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)tParam.getMSF(), xModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE );
XAccessibleContext ctx = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE );
XAccessibleComponent AccessibleSpreadsheet = UnoRuntime.queryInterface(XAccessibleComponent.class,AccessibilityTools.SearchedContext);
XAccessibleComponent AccessibleSpreadsheet = UnoRuntime.queryInterface(XAccessibleComponent.class,ctx);
log.println("Got " + util.utils.getImplName(AccessibleSpreadsheet));

View File

@ -167,9 +167,7 @@ public class ScAccessiblePreviewCell extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), xModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL, true);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL, true);
log.println("ImplementationName " + utils.getImplName(oObj));

View File

@ -172,9 +172,7 @@ public class ScAccessiblePreviewTable extends TestCase {
at.printAccessibleTree(log,xRoot, Param.getBool(PropertyName.DEBUG_IS_ACTIVE));
at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
log.println("ImplementationName " + utils.getImplName(oObj));

View File

@ -112,9 +112,7 @@ public class ScAccessibleSpreadsheet extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), xModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE );
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE );
log.println("ImplementationName " + utils.getImplName(oObj));

View File

@ -54,15 +54,12 @@ public class AccessibleDocumentView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
if (oObj == null) {
log.println("DocumentView hasn't the role 'Document'");
log.println("trying the role 'Shape'");
at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE);
}
log.println("ImplementationName " + utils.getImplName(oObj));

View File

@ -105,9 +105,7 @@ public class AccessibleDrawDocumentView extends TestCase {
XAccessible xRoot = at.getAccessibleObject(xWindow);
//com.sun.star.accessibility.AccessibleRole
at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
log.println("ImplementationName "+utils.getImplName(oObj));

View File

@ -70,9 +70,7 @@ public class AccessibleOutlineView extends TestCase {
(XMultiServiceFactory)Param.getMSF(),aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
log.println("ImplementationName "+utils.getImplName(oObj));

View File

@ -79,9 +79,7 @@ public class AccessibleSlideView extends TestCase {
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
System.out.println("ImplementationName "+utils.getImplName(oObj));

View File

@ -121,9 +121,7 @@ public class SwAccessibleDocumentPageView extends TestCase {
XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT );
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT );
log.println("ImplementationName " + utils.getImplName(oObj));

View File

@ -102,9 +102,7 @@ public class SwAccessibleDocumentView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -118,9 +118,7 @@ public class SwAccessibleEndnoteView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.END_NOTE);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.END_NOTE);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -132,9 +132,7 @@ public class SwAccessibleFooterView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTER);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTER);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -119,9 +119,7 @@ public class SwAccessibleFootnoteView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTNOTE);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTNOTE);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -122,9 +122,7 @@ public class SwAccessibleHeaderView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.HEADER);
oObj = AccessibilityTools.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.HEADER);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -74,9 +74,7 @@ public class SwAccessibleParagraphView extends TestCase {
XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH);
oObj = at.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH);
log.println("ImplementationName " + utils.getImplName(oObj));

View File

@ -30,6 +30,7 @@ import util.utils;
import com.sun.star.accessibility.AccessibleRole;
import com.sun.star.accessibility.XAccessible;
import com.sun.star.accessibility.XAccessibleContext;
import com.sun.star.accessibility.XAccessibleSelection;
import com.sun.star.awt.XWindow;
import com.sun.star.frame.XModel;
@ -37,7 +38,6 @@ import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextTable;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
/**
@ -65,7 +65,7 @@ public class SwAccessibleTableCellView extends TestCase {
*/
protected TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
XInterface oObj = null;
XAccessibleContext oObj = null;
XTextTable oTable = null;
SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
@ -94,9 +94,7 @@ public class SwAccessibleTableCellView extends TestCase {
XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL);
oObj = at.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL);
log.println("ImplementationName " + utils.getImplName(oObj));
@ -105,7 +103,7 @@ public class SwAccessibleTableCellView extends TestCase {
final XAccessibleSelection accSel = UnoRuntime.queryInterface(
XAccessibleSelection.class,
at.SearchedContext.getAccessibleParent());
oObj.getAccessibleParent());
tEnv.addObjRelation("EventProducer",
new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {

View File

@ -95,9 +95,7 @@ public class SwAccessibleTableView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
oObj = at.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -73,9 +73,7 @@ public class SwAccessibleTextEmbeddedObject extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.EMBEDDED_OBJECT);
oObj = at.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.EMBEDDED_OBJECT);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -106,9 +106,7 @@ public class SwAccessibleTextFrameView extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);
oObj = at.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -95,9 +95,7 @@ public class SwAccessibleTextGraphicObject extends TestCase {
XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.GRAPHIC);
oObj = at.SearchedContext;
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.GRAPHIC);
log.println("ImplementationName " + utils.getImplName(oObj));
at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

View File

@ -174,11 +174,11 @@ public class AccessibleRelationSet {
XWindow xWindow = at.getCurrentWindow(factory, aModel);
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
XAccessibleContext ctx = at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
para1 = at.SearchedContext.getAccessibleChild(0);
para2 = at.SearchedContext.getAccessibleChild(1);
para3 = at.SearchedContext.getAccessibleChild(2);
para1 = ctx.getAccessibleChild(0);
para2 = ctx.getAccessibleChild(1);
para3 = ctx.getAccessibleChild(2);
}
@After public void after() {