📄 import.java
字号:
/*******************************************************************************
* Copyright (c) 2004 Stefan Zeiger and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.novocode.com/legal/epl-v10.html
*
* Contributors:
* Stefan Zeiger (szeiger@novocode.com) - initial API and implementation
*******************************************************************************/
package com.novocode.naf.resource;
import org.w3c.dom.Element;
import com.novocode.naf.app.NAFException;
/**
* An <code><import></code> statement.
*
* @author Stefan Zeiger (szeiger@novocode.com)
* @since Nov 6, 2004
* @version $Id: Import.java,v 1.2 2005/05/08 18:49:27 szeiger Exp $
*/
public final class Import
{
private String as, clazz, prefix, suffix, unqualifiedClass, using;
public Import(String clazz, String as, String using)
{
this.clazz = clazz;
this.as = as;
int sep = clazz.indexOf('*');
if(sep != -1)
{
prefix = clazz.substring(0, sep);
suffix = clazz.substring(sep+1);
}
else
{
sep = clazz.lastIndexOf('.');
if(sep != -1) unqualifiedClass = clazz.substring(sep+1);
else unqualifiedClass = clazz;
}
}
public static Import parse(Element e) throws NAFException
{
String clazz = e.getAttribute("class");
String as = e.getAttribute("as");
String using = e.getAttribute("using");
if(as != null && as.length() == 0) as = null;
if(clazz == null || clazz.length() == 0)
throw new NAFException("An <import> element must contain a non-empty \"class\" attribute");
if(clazz.indexOf('*') != -1 && as != null)
throw new NAFException("An <import> element with a class pattern may not contain an \"as\" attribute");
return new Import(clazz, as, using);
}
public String toString()
{
String s = "[import "+clazz;
if(as != null) s += " as "+as;
return s + "]";
}
private String classNameFor(String s)
{
if(as != null && as.equals(s)) return clazz;
else if(prefix != null) return prefix + s + suffix;
else if(unqualifiedClass.equals(s)) return clazz;
else return null;
}
public Class classFor(String s)
{
String n = classNameFor(s);
if(n == null) return null;
try { return Class.forName(n); }
catch(ClassNotFoundException ex) { return null; }
}
public String getUsing()
{
return using;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -