本文整理匯總了Java中org.eclipse.jdt.core.IPackageFragment.isDefaultPackage方法的典型用法代碼示例。如果您正苦於以下問題:Java IPackageFragment.isDefaultPackage方法的具體用法?Java IPackageFragment.isDefaultPackage怎麽用?Java IPackageFragment.isDefaultPackage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.IPackageFragment
的用法示例。
在下文中一共展示了IPackageFragment.isDefaultPackage方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: getTopLevelPackages
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
public static Collection<IPackageFragment> getTopLevelPackages(IJavaProject javaProject) {
Set<IPackageFragment> packages = new LinkedHashSet<>();
try {
if (javaProject == null || !javaProject.getProject().isAccessible()) {
return packages;
}
for (IPackageFragment f : javaProject.getPackageFragments()){
if (f.getKind() != IPackageFragmentRoot.K_SOURCE || f.isDefaultPackage() ) {
continue;
}
if (f.containsJavaResources() || f.getChildren().length > 1) {
packages.add(f);
}
}
} catch (CoreException e) {
e.printStackTrace();
}
return packages;
}
示例3: appendClassFileLabel
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* Appends the label for a class file. Considers the CF_* flags.
*
* @param classFile the element to render
* @param flags the rendering flags. Flags with names starting with 'CF_' are considered.
*/
public void appendClassFileLabel(IClassFile classFile, long flags) {
if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) {
IPackageFragment pack= (IPackageFragment) classFile.getParent();
if (!pack.isDefaultPackage()) {
appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS));
fBuilder.append('.');
}
}
fBuilder.append(classFile.getElementName());
if (getFlag(flags, JavaElementLabels.CF_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentLabel((IPackageFragment) classFile.getParent(), flags & QUALIFIER_FLAGS);
}
}
示例4: appendCompilationUnitLabel
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* Appends the label for a compilation unit. Considers the CU_* flags.
*
* @param cu the element to render
* @param flags the rendering flags. Flags with names starting with 'CU_' are considered.
*/
public void appendCompilationUnitLabel(ICompilationUnit cu, long flags) {
if (getFlag(flags, JavaElementLabels.CU_QUALIFIED)) {
IPackageFragment pack= (IPackageFragment) cu.getParent();
if (!pack.isDefaultPackage()) {
appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS));
fBuilder.append('.');
}
}
fBuilder.append(cu.getElementName());
if (getFlag(flags, JavaElementLabels.CU_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentLabel((IPackageFragment) cu.getParent(), flags & QUALIFIER_FLAGS);
}
}
示例5: appendPackageFragmentLabel
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* Appends the label for a package fragment. Considers the P_* flags.
*
* @param pack the element to render
* @param flags the rendering flags. Flags with names starting with P_' are considered.
*/
public void appendPackageFragmentLabel(IPackageFragment pack, long flags) {
if (getFlag(flags, JavaElementLabels.P_QUALIFIED)) {
appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
fBuilder.append('/');
}
if (pack.isDefaultPackage()) {
fBuilder.append(JavaElementLabels.DEFAULT_PACKAGE);
} else if (getFlag(flags, JavaElementLabels.P_COMPRESSED)) {
appendCompressedPackageFragment(pack);
} else {
fBuilder.append(getElementName(pack));
}
if (getFlag(flags, JavaElementLabels.P_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
}
}
示例6: 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()));
}
示例7: getName
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
@Override
public String getName() {
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
try {
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
} catch(JavaModelException e) {
JavaLanguageServerPlugin.log(e);
}
return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
示例8: 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 + "\"");
}
}