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


Java IPackageDeclaration类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.IPackageDeclaration的典型用法代码示例。如果您正苦于以下问题:Java IPackageDeclaration类的具体用法?Java IPackageDeclaration怎么用?Java IPackageDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IPackageDeclaration类属于org.eclipse.jdt.core包,在下文中一共展示了IPackageDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addEdits

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的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

示例2: getName

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的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)));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:CorrectPackageDeclarationProposal.java

示例3: testResolveStandaloneCompilationUnit

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
@Test
public void testResolveStandaloneCompilationUnit() throws CoreException {
	Path helloSrcRoot = Paths.get("projects", "eclipse", "hello", "src").toAbsolutePath();
	URI uri = helloSrcRoot.resolve(Paths.get("java", "Foo.java")).toUri();
	ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri.toString());
	assertNotNull("Could not find compilation unit for " + uri, cu);
	assertEquals(ProjectsManager.DEFAULT_PROJECT_NAME, cu.getResource().getProject().getName());
	IJavaElement[] elements = cu.getChildren();
	assertEquals(2, elements.length);
	assertTrue(IPackageDeclaration.class.isAssignableFrom(elements[0].getClass()));
	assertTrue(IType.class.isAssignableFrom(elements[1].getClass()));
	assertTrue(cu.getResource().isLinked());
	assertEquals(cu.getResource(), JDTUtils.findResource(uri, ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI));

	uri = helloSrcRoot.resolve("NoPackage.java").toUri();
	cu = JDTUtils.resolveCompilationUnit(uri.toString());
	assertNotNull("Could not find compilation unit for " + uri, cu);
	assertEquals(ProjectsManager.DEFAULT_PROJECT_NAME, cu.getResource().getProject().getName());
	elements = cu.getChildren();
	assertEquals(1, elements.length);
	assertTrue(IType.class.isAssignableFrom(elements[0].getClass()));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:JDTUtilsTest.java

示例4: getDeclarationNodes

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode)
    throws JavaModelException {
  switch (element.getElementType()) {
    case IJavaElement.FIELD:
      return new ASTNode[] {getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
    case IJavaElement.IMPORT_CONTAINER:
      return getImportNodes((IImportContainer) element, cuNode);
    case IJavaElement.IMPORT_DECLARATION:
      return new ASTNode[] {getImportDeclarationNode((IImportDeclaration) element, cuNode)};
    case IJavaElement.INITIALIZER:
      return new ASTNode[] {getInitializerNode((IInitializer) element, cuNode)};
    case IJavaElement.METHOD:
      return new ASTNode[] {
        getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)
      };
    case IJavaElement.PACKAGE_DECLARATION:
      return new ASTNode[] {getPackageDeclarationNode((IPackageDeclaration) element, cuNode)};
    case IJavaElement.TYPE:
      return new ASTNode[] {getAbstractTypeDeclarationNode((IType) element, cuNode)};
    default:
      Assert.isTrue(false, String.valueOf(element.getElementType()));
      return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ASTNodeSearchUtil.java

示例5: extractJavadoc

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
/**
 * Extracts the Javadoc for the given Java element and returns it as HTML.
 *
 * @param element the Java element to get the documentation for
 * @return the Javadoc for Java element or <code>null</code> if the Javadoc is not available
 * @throws org.eclipse.core.runtime.CoreException if fetching the Javadoc for the given element
 *     failed connected
 */
private String extractJavadoc(IJavaElement element) throws CoreException {
  if (element instanceof IMember) {
    return JavadocContentAccess2.getHTMLContent(
        (IMember) element,
        true,
        UrlContextProvider.get(element.getJavaProject().getPath().toString()));
  } else if (element instanceof IPackageDeclaration) {
    return JavadocContentAccess2.getHTMLContent(
        (IPackageDeclaration) element,
        UrlContextProvider.get(element.getJavaProject().getPath().toString()));
  } else if (element instanceof IPackageFragment) {
    return JavadocContentAccess2.getHTMLContent(
        (IPackageFragment) element,
        UrlContextProvider.get(element.getJavaProject().getPath().toString()));
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:ProposalInfo.java

示例6: getName

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的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) {
    JavaPlugin.log(e);
  }
  return (Messages.format(
      CorrectionMessages.CorrectPackageDeclarationProposal_change_description,
      JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:CorrectPackageDeclarationProposal.java

示例7: getDeclarationNodes

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException {
	switch(element.getElementType()){
		case IJavaElement.FIELD:
			return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
		case IJavaElement.IMPORT_CONTAINER:
			return getImportNodes((IImportContainer)element, cuNode);
		case IJavaElement.IMPORT_DECLARATION:
			return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)};
		case IJavaElement.INITIALIZER:
			return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)};
		case IJavaElement.METHOD:
			return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)};
		case IJavaElement.PACKAGE_DECLARATION:
			return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)};
		case IJavaElement.TYPE:
			return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)};
		default:
			Assert.isTrue(false, String.valueOf(element.getElementType()));
			return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:ASTNodeSearchUtil.java

示例8: isMoveAvailable

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
public static boolean isMoveAvailable(final IResource[] resources, final IJavaElement[] elements) throws JavaModelException {
	if (elements != null) {
		for (int index= 0; index < elements.length; index++) {
			IJavaElement element= elements[index];
			if (element == null || !element.exists())
				return false;
			if ((element instanceof IType) && ((IType) element).isLocal())
				return false;
			if ((element instanceof IPackageDeclaration))
				return false;
			if (element instanceof IField && JdtFlags.isEnum((IMember) element))
				return false;
		}
	}
	return ReorgPolicyFactory.createMovePolicy(resources, elements).canEnable();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:RefactoringAvailabilityTester.java

示例9: getInput

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
/**
 * Returns the input for the given element. The Java breadcrumb does not show some elements of
 * the model:
 * <ul>
 * 		<li><code>ITypeRoots</li>
 * 		<li><code>IPackageDeclaration</li>
 * 		<li><code>IImportContainer</li>
 * 		<li><code>IImportDeclaration</li>
 * </ul>
 *
 * @param element the potential input element
 * @return the element to use as input
 */
private IJavaElement getInput(IJavaElement element) {
	try {
		if (element instanceof IImportDeclaration)
			element= element.getParent();

		if (element instanceof IImportContainer)
			element= element.getParent();

		if (element instanceof IPackageDeclaration)
			element= element.getParent();

		if (element instanceof ICompilationUnit) {
			IType[] types= ((ICompilationUnit) element).getTypes();
			if (types.length > 0)
				element= types[0];
		}

		if (element instanceof IClassFile)
			element= ((IClassFile) element).getType();

		return element;
	} catch (JavaModelException e) {
		return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:39,代码来源:JavaEditorBreadcrumb.java

示例10: addEdits

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的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= StubUtility.getLineDelimiterUsed(cu);
		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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:CorrectPackageDeclarationProposal.java

示例11: getName

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的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) {
		JavaPlugin.log(e);
	}
	return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:CorrectPackageDeclarationProposal.java

示例12: widgetSelected

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
@Override
public void widgetSelected(SelectionEvent e) {
    Shell shell = Display.getDefault().getActiveShell();
    JavaSelectDialog dialog = new JavaSelectDialog(shell, "Please select a custom class.");
    dialog.open();
    ICompilationUnit unit = dialog.getCompilationUnit();
    String javaFileName = unit.getElementName();
    String javaName = javaFileName.replaceFirst(".java$", "");
    try {
        IPackageDeclaration declaration = unit.getPackageDeclarations()[0];
        String packageName = declaration.getElementName();
        String fullName = packageName + "." + javaName;
        text.setText(fullName);
    } catch (JavaModelException t) {
        throw Throwables.propagate(new SystemException(t));
    } finally {
        dialog.close();
    }
}
 
开发者ID:ko2ic,项目名称:comment-tag-gen-plugin,代码行数:20,代码来源:JavaSelectButton.java

示例13: getImportDeclaration

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
public static String getImportDeclaration(IFile file, String className)
		throws JavaModelException {
	String fullyQualifiedName = null;
	ICompilationUnit currentFile = JavaCore.createCompilationUnitFrom(file);
	IImportDeclaration[] imports = currentFile.getImports();
	for (IImportDeclaration iImportDeclaration : imports) {
		if (iImportDeclaration.getElementName().endsWith(
				MethodUtil.PACKAGE_DOT + className)) {
			fullyQualifiedName = iImportDeclaration.getElementName();
			break;
		}
	}
	if (fullyQualifiedName == null || fullyQualifiedName.length() <= 0) {
		IPackageDeclaration packageDeclaration = currentFile
				.getPackageDeclarations()[0];
		fullyQualifiedName = packageDeclaration.getElementName()
				+ MethodUtil.PACKAGE_DOT + className;
	}
	return fullyQualifiedName;
}
 
开发者ID:dongdn,项目名称:get-set-generator,代码行数:21,代码来源:ProjectUtil.java

示例14: getPackageDeclaration

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
public static IPackageDeclaration getPackageDeclaration(ICompilationUnit cu) {
	try {
		IPackageDeclaration[] pds = cu.getPackageDeclarations();
		int i = 0, j = -1, count = 0;
		for (; i < pds.length; i++) {
			if (pds[i].exists()) {
				count++;
				j = i;
			}
		}
		if (count != 1) {
			return null;
		}
		return pds[j];
	} catch (JavaModelException e) {
		LoggerUtil.error(e);
		return null;
	}
}
 
开发者ID:cntoplolicon,项目名称:seasar2-assistant,代码行数:20,代码来源:NamingConventionUtil.java

示例15: getCompilationUnitFor

import org.eclipse.jdt.core.IPackageDeclaration; //导入依赖的package包/类
protected ICompilationUnit getCompilationUnitFor(IJavaElement element) {

		if (element instanceof ICompilationUnit) {
			return (ICompilationUnit)element;
		}

		if (element instanceof IMember) {
			return ((IMember)element).getCompilationUnit();
		}

		if (element instanceof IPackageDeclaration ||
			element instanceof IImportDeclaration) {
				return (ICompilationUnit)element.getParent();
			}

		return null;

	}
 
开发者ID:jwloka,项目名称:reflectify,代码行数:19,代码来源:AbstractJavaModelTests.java


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