com.sun.tools.xjc.addon.sync.SynchronizedMethodAddOn Maven / Gradle / Ivy
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.tools.xjc.addon.sync;
import java.io.IOException;
import com.sun.codemodel.JMethod;
import com.sun.tools.xjc.BadCommandLineException;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.Plugin;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.Outline;
import org.xml.sax.ErrorHandler;
/**
* Generates synchronized methods.
*
* @author
* Kohsuke Kawaguchi ([email protected])
*/
public class SynchronizedMethodAddOn extends Plugin {
public String getOptionName() {
return "Xsync-methods";
}
public String getUsage() {
return " -Xsync-methods : generate accessor methods with the 'synchronized' keyword";
}
public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException {
return 0; // no option recognized
}
public boolean run( Outline model, Options opt, ErrorHandler errorHandler ) {
for( ClassOutline co : model.getClasses() )
augument(co);
return true;
}
/**
* Adds "synchoronized" to all the methods.
*/
private void augument(ClassOutline co) {
for (JMethod m : co.implClass.methods())
m.getMods().setSynchronized(true);
}
}