📄 sourceupdatemethodresolver.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: SourceUpdateMethodResolver.java,v 1.7 2004/01/14 22:28:38 per_nyfelt Exp $package org.ozoneDB.tools.OPP.srcgen.resolve;import org.ozoneDB.tools.OPP.message.MessageWriter;import org.ozoneDB.tools.OPP.OPPHelper;import org.ozoneDB.tools.OPP.OPP;import org.ozoneDB.tools.OPP.srcgen.MethodResolver;import org.ozoneDB.tools.OPP.srcgen.ResolverException;import org.ozoneDB.tools.OPP.srcgen.ClassQuery;import org.ozoneDB.tools.OPP.srcgen.streamfactory.InputStreamFactory;import org.ozoneDB.OzoneRemote;import org.ozoneDB.core.Lock;import java.io.*;import java.util.regex.Pattern;/** * Helper class that allows to parse the Java source code of interface files * to find update methods * * @author Joakim Ohlrogge * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.7 $Date: 2004/01/14 22:28:38 $ */public class SourceUpdateMethodResolver implements MethodResolver { private MessageWriter genListener; private InputStreamFactory streamFactory; private ClassQuery classQuery; public SourceUpdateMethodResolver(InputStreamFactory _streamFactory, MessageWriter _genListener, ClassQuery _classQuery) { streamFactory = _streamFactory; genListener = _genListener; classQuery = _classQuery; } /** * Recursivly search all remote interfaces (implement OzoneRemote) for * update methods. */ private void searchUpdateMethods(String cl, MethodResolver.UpdateMethodBag updateMethodsIf) throws IOException, ClassNotFoundException { String dbRemote = OzoneRemote.class.getName(); java.util.Vector stack = new java.util.Vector(); stack.addElement(cl); while (!stack.isEmpty()) { String dbInterface = (String) stack.lastElement(); stack.removeElementAt(stack.size() - 1); genListener.debug("checking: " + dbInterface); if (!dbRemote.equals(dbInterface) && classQuery.isAssignable(dbRemote, dbInterface)) { String[] ifs = classQuery.getInterfaces(dbInterface); for (int i = 0; i < ifs.length; i++) { stack.addElement(ifs[i]); } //if (classQuery.isInterface(dbInterface)) { searchUpdateMethods2(dbInterface, updateMethodsIf); } //} } } /** * Search all methods that are marked in the resolver code of the remote * Java interface. */ private void searchUpdateMethods2(String dbInterface, MethodResolver.UpdateMethodBag updateMethodsIf) throws IOException { // method name regexp Pattern re = OPPHelper.newRE(OPP.UPDATE_SIGN, true); // method comment regexp Pattern mre = OPPHelper.newRE(OPP.METHOD_PATTERN, false); // javadoc regexp Pattern jre = OPPHelper.newRE(OPP.JAVADOC_PATTERN, false); // javadoc comemnt start Pattern docstart = OPPHelper.newRE("/\\*\\*", false); genListener.debug("reading: " + dbInterface); LineNumberReader reader = new LineNumberReader(new InputStreamReader(streamFactory.newInstance(dbInterface))); try { String line = reader.readLine(); // to support multi line method signatures // the regexp for update must match on the method signature line // or one the followings boolean isJavadocUpdate = false; String lastMatchedMethod = null; while (line != null) { // System.out.println (line); boolean isUpdate = OPPHelper.reSearch(re, line, 0, 0) != null; // before each method stands his appropriate javadoc comment String match = OPPHelper.reSearch(docstart, line, 0, 0); if (match != null) { lastMatchedMethod = null; isJavadocUpdate = false; } match = OPPHelper.reSearch(mre, line, 0, 1); if (match != null) { lastMatchedMethod = match; } match = OPPHelper.reSearch(jre, line, 0, 0); if (match != null) { isJavadocUpdate = true; } if (lastMatchedMethod != null && (isUpdate || isJavadocUpdate)) { String methodName = lastMatchedMethod; genListener.debug("method: " + methodName + " matched per update regexp in interface "); updateMethodsIf.addMethod(methodName, Lock.LEVEL_WRITE); lastMatchedMethod = null; isJavadocUpdate = false; } else if (lastMatchedMethod == null && isUpdate) { genListener.warning(OPPHelper.classFileBasename(dbInterface) + ".java", reader.getLineNumber(), "Unable to determine the method name for the " + " found update definition in line " + reader.getLineNumber() + "."); } else { /*if (lastMatchedMethod != null && !isUpdate && !isJavadocUpdate) { String methodName = lastMatchedMethod; if (updateMethodsIf.contains(methodName)) { genListener.warning(OPPHelper.classFileBasename(dbInterface) + ".java", reader.getLineNumber(), "All '" + methodName + "' methods will be marked as update methods."); } }*/ } line = reader.readLine(); } } finally { reader.close(); } } public void resolveMethods(String className, MethodResolver.UpdateMethodBag result) throws ResolverException { try { searchUpdateMethods(className, result); } catch (IOException e) { throw new ResolverException("Could not resolve update methods (" + className + "). " + e.getMessage(), e); } catch (ClassNotFoundException e) { throw new ResolverException("Could not resolve update methods (" + className + "). " + e.getMessage(), e); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -