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


Java AbstractTypeDeclaration类代码示例

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


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

示例1: rewriteAST

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:57,代码来源:AbstractSerialVersionOperation.java

示例2: decideRuleKind

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
private static String decideRuleKind(ReferencedClassesParser parser, Set<String> dependencies) {
  CompilationUnit cu = parser.compilationUnit;
  if (cu.types().isEmpty()) {
    return "java_library";
  }
  AbstractTypeDeclaration topLevelClass = (AbstractTypeDeclaration) cu.types().get(0);
  if ((topLevelClass.getModifiers() & Modifier.ABSTRACT) != 0) {
    // Class is abstract, can't be a test.
    return "java_library";
  }

  // JUnit 4 tests
  if (parser.className.endsWith("Test") && dependencies.contains("org.junit.Test")) {
    return "java_test";
  }

  if (any(
      topLevelClass.bodyDeclarations(),
      d -> d instanceof MethodDeclaration && isMainMethod((MethodDeclaration) d))) {
    return "java_binary";
  }

  return "java_library";
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:25,代码来源:JavaSourceFileParser.java

示例3: getBindingOfParentTypeContext

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
/**
 * Returns the type binding of the node's type context or null if the node is inside
 * an annotation, type parameter, super type declaration, or Javadoc of a top level type.
 * The result of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in the type's body.
 *
 * @param node an AST node
 * @return the type binding of the node's parent type context, or <code>null</code>
 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
	StructuralPropertyDescriptor lastLocation= null;

	while (node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			AbstractTypeDeclaration decl= (AbstractTypeDeclaration) node;
			if (lastLocation == decl.getBodyDeclarationsProperty()
					|| lastLocation == decl.getJavadocProperty()) {
				return decl.resolveBinding();
			} else if (decl instanceof EnumDeclaration && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
				return decl.resolveBinding();
			}
		} else if (node instanceof AnonymousClassDeclaration) {
			return ((AnonymousClassDeclaration) node).resolveBinding();
		}
		lastLocation= node.getLocationInParent();
		node= node.getParent();
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:29,代码来源:Bindings.java

示例4: getReceiverTypeBinding

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
/**
 * Returns the receiver's type binding of the given method invocation.
 *
 * @param invocation method invocation to resolve type of
 * @return the type binding of the receiver
 */
public static ITypeBinding getReceiverTypeBinding(MethodInvocation invocation) {
	ITypeBinding result= null;
	Expression exp= invocation.getExpression();
	if(exp != null) {
		return exp.resolveTypeBinding();
	}
	else {
		AbstractTypeDeclaration type= (AbstractTypeDeclaration)getParent(invocation, AbstractTypeDeclaration.class);
		if (type != null) {
			return type.resolveBinding();
		}
	}
	return result;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:ASTNodes.java

示例5: getEnclosingDeclaration

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
public static IBinding getEnclosingDeclaration(ASTNode node) {
	while(node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			return ((AbstractTypeDeclaration)node).resolveBinding();
		} else if (node instanceof AnonymousClassDeclaration) {
			return ((AnonymousClassDeclaration)node).resolveBinding();
		} else if (node instanceof MethodDeclaration) {
			return ((MethodDeclaration)node).resolveBinding();
		} else if (node instanceof FieldDeclaration) {
			List<?> fragments= ((FieldDeclaration)node).fragments();
			if (fragments.size() > 0) {
				return ((VariableDeclarationFragment)fragments.get(0)).resolveBinding();
			}
		} else if (node instanceof VariableDeclarationFragment) {
			IVariableBinding variableBinding= ((VariableDeclarationFragment)node).resolveBinding();
			if (variableBinding.getDeclaringMethod() != null || variableBinding.getDeclaringClass() != null)
			{
				return variableBinding;
				// workaround for incomplete wiring of DOM bindings: keep searching when variableBinding is unparented
			}
		}
		node= node.getParent();
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodes.java

示例6: getCatchBodyContent

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
public static String getCatchBodyContent(ICompilationUnit cu, String exceptionType, String variableName, ASTNode locationInAST, String lineDelimiter) throws CoreException {
	String enclosingType = ""; //$NON-NLS-1$
	String enclosingMethod = ""; //$NON-NLS-1$

	if (locationInAST != null) {
		MethodDeclaration parentMethod = ASTResolving.findParentMethodDeclaration(locationInAST);
		if (parentMethod != null) {
			enclosingMethod = parentMethod.getName().getIdentifier();
			locationInAST = parentMethod;
		}
		ASTNode parentType = ASTResolving.findParentType(locationInAST);
		if (parentType instanceof AbstractTypeDeclaration) {
			enclosingType = ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
		}
	}
	return getCatchBodyContent(cu, exceptionType, variableName, enclosingType, enclosingMethod, lineDelimiter);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:StubUtility.java

示例7: getDeclarationNode

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name
 *            the name of the node
 *
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
	ASTNode parent = name.getParent();
	if (!(parent instanceof AbstractTypeDeclaration)) {

		parent = parent.getParent();
		if (parent instanceof ParameterizedType || parent instanceof Type) {
			parent = parent.getParent();
		}
		if (parent instanceof ClassInstanceCreation) {

			final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
			parent = creation.getAnonymousClassDeclaration();
		}
	}
	return parent;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:PotentialProgrammingProblemsFix.java

示例8: isTypeBindingNull

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
private static boolean isTypeBindingNull(ASTNode typeNode) {
	if (typeNode instanceof AbstractTypeDeclaration) {
		AbstractTypeDeclaration abstractTypeDeclaration= (AbstractTypeDeclaration) typeNode;
		if (abstractTypeDeclaration.resolveBinding() == null) {
			return true;
		}

		return false;
	} else if (typeNode instanceof AnonymousClassDeclaration) {
		AnonymousClassDeclaration anonymousClassDeclaration= (AnonymousClassDeclaration) typeNode;
		if (anonymousClassDeclaration.resolveBinding() == null) {
			return true;
		}

		return false;
	} else if (typeNode instanceof EnumConstantDeclaration) {
		return false;
	} else {
		return true;
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:UnimplementedCodeFix.java

示例9: perform

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
public static List<Match> perform(ASTNode start, ASTNode[] snippet) {
	Assert.isTrue(start instanceof AbstractTypeDeclaration || start instanceof AnonymousClassDeclaration);
	SnippetFinder finder = new SnippetFinder(snippet);
	start.accept(finder);
	for (Iterator<Match> iter = finder.fResult.iterator(); iter.hasNext();) {
		Match match = iter.next();
		ASTNode[] nodes = match.getNodes();
		// doesn't match if the candidate is the left hand side of an
		// assignment and the snippet consists of a single node.
		// Otherwise y= i; i= z; results in y= e(); e()= z;
		if (nodes.length == 1 && isLeftHandSideOfAssignment(nodes[0])) {
			iter.remove();
		}
	}
	return finder.fResult;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:17,代码来源:SnippetFinder.java

示例10: getRewrite

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() throws CoreException {
	CompilationUnit astRoot= fContext.getASTRoot();

	AST ast= astRoot.getAST();
	ASTRewrite rewrite= ASTRewrite.create(ast);

	AbstractTypeDeclaration decl= findTypeDeclaration(astRoot.types(), fOldName);
	if (decl != null) {
		ASTNode[] sameNodes= LinkedNodeFinder.findByNode(astRoot, decl.getName());
		for (int i= 0; i < sameNodes.length; i++) {
			rewrite.replace(sameNodes[i], ast.newSimpleName(fNewName), null);
		}
	}
	return rewrite;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:17,代码来源:CorrectMainTypeNameProposal.java

示例11: getBindingOfParentTypeContext

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
/**
 * Returns the type binding of the node's type context or null if the node is inside an
 * annotation, type parameter, super type declaration, or Javadoc of a top level type. The result
 * of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in
 * the type's body.
 *
 * @param node an AST node
 * @return the type binding of the node's parent type context, or <code>null</code>
 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
  StructuralPropertyDescriptor lastLocation = null;

  while (node != null) {
    if (node instanceof AbstractTypeDeclaration) {
      AbstractTypeDeclaration decl = (AbstractTypeDeclaration) node;
      if (lastLocation == decl.getBodyDeclarationsProperty()
          || lastLocation == decl.getJavadocProperty()) {
        return decl.resolveBinding();
      } else if (decl instanceof EnumDeclaration
          && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
        return decl.resolveBinding();
      }
    } else if (node instanceof AnonymousClassDeclaration) {
      return ((AnonymousClassDeclaration) node).resolveBinding();
    }
    lastLocation = node.getLocationInParent();
    node = node.getParent();
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:Bindings.java

示例12: addOuterDeclarationsForLocalType

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
private boolean addOuterDeclarationsForLocalType(
    ITypeBinding localBinding, int flags, IBindingRequestor requestor) {
  ASTNode node = fRoot.findDeclaringNode(localBinding);
  if (node == null) {
    return false;
  }

  if (node instanceof AbstractTypeDeclaration || node instanceof AnonymousClassDeclaration) {
    if (addLocalDeclarations(node.getParent(), flags, requestor)) return true;

    ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(node.getParent());
    if (parentTypeBinding != null) {
      if (addTypeDeclarations(parentTypeBinding, flags, requestor)) return true;
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:ScopeAnalyzer.java

示例13: getCatchBodyContent

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
public static String getCatchBodyContent(
    ICompilationUnit cu,
    String exceptionType,
    String variableName,
    ASTNode locationInAST,
    String lineDelimiter)
    throws CoreException {
  String enclosingType = ""; // $NON-NLS-1$
  String enclosingMethod = ""; // $NON-NLS-1$

  if (locationInAST != null) {
    MethodDeclaration parentMethod = ASTResolving.findParentMethodDeclaration(locationInAST);
    if (parentMethod != null) {
      enclosingMethod = parentMethod.getName().getIdentifier();
      locationInAST = parentMethod;
    }
    ASTNode parentType = ASTResolving.findParentType(locationInAST);
    if (parentType instanceof AbstractTypeDeclaration) {
      enclosingType = ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
    }
  }
  return getCatchBodyContent(
      cu, exceptionType, variableName, enclosingType, enclosingMethod, lineDelimiter);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:StubUtility.java

示例14: getDeclarationNode

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name the name of the node
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
  ASTNode parent = name.getParent();
  if (!(parent instanceof AbstractTypeDeclaration)) {

    parent = parent.getParent();
    if (parent instanceof ParameterizedType || parent instanceof Type)
      parent = parent.getParent();
    if (parent instanceof ClassInstanceCreation) {

      final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
      parent = creation.getAnonymousClassDeclaration();
    }
  }
  return parent;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:PotentialProgrammingProblemsFix.java

示例15: getSelectedTypeNode

import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; //导入依赖的package包/类
public static ASTNode getSelectedTypeNode(CompilationUnit root, IProblemLocation problem) {
  ASTNode selectedNode = problem.getCoveringNode(root);
  if (selectedNode == null) return null;

  if (selectedNode.getNodeType() == ASTNode.ANONYMOUS_CLASS_DECLARATION) { // bug 200016
    selectedNode = selectedNode.getParent();
  }

  if (selectedNode.getLocationInParent() == EnumConstantDeclaration.NAME_PROPERTY) {
    selectedNode = selectedNode.getParent();
  }
  if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME
      && selectedNode.getParent() instanceof AbstractTypeDeclaration) {
    return selectedNode.getParent();
  } else if (selectedNode.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
    return ((ClassInstanceCreation) selectedNode).getAnonymousClassDeclaration();
  } else if (selectedNode.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION) {
    EnumConstantDeclaration enumConst = (EnumConstantDeclaration) selectedNode;
    if (enumConst.getAnonymousClassDeclaration() != null)
      return enumConst.getAnonymousClassDeclaration();
    return enumConst;
  } else {
    return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:UnimplementedCodeFix.java


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