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


Java BodyDeclaration类代码示例

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


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

示例1: checkFinalConditions

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
	pm.beginTask(RefactoringCoreMessages.ExtractMethodRefactoring_checking_new_name, 2);
	pm.subTask(EMPTY);

	RefactoringStatus result = checkMethodName();
	result.merge(checkParameterNames());
	result.merge(checkVarargOrder());
	pm.worked(1);
	if (pm.isCanceled()) {
		throw new OperationCanceledException();
	}

	BodyDeclaration node = fAnalyzer.getEnclosingBodyDeclaration();
	if (node != null) {
		fAnalyzer.checkInput(result, fMethodName, fDestination);
		pm.worked(1);
	}
	pm.done();
	return result;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:ExtractMethodRefactoring.java

示例2: initializeDestinations

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private void initializeDestinations() {
	List<ASTNode> result = new ArrayList<>();
	BodyDeclaration decl = fAnalyzer.getEnclosingBodyDeclaration();
	ASTNode current = ASTResolving.findParentType(decl.getParent());
	if (fAnalyzer.isValidDestination(current)) {
		result.add(current);
	}
	if (current != null && (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration)) {
		ITypeBinding binding = ASTNodes.getEnclosingType(current);
		ASTNode next = ASTResolving.findParentType(current.getParent());
		while (next != null && binding != null && binding.isNested()) {
			if (fAnalyzer.isValidDestination(next)) {
				result.add(next);
			}
			current = next;
			binding = ASTNodes.getEnclosingType(current);
			next = ASTResolving.findParentType(next.getParent());
		}
	}
	fDestinations = result.toArray(new ASTNode[result.size()]);
	fDestination = fDestinations[fDestinationIndex];
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:ExtractMethodRefactoring.java

示例3: addMethodReturnsVoidProposals

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
public static void addMethodReturnsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) throws JavaModelException {
	CompilationUnit astRoot= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (!(selectedNode instanceof ReturnStatement)) {
		return;
	}
	ReturnStatement returnStatement= (ReturnStatement) selectedNode;
	Expression expression= returnStatement.getExpression();
	if (expression == null) {
		return;
	}
	BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
	if (decl instanceof MethodDeclaration) {
		MethodDeclaration methDecl= (MethodDeclaration) decl;
		Type retType= methDecl.getReturnType2();
		if (retType == null || retType.resolveBinding() == null) {
			return;
		}
		TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, IProposalRelevance.METHOD_RETURNS_VOID, proposals);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:ReturnTypeSubProcessor.java

示例4: getInterfaceMethodModifiers

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private int getInterfaceMethodModifiers(ASTNode targetTypeDecl, boolean createAbstractMethod) {
	// for interface and annotation members copy the modifiers from an existing member
	if (targetTypeDecl instanceof TypeDeclaration) {
		TypeDeclaration type= (TypeDeclaration) targetTypeDecl;
		MethodDeclaration[] methodDecls= type.getMethods();
		if (methodDecls.length > 0) {
			if (createAbstractMethod) {
				for (MethodDeclaration methodDeclaration : methodDecls) {
					IMethodBinding methodBinding= methodDeclaration.resolveBinding();
					if (methodBinding != null && JdtFlags.isAbstract(methodBinding)) {
						return methodDeclaration.getModifiers();
					}
				}
			}
			return methodDecls[0].getModifiers() & Modifier.PUBLIC;
		}
		List<BodyDeclaration> bodyDecls= type.bodyDeclarations();
		if (bodyDecls.size() > 0) {
			return bodyDecls.get(0).getModifiers() & Modifier.PUBLIC;
		}
	}
	return 0;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:NewMethodCorrectionProposal.java

示例5: assignModifiersForElementBasedOnDeclaration

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
public static void assignModifiersForElementBasedOnDeclaration(NamedElement element, BodyDeclaration declaration) {
	int modifiers = declaration.getModifiers();
	VisibilityKind visibility = VisibilityProvider.getVisibilityOfNamedElementFromModifiers(element, modifiers);
	element.setVisibility(visibility);

	boolean isAbstract = Modifier.isAbstract(modifiers);
	boolean isStatic = Modifier.isStatic(modifiers);

	if (element instanceof Classifier) {
		Classifier classifierElem = (Classifier) element;
		classifierElem.setIsAbstract(isAbstract);
	}
	if (element instanceof BehavioralFeature) {
		BehavioralFeature featureElem = (BehavioralFeature) element;
		featureElem.setIsStatic(isStatic);
		featureElem.setIsAbstract(isAbstract);
	}
	if (element instanceof Property) {
		Property propertyElem = (Property) element;
		propertyElem.setIsStatic(isStatic);
	}
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:23,代码来源:ElementModifiersAssigner.java

示例6: createFix

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private static Java50Fix createFix(
    CompilationUnit compilationUnit, IProblemLocation problem, String annotation, String label) {
  ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
  if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) return null;

  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
  if (selectedNode == null) return null;

  ASTNode declaringNode = getDeclaringNode(selectedNode);
  if (!(declaringNode instanceof BodyDeclaration)) return null;

  BodyDeclaration declaration = (BodyDeclaration) declaringNode;

  AnnotationRewriteOperation operation = new AnnotationRewriteOperation(declaration, annotation);

  return new Java50Fix(label, compilationUnit, new CompilationUnitRewriteOperation[] {operation});
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:Java50Fix.java

示例7: createAddDeprecatedAnnotationOperations

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private static void createAddDeprecatedAnnotationOperations(
    CompilationUnit compilationUnit,
    IProblemLocation[] locations,
    List<CompilationUnitRewriteOperation> result) {
  for (int i = 0; i < locations.length; i++) {
    IProblemLocation problem = locations[i];

    if (isMissingDeprecationProblem(problem.getProblemId())) {
      ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
      if (selectedNode != null) {

        ASTNode declaringNode = getDeclaringNode(selectedNode);
        if (declaringNode instanceof BodyDeclaration) {
          BodyDeclaration declaration = (BodyDeclaration) declaringNode;
          AnnotationRewriteOperation operation =
              new AnnotationRewriteOperation(declaration, DEPRECATED);
          result.add(operation);
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:Java50Fix.java

示例8: checkModifiers

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
public static void checkModifiers(ProblemCollector collector, BodyDeclaration elem,
		Predicate<Modifier> allowSpecific) {
	for (Object obj : elem.modifiers()) {
		if (!(obj instanceof Modifier)) {
			continue;
		}
		Modifier modifier = (Modifier) obj;
		boolean valid;
		if (allowSpecific.test(modifier)) {
			valid = true;
		} else {
			valid = modifier.isPrivate() || modifier.isPublic() || modifier.isProtected() || modifier.isFinal();
		}
		if (!valid) {
			collector.report(new InvalidModifier(collector.getSourceInfo(), modifier));
		}
	}
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:19,代码来源:Utils.java

示例9: getDelegateJavadocTag

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private TagElement getDelegateJavadocTag(BodyDeclaration declaration) throws JavaModelException {
  Assert.isNotNull(declaration);

  String msg = RefactoringCoreMessages.DelegateCreator_use_member_instead;
  int firstParam = msg.indexOf("{0}"); // $NON-NLS-1$
  Assert.isTrue(firstParam != -1);

  List<ASTNode> fragments = new ArrayList<ASTNode>();
  TextElement text = getAst().newTextElement();
  text.setText(msg.substring(0, firstParam).trim());
  fragments.add(text);

  fragments.add(createJavadocMemberReferenceTag(declaration, getAst()));

  text = getAst().newTextElement();
  text.setText(msg.substring(firstParam + 3).trim());
  fragments.add(text);

  final TagElement tag = getAst().newTagElement();
  tag.setTagName(TagElement.TAG_DEPRECATED);
  tag.fragments().addAll(fragments);
  return tag;
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:DelegateCreator.java

示例10: createFieldsForAccessedLocals

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private void createFieldsForAccessedLocals(
    CompilationUnitRewrite rewrite,
    IVariableBinding[] varBindings,
    String[] fieldNames,
    List<BodyDeclaration> newBodyDeclarations)
    throws CoreException {
  final ImportRewrite importRewrite = rewrite.getImportRewrite();
  final ASTRewrite astRewrite = rewrite.getASTRewrite();
  final AST ast = astRewrite.getAST();

  for (int i = 0; i < varBindings.length; i++) {
    VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
    fragment.setInitializer(null);
    fragment.setName(ast.newSimpleName(fieldNames[i]));
    FieldDeclaration field = ast.newFieldDeclaration(fragment);
    ITypeBinding varType = varBindings[i].getType();
    field.setType(importRewrite.addImport(varType, ast));
    field.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.FINAL));
    if (doAddComments()) {
      String string =
          CodeGeneration.getFieldComment(
              rewrite.getCu(),
              varType.getName(),
              fieldNames[i],
              StubUtility.getLineDelimiterUsed(fCu));
      if (string != null) {
        Javadoc javadoc = (Javadoc) astRewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
        field.setJavadoc(javadoc);
      }
    }

    newBodyDeclarations.add(field);

    addLinkedPosition(KEY_FIELD_NAME_EXT + i, fragment.getName(), astRewrite, false);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:ConvertAnonymousToNestedRefactoring.java

示例11: getFieldsToInitializeInConstructor

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private List<VariableDeclarationFragment> getFieldsToInitializeInConstructor() {
  List<VariableDeclarationFragment> result = new ArrayList<VariableDeclarationFragment>(0);
  for (Iterator<BodyDeclaration> iter = fAnonymousInnerClassNode.bodyDeclarations().iterator();
      iter.hasNext(); ) {
    Object element = iter.next();
    if (element instanceof FieldDeclaration) {
      List<VariableDeclarationFragment> fragments = ((FieldDeclaration) element).fragments();
      for (Iterator<VariableDeclarationFragment> fragmentIter = fragments.iterator();
          fragmentIter.hasNext(); ) {
        VariableDeclarationFragment fragment = fragmentIter.next();
        if (isToBeInitializerInConstructor(fragment, result)) result.add(fragment);
      }
    }
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:ConvertAnonymousToNestedRefactoring.java

示例12: checkFinalConditions

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
  pm.beginTask(RefactoringCoreMessages.ExtractMethodRefactoring_checking_new_name, 2);
  pm.subTask(EMPTY);

  RefactoringStatus result = checkMethodName();
  result.merge(checkParameterNames());
  result.merge(checkVarargOrder());
  pm.worked(1);
  if (pm.isCanceled()) throw new OperationCanceledException();

  BodyDeclaration node = fAnalyzer.getEnclosingBodyDeclaration();
  if (node != null) {
    fAnalyzer.checkInput(result, fMethodName, fDestination);
    pm.worked(1);
  }
  pm.done();
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ExtractMethodRefactoring.java

示例13: initializeDestinations

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private void initializeDestinations() {
  List<ASTNode> result = new ArrayList<ASTNode>();
  BodyDeclaration decl = fAnalyzer.getEnclosingBodyDeclaration();
  ASTNode current = ASTResolving.findParentType(decl.getParent());
  if (fAnalyzer.isValidDestination(current)) {
    result.add(current);
  }
  if (current != null
      && (decl instanceof MethodDeclaration
          || decl instanceof Initializer
          || decl instanceof FieldDeclaration)) {
    ITypeBinding binding = ASTNodes.getEnclosingType(current);
    ASTNode next = ASTResolving.findParentType(current.getParent());
    while (next != null && binding != null && binding.isNested()) {
      if (fAnalyzer.isValidDestination(next)) {
        result.add(next);
      }
      current = next;
      binding = ASTNodes.getEnclosingType(current);
      next = ASTResolving.findParentType(next.getParent());
    }
  }
  fDestinations = result.toArray(new ASTNode[result.size()]);
  fDestination = fDestinations[fDestinationIndex];
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:ExtractMethodRefactoring.java

示例14: computeConstantDeclarationLocation

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private void computeConstantDeclarationLocation() throws JavaModelException {
  if (isDeclarationLocationComputed()) return;

  BodyDeclaration lastStaticDependency = null;
  Iterator<BodyDeclaration> decls =
      getContainingTypeDeclarationNode().bodyDeclarations().iterator();

  while (decls.hasNext()) {
    BodyDeclaration decl = decls.next();

    int modifiers;
    if (decl instanceof FieldDeclaration) modifiers = ((FieldDeclaration) decl).getModifiers();
    else if (decl instanceof Initializer) modifiers = ((Initializer) decl).getModifiers();
    else {
      continue; /* this declaration is not a field declaration
                or initializer, so the placement of the constant
                declaration relative to it does not matter */
    }

    if (Modifier.isStatic(modifiers) && depends(getSelectedExpression(), decl))
      lastStaticDependency = decl;
  }

  if (lastStaticDependency == null) fInsertFirst = true;
  else fToInsertAfter = lastStaticDependency;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:ExtractConstantRefactoring.java

示例15: depends

import org.eclipse.jdt.core.dom.BodyDeclaration; //导入依赖的package包/类
private static boolean depends(IExpressionFragment selected, BodyDeclaration bd) {
  /* We currently consider selected to depend on bd only if db includes a declaration
   * of a static field on which selected depends.
   *
   * A more accurate strategy might be to also check if bd contains (or is) a
   * static initializer containing code which changes the value of a static field on
   * which selected depends.  However, if a static is written to multiple times within
   * during class initialization, it is difficult to predict which value should be used.
   * This would depend on which value is used by expressions instances for which the new
   * constant will be substituted, and there may be many of these; in each, the
   * static field in question may have taken on a different value (if some of these uses
   * occur within static initializers).
   */

  if (bd instanceof FieldDeclaration) {
    FieldDeclaration fieldDecl = (FieldDeclaration) bd;
    for (Iterator<VariableDeclarationFragment> fragments = fieldDecl.fragments().iterator();
        fragments.hasNext(); ) {
      VariableDeclarationFragment fragment = fragments.next();
      SimpleName staticFieldName = fragment.getName();
      if (selected.getSubFragmentsMatching(
                  ASTFragmentFactory.createFragmentForFullSubtree(staticFieldName))
              .length
          != 0) return true;
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:ExtractConstantRefactoring.java


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