//
// This file is part of the Prose Development Tools for Eclipse package.
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// The Original Code is Prose Development Tools for Eclipse.
//
// The Initial Developer of the Original Code is Angela Nicoara. Portions
// created by Angela Nicoara are Copyright (C) 2006 Angela Nicoara.
// All Rights Reserved.
//
// Contributor(s):
// $Id: NewCrosscutWizardPage.java,v 1.1 2008/11/18 12:26:05 anicoara Exp $
// ==============================================================================
//
package ch.ethz.prose.eclipse.internal.wizards;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.wizards.NewElementWizardPage;
import org.eclipse.jface.wizard.IWizardPage;
/**
* Wizard page to customize crosscuts.
*
* @author Angela Nicoara
* @author Johann Gyger
* @version $Id: NewCrosscutWizardPage.java,v 1.1 2008/11/18 12:26:05 anicoara Exp $
*/
public abstract class NewCrosscutWizardPage extends NewElementWizardPage {
/**
* Create a new crosscut page.
*
* @param name Page name
*/
public NewCrosscutWizardPage(String name) {
super(name);
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizardPage#getNextPage()
*/
public IWizardPage getNextPage() {
return null;
}
/**
* @return Main page of aspect creation wizard
*/
public NewAspectWizardPage getMainPage() {
return ((NewAspectCreationWizard) getWizard()).getMainPage();
}
/**
* Get a unique crosscut field name
*
* @param aspect Aspect that will contain the new crosscut
* @return Unique field name
*/
public String getUniqueFieldName(IType aspect) {
int fieldCount = 1;
String result;
IField field;
do {
result = "c" + fieldCount++;
field = aspect.getField(result);
} while (field.exists());
return result;
}
/**
* Write crosscut source code.
*
* @param aspect Type into which the crosscut is generated
* @param crosscutType Crosscut type
* @param imports Imports manager
* @param monitor Progress Manager
* @param nl New line sequence
* @return Crosscut field that has been created
* @throws CoreException
*/
public abstract IField writeCrosscut(IType aspect, int crosscutType, ImportsManager imports, IProgressMonitor monitor, String nl)
throws CoreException;
/**
* Write the advice signature.
*
* @param imports Imports manager
* @param source Buffer to write on
*/
public abstract void writeAdviceSignature(ImportsManager imports, StringBuffer source);
/**
* Resolve a class name.
*
* @param jproject Project which contains the class
* @param sclassName Class name
* @return Resolved type
* @throws JavaModelException
*/
protected IType resolveClassName(IJavaProject jproject, String sclassName) throws JavaModelException {
if (!jproject.exists()) {
return null;
}
IType type = null;
IPackageFragment currPack = getMainPage().getPackageFragment();
if (type == null && currPack != null) {
String packName = currPack.getElementName();
// search in own package
if (!currPack.isDefaultPackage()) {
type = jproject.findType(packName, sclassName);
}
// search in java.lang
if (type == null && !"java.lang".equals(packName)) { //$NON-NLS-1$
type = jproject.findType("java.lang", sclassName); //$NON-NLS-1$
}
}
// search fully qualified
if (type == null) {
type = jproject.findType(sclassName);
}
return type;
}
}