com.sun.tools.xjc.addon.sync.SynchronizedMethodAddOn Maven / Gradle / Ivy
/*
* Copyright (c) 1997, 2021 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 {
@Override
public String getOptionName() {
return "Xsync-methods";
}
@Override
public String getUsage() {
return " -Xsync-methods : generate accessor methods with the 'synchronized' keyword";
}
@Override
public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException {
return 0; // no option recognized
}
@Override
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.mods().setSynchronized(true);
}
}