本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragment.getElementName方法的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragment.getElementName方法的具体用法?Java IPackageFragment.getElementName怎么用?Java IPackageFragment.getElementName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IPackageFragment
的用法示例。
在下文中一共展示了IPackageFragment.getElementName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getName
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* Obtains the name of the specified element.
* @param elem the element
* @param type the type of the element
* @return the name string
*/
public static String getName(IJavaElement elem) {
int type = elem.getElementType();
if (type == IJavaElement.JAVA_PROJECT) {
return elem.getResource().getName();
} else if (type == IJavaElement.PACKAGE_DECLARATION) {
IPackageFragment jpackage = (IPackageFragment)elem;
return jpackage.getElementName();
} else if (type == IJavaElement.COMPILATION_UNIT) {
return elem.getResource().getName();
}
return "";
}
示例2: build
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* @see IBuilder#build
*/
@Override
public void build(Measure measure, ItemMeasured item) {
IPackageFragment[] packages;
ItemMeasured packageMeasured;
String packageName = "";
try {
packages = project.getPackageFragments();
for (IPackageFragment myPackage : packages) {
if ((myPackage.getKind() == IPackageFragmentRoot.K_SOURCE) && myPackage.hasChildren()) {
packageName = myPackage.isDefaultPackage() ? "(default)" : myPackage.getElementName();
packageMeasured = new ItemMeasured(packageName, item);
addClassBuilder(measure, myPackage, packageMeasured);
item.addChild(packageMeasured);
item.setMax(packageMeasured.getMax());
item.setClassWithMax(packageMeasured.getClassWithMax());
item.addValue(packageMeasured.getValue());
item.addMean(packageMeasured.getMean());
}
}
} catch (JavaModelException exception) {
logger.error(exception);
}
}
示例3: addEdits
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i= 0; i < decls.length; i++) {
ISourceRange range= decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim = "\n";
String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
示例4: getNameOfContainingPackage
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* Gets the name of containing package.
*
* @param xtextDocument
* the xtext document
* @return the name of containing package
*/
public String getNameOfContainingPackage(final IXtextDocument xtextDocument) {
IFile file = xtextDocument.getAdapter(IFile.class);
if (file != null && file.getParent() instanceof IFolder) {
IJavaProject javaProject = JavaCore.create(file.getProject());
try {
IPackageFragment myFragment = javaProject.findPackageFragment(file.getParent().getFullPath());
return myFragment.getElementName();
} catch (JavaModelException e) {
LOGGER.error("Could not determine package for file of given document");
}
}
return null;
}
示例5: getCatalogQualifiedName
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* Gets the catalog qualified name. Instead of using the qualified name provider, which is based
* on the object attribute values, this method uses the resource properties for determining the
* fully qualified name. This is legitimate, because the check catalog FQN consists of the Java
* package name concatenated with the file name (which must be equal to the model name).
*
* @param catalog
* the catalog
* @return the catalog qualified name
*/
public String getCatalogQualifiedName(final CheckCatalog catalog) {
final URI uri = EcoreUtil.getURI(catalog);
IFile file = RuntimeProjectUtil.findFileStorage(uri, mapper);
IJavaProject project = JavaCore.create(file.getProject());
try {
IPackageFragment packageFragment = project.findPackageFragment(file.getParent().getFullPath());
final String fileNameWithoutExtension = file.getName().substring(0, file.getName().length() - (file.getFileExtension().length() + 1));
return packageFragment.getElementName() + '.' + fileNameWithoutExtension;
} catch (JavaModelException e) {
LOGGER.error("Could not determine plugin path for catalog " + catalog.getName(), e);
}
return null;
}
示例6: getQualifiedName
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* Returns the qualified name of the given file, i.e. qualified.name.of.File
* for <code>/project/sourceFolder/qualified/name/of/File.fileExt</code> or
* <code>/project/outputFolder/qualified/name/of/File.fileExt</code>.
*
* @param file
* a file
* @return a qualified name source folder
* @throws TurnusException
*/
public static String getQualifiedName(IFile file) throws TurnusException {
try {
IProject project = file.getProject();
IJavaProject javaProject = JavaCore.create(project);
if (!javaProject.exists()) {
throw new TurnusException(
"Impossible to obtainthe qualified name of \"" + file + "\": the project does not exist");
}
IPath path = file.getParent().getFullPath();
IPackageFragment fragment = null;
if (javaProject.getOutputLocation().isPrefixOf(path)) {
// create relative path
int count = path.matchingFirstSegments(javaProject.getOutputLocation());
IPath relPath = path.removeFirstSegments(count);
// creates full path to source
for (IFolder folder : EcoreUtils.getSourceFolders(project)) {
path = folder.getFullPath().append(relPath);
fragment = javaProject.findPackageFragment(path);
if (fragment != null) {
break;
}
}
} else {
fragment = javaProject.findPackageFragment(path);
}
if (fragment == null) {
throw new TurnusException("Impossible to obtainthe qualified name of \"" + file
+ "\": the package fragment is not valid");
}
String name = file.getFullPath().removeFileExtension().lastSegment();
if (fragment.isDefaultPackage()) {
// handles the default package case
return name;
}
return fragment.getElementName() + "." + name;
} catch (Exception e) {
throw new TurnusException("Impossible to obtainthe qualified name of \"" + file + "\"");
}
}