当前位置: 首页>>代码示例>>Java>>正文


Java IPackageFragment.getElementName方法代码示例

本文整理汇总了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 "";
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:22,代码来源:ResourceMacro.java

示例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);
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:28,代码来源:PackageBuilder.java

示例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()));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:CorrectPackageDeclarationProposal.java

示例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;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:21,代码来源:CheckResourceUtil.java

示例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;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:24,代码来源:CheckProjectHelper.java

示例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 + "\"");
	}
}
 
开发者ID:turnus,项目名称:turnus,代码行数:54,代码来源:FileUtils.java


注:本文中的org.eclipse.jdt.core.IPackageFragment.getElementName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。