All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aspectj.ajde.ui.javaoptions.JavaCompilerWarningsOptionsPanel Maven / Gradle / Ivy

Go to download

AspectJ tools most notably contains the AspectJ compiler (AJC). AJC applies aspects to Java classes during compilation, fully replacing Javac for plain Java classes and also compiling native AspectJ or annotation-based @AspectJ syntax. Furthermore, AJC can weave aspects into existing class files in a post-compile binary weaving step. This library is a superset of AspectJ weaver and hence also of AspectJ runtime.

There is a newer version: 1.9.22.1
Show newest version
/********************************************************************
 * Copyright (c) 2007 Contributors. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *
 * Contributors: IBM Corporation - initial API and implementation
 * 				 Helen Hawkins   - initial version (bug 148190)
 *******************************************************************/
package org.aspectj.ajde.ui.javaoptions;

import java.awt.BorderLayout;
import java.awt.Color;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import org.aspectj.ajde.core.JavaOptions;
import org.aspectj.ajde.ui.swing.OptionsPanel;

/**
 * An options panel which displays the java compiler warning options.
 * Users should add this to the Ajde.getOptionsFrame()
 */
public class JavaCompilerWarningsOptionsPanel extends OptionsPanel {

	private final String[] ignoreOrWarning = new String[] {JavaOptions.IGNORE,JavaOptions.WARNING};
	private static final long serialVersionUID = 4491319302490183151L;

	private JPanel parentPanel;

	private Border warningsEtchedBorder;
	private TitledBorder warningsTitleBorder;
	private Border warningsCompoundBorder;
	private JPanel warningsPanel;
	private Box warningsBox = Box.createVerticalBox();

	private JavaBuildOptions javaBuildOptions;

	private Map/*String --> JComboBox*/ warningComboBoxes = new HashMap();

	public JavaCompilerWarningsOptionsPanel(JavaBuildOptions javaBuildOptions) {
		this.javaBuildOptions = javaBuildOptions;
		try {
			jbInit();
			this.setName("Java Compiler Warning Options");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void loadOptions() throws IOException {
		createWarningContents();
	}

	public void saveOptions() throws IOException {
		Set> s = warningComboBoxes.entrySet();
		for (Entry entry : s) {
			String javaOption = entry.getKey();
			JComboBox combo = entry.getValue();
			String value = (String) combo.getSelectedItem();
			javaBuildOptions.setOption(javaOption, value);
		}
	}

	private void jbInit() throws Exception {
		this.setLayout(new BorderLayout());
		createBorders();
		addBordersToPanel();
		this.add(parentPanel,BorderLayout.NORTH);
	}


	private void createWarningContents() {
		createWarningsEntry("Method with a constructor name",JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME);
		createWarningsEntry("Method overriden but not package visible",JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD);
		createWarningsEntry("Deprecated API's",JavaOptions.WARN_DEPRECATION);
		createWarningsEntry("Hidden catch block",JavaOptions.WARN_HIDDEN_CATCH_BLOCKS);
		createWarningsEntry("Unused local or private member",JavaOptions.WARN_UNUSED_LOCALS);
		createWarningsEntry("Parameter is never read",JavaOptions.WARN_UNUSED_PARAMETER);
		createWarningsEntry("Unused import",JavaOptions.WARN_UNUSED_IMPORTS);
		createWarningsEntry("Synthetic access",JavaOptions.WARN_SYNTHETIC_ACCESS);
		createWarningsEntry("Assert identifier",JavaOptions.WARN_ASSERT_IDENITIFIER);
		createWarningsEntry("Non-externalized strings",JavaOptions.WARN_NON_NLS);
		warningsPanel.add(warningsBox,null);
	}

	private void createWarningsEntry(String labelText, String javaOptionToSet) {
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());

		JLabel label = new JLabel();
		label.setFont(new java.awt.Font("Dialog", 0, 11));
		label.setText(labelText);
		panel.add(label,BorderLayout.WEST);

		JComboBox warnings = new JComboBox(ignoreOrWarning);
		String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
		if (value.equals(JavaOptions.IGNORE)) {
			warnings.setSelectedIndex(0);
		} else {
			warnings.setSelectedIndex(1);
		}
		panel.add(warnings,BorderLayout.EAST);
		warningsBox.add(panel,null);
		warningComboBoxes.put(javaOptionToSet,warnings);
	}

	private void createBorders() {
		warningsEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158));
		warningsTitleBorder = new TitledBorder(warningsEtchedBorder, "Warning Options");
		warningsCompoundBorder = BorderFactory.createCompoundBorder(warningsTitleBorder,
				BorderFactory.createEmptyBorder(5, 5, 5, 5));
		warningsTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11));
	}

	private void addBordersToPanel() {
		parentPanel = new JPanel();
		parentPanel.setLayout(new BorderLayout());

		warningsPanel = new JPanel();
		warningsPanel.setBorder(warningsCompoundBorder);
		parentPanel.add(warningsPanel,BorderLayout.CENTER);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy