⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 includedirective.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2005 Craig Setera
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 */
package eclipseme.core.internal.preprocessor.directive;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.dom.Comment;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;

import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.preprocessor.Directive;
import eclipseme.core.internal.preprocessor.Preprocessor;
import eclipseme.core.internal.preprocessor.ProcessingState;
import eclipseme.core.model.SymbolDefinitionSet;

/**
 * Defines an identifier, thus making its value "true" when it 
 * is referenced in further expressions.
 * <p />
 * Copyright (c) 2003-2005 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.4 $
 * <br>
 * $Date: 2006/11/12 01:11:01 $
 * <br>
 * @author Craig Setera
 */
public class IncludeDirective extends AbstractStartDirective {
	/**
	 * Construct a new instance.
	 * 
	 * @param resource
	 * @param comment
	 * @param commentText
	 */
	public IncludeDirective(
		IResource resource,
		Comment comment, 
		String commentText) 
	{
		super(resource, comment, commentText);
	}

	/**
	 * @see eclipseme.core.internal.preprocessor.Directive#execute(ProcessingState, IProgressMonitor)
	 */
	public void execute(ProcessingState processingState, IProgressMonitor monitor) 
		throws CoreException 
	{
		if (validateClosed()) {
			String filename = getDirectiveArguments();
			if ((filename != null) && (filename.length() > 0)) {
				processInclude(processingState, monitor);
			} else {
				createProblemMarker(IMarker.SEVERITY_WARNING, filename + " not found");
			}
		}
	}

	/**
	 * @see eclipseme.core.internal.preprocessor.Directive#getType()
	 */
	public int getType() {
		return TYPE_INCLUDE;
	}

	/**
	 * @see eclipseme.core.internal.preprocessor.Directive#isEnabled(eclipseme.core.model.SymbolDefinitionSet, IProgressMonitor)
	 */
	protected boolean isEnabled(SymbolDefinitionSet identifiers, IProgressMonitor monitor) {
		return true;
	}

	/**
	 * Return the resource referenced by the include directive.
	 * 
	 * @return
	 */
	private IFile getIncludedFile() {
		IProject project = resource.getProject();
		return project.getFile(getDirectiveArguments());
	}

	/**
	 * Process the include directive.
	 * 
	 * @param processingState
	 * @param monitor
	 * @throws CoreException
	 */
	private void processInclude(ProcessingState processingState, IProgressMonitor monitor) throws CoreException {
		IResource includedResource = getIncludedFile();
		
		Preprocessor preprocessor = new Preprocessor();
		IDocument document = 
			preprocessor.preprocess(includedResource, processingState.symbols, monitor);
		
		int directiveLine = getLine(processingState);
		try {
			int offset = processingState.document.getLineOffset(directiveLine + 1);
			insertText(processingState, offset, document.get());
		} catch (BadLocationException e) {
			EclipseMECorePlugin.throwCoreException(IStatus.ERROR, -999, e);
		}
	}

	/**
	 * Return a boolean indicating whether the directive is appropriately
	 * closed.
	 * 
	 * @return
	 * @throws CoreException 
	 */
	private boolean validateClosed() 
		throws CoreException 
	{
		Directive[] children = getChildren();
		boolean closed = 
			(children.length > 0) &&
			(children[0].getType() == Directive.TYPE_ENDINCLUDE);
		
		if (!closed) {
			createProblemMarker(IMarker.SEVERITY_ERROR, "#include not properly closed with #endinclude");
		}
		
		return closed;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -