Java Code Examples for org.eclipse.jdt.core.dom.ASTNode#PACKAGE_DECLARATION

The following examples show how to use org.eclipse.jdt.core.dom.ASTNode#PACKAGE_DECLARATION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void insertToCu(ASTRewrite rewrite, ASTNode node, CompilationUnit cuNode) {
	switch (node.getNodeType()) {
		case ASTNode.TYPE_DECLARATION:
		case ASTNode.ENUM_DECLARATION:
		case ASTNode.ANNOTATION_TYPE_DECLARATION:
			rewrite.getListRewrite(cuNode, CompilationUnit.TYPES_PROPERTY).insertAt(node, ASTNodes.getInsertionIndex((AbstractTypeDeclaration) node, cuNode.types()), null);
			break;
		case ASTNode.IMPORT_DECLARATION:
			rewrite.getListRewrite(cuNode, CompilationUnit.IMPORTS_PROPERTY).insertLast(node, null);
			break;
		case ASTNode.PACKAGE_DECLARATION:
			// only insert if none exists
			if (cuNode.getPackage() == null)
				rewrite.set(cuNode, CompilationUnit.PACKAGE_PROPERTY, node, null);
			break;
		default:
			Assert.isTrue(false, String.valueOf(node.getNodeType()));
	}
}
 
Example 2
Source File: JavaTextBufferNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the corresponding place holder type for the given element.
 * @return a place holder type (see ASTRewrite) or -1 if there is no corresponding placeholder
 */
static final int getPlaceHolderType(ITypedElement element) {

	if (element instanceof DocumentRangeNode) {
		JavaNode jn= (JavaNode) element;
		switch (jn.getTypeCode()) {

		case JavaNode.PACKAGE:
		    return ASTNode.PACKAGE_DECLARATION;

		case JavaNode.CLASS:
		case JavaNode.INTERFACE:
			return ASTNode.TYPE_DECLARATION;

		case JavaNode.ENUM:
			return ASTNode.ENUM_DECLARATION;

		case JavaNode.ANNOTATION:
			return ASTNode.ANNOTATION_TYPE_DECLARATION;

		case JavaNode.CONSTRUCTOR:
		case JavaNode.METHOD:
			return ASTNode.METHOD_DECLARATION;

		case JavaNode.FIELD:
			return ASTNode.FIELD_DECLARATION;

		case JavaNode.INIT:
			return ASTNode.INITIALIZER;

		case JavaNode.IMPORT:
		case JavaNode.IMPORT_CONTAINER:
			return ASTNode.IMPORT_DECLARATION;

		case JavaNode.CU:
		    return ASTNode.COMPILATION_UNIT;
		}
	}
	return -1;
}
 
Example 3
Source File: JavaAddElementFromHistoryImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the corresponding place holder type for the given element.
 * @return a place holder type (see ASTRewrite) or -1 if there is no corresponding placeholder
 */
private int getPlaceHolderType(ITypedElement element) {

	if (element instanceof DocumentRangeNode) {
		JavaNode jn= (JavaNode) element;
		switch (jn.getTypeCode()) {

		case JavaNode.PACKAGE:
		    return ASTNode.PACKAGE_DECLARATION;

		case JavaNode.CLASS:
		case JavaNode.INTERFACE:
			return ASTNode.TYPE_DECLARATION;

		case JavaNode.ENUM:
			return ASTNode.ENUM_DECLARATION;

		case JavaNode.ANNOTATION:
			return ASTNode.ANNOTATION_TYPE_DECLARATION;

		case JavaNode.CONSTRUCTOR:
		case JavaNode.METHOD:
			return ASTNode.METHOD_DECLARATION;

		case JavaNode.FIELD:
			return ASTNode.FIELD_DECLARATION;

		case JavaNode.INIT:
			return ASTNode.INITIALIZER;

		case JavaNode.IMPORT:
		case JavaNode.IMPORT_CONTAINER:
			return ASTNode.IMPORT_DECLARATION;

		case JavaNode.CU:
		    return ASTNode.COMPILATION_UNIT;
		}
	}
	return -1;
}