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


Java ClassInstanceCreation.getAnonymousClassDeclaration方法代码示例

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


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

示例1: rewriteAST

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的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: asClosure

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
public static Optional<GroovyClosure> asClosure(ASTNodeFactory nodeFactory, GroovyClosureBuilder groovyClosureBuilder,
                                      Expression expression, String methodName) {
    if (expression instanceof ClassInstanceCreation) {
        ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
        if (classInstanceCreation.getAnonymousClassDeclaration() != null) {
            AnonymousClassDeclaration classDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
            if (classDeclaration.bodyDeclarations().size() == 1 &&
                    classDeclaration.bodyDeclarations().get(0) instanceof MethodDeclaration &&
                    ((MethodDeclaration) classDeclaration.bodyDeclarations().get(0))
                            .getName().getIdentifier().equals(methodName)) {
                MethodDeclaration methodDeclaration = (MethodDeclaration) classDeclaration.bodyDeclarations().get(0);
                List<Statement> statements = nodeFactory.clone(methodDeclaration.getBody()).statements();
                GroovyClosure closure = groovyClosureBuilder.aClosure()
                        .withBodyStatements(statements)
                        .withTypeLiteral(nodeFactory.typeLiteral(type(nodeFactory, classInstanceCreation)))
                        .withArgument(nodeFactory.clone((SingleVariableDeclaration) methodDeclaration.parameters().get(0)))
                        .build();
                return Optional.of(closure);
            }
        }
    }
    return empty();
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:24,代码来源:ClosureHelper.java

示例3: getDeclarationNode

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

示例4: getDeclarationNode

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

示例5: rewriteAST

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
/** {@inheritDoc} */
@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,
            StubUtility.getLineDelimiterUsed(fUnit));
    if (comment != null && comment.length() > 0) {
      final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
      declaration.setJavadoc(doc);
    }
  }
  if (fragment == null) return;

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

示例6: endVisit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
public void endVisit(ClassInstanceCreation node) {
  Expression receiver = node.getExpression();
  Type createdType = node.getType();

  ConstraintVariable2 typeCv;
  if (node.getAnonymousClassDeclaration() == null) {
    typeCv = getConstraintVariable(createdType);
  } else {
    typeCv = fTCModel.makeImmutableTypeVariable(createdType.resolveBinding(), null);
    setConstraintVariable(createdType, typeCv);
  }
  setConstraintVariable(node, typeCv);

  IMethodBinding methodBinding = node.resolveConstructorBinding();
  Map<String, IndependentTypeVariable2> methodTypeVariables =
      createMethodTypeArguments(methodBinding);
  List<Expression> arguments = node.arguments();
  doVisitMethodInvocationArguments(
      methodBinding, arguments, receiver, methodTypeVariables, createdType);
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:InferTypeArgumentsConstraintCreator.java

示例7: create

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
public ITypeConstraint[] create(ClassInstanceCreation instanceCreation) {
  List<Expression> arguments = instanceCreation.arguments();
  List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
  IMethodBinding methodBinding = instanceCreation.resolveConstructorBinding();
  result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
  if (instanceCreation.getAnonymousClassDeclaration() == null) {
    ConstraintVariable constructorVar =
        fConstraintVariableFactory.makeExpressionOrTypeVariable(instanceCreation, getContext());
    ConstraintVariable typeVar =
        fConstraintVariableFactory.makeRawBindingVariable(instanceCreation.resolveTypeBinding());
    result.addAll(
        Arrays.asList(fTypeConstraintFactory.createDefinesConstraint(constructorVar, typeVar)));
  }
  return result.toArray(new ITypeConstraint[result.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:FullConstraintCreator.java

示例8: endVisit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
public void endVisit(ClassInstanceCreation node) {
	Expression receiver= node.getExpression();
	Type createdType= node.getType();

	ConstraintVariable2 typeCv;
	if (node.getAnonymousClassDeclaration() == null) {
		typeCv= getConstraintVariable(createdType);
	} else {
		typeCv= fTCModel.makeImmutableTypeVariable(createdType.resolveBinding(), null);
		setConstraintVariable(createdType, typeCv);
	}
	setConstraintVariable(node, typeCv);

	IMethodBinding methodBinding= node.resolveConstructorBinding();
	Map<String, IndependentTypeVariable2> methodTypeVariables= createMethodTypeArguments(methodBinding);
	List<Expression> arguments= node.arguments();
	doVisitMethodInvocationArguments(methodBinding, arguments, receiver, methodTypeVariables, createdType);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:InferTypeArgumentsConstraintCreator.java

示例9: getDeclarationNode

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:PotentialProgrammingProblemsFix.java

示例10: visit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
public boolean visit(ClassInstanceCreation node) {
	doVisitChildren(node.typeArguments());
	doVisitNode(node.getType());
	evalQualifyingExpression(node.getExpression(), null);
	if (node.getAnonymousClassDeclaration() != null) {
		node.getAnonymousClassDeclaration().accept(this);
	}
	doVisitChildren(node.arguments());
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:12,代码来源:ImportReferencesCollector.java

示例11: findFormalsForVariable

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
private void findFormalsForVariable(ClassInstanceCreation ctorCall)
		throws JavaModelException, CoreException {
	final int paramNumber = getParamNumber(ctorCall.arguments(), this.name);
	IMethod meth = (IMethod) ctorCall.resolveConstructorBinding()
			.getJavaElement();
	if (meth == null && ctorCall.getAnonymousClassDeclaration() != null) {
		// most likely an anonymous class.
		final AnonymousClassDeclaration acd = ctorCall
				.getAnonymousClassDeclaration();
		final ITypeBinding binding = acd.resolveBinding();
		final ITypeBinding superBinding = binding.getSuperclass();
		for (final Iterator it = Arrays.asList(
				superBinding.getDeclaredMethods()).iterator(); it.hasNext();) {
			final IMethodBinding imb = (IMethodBinding) it.next();
			if (imb.isConstructor()) {
				final ITypeBinding[] itb = imb.getParameterTypes();
				if (itb.length > paramNumber) {
					final ITypeBinding ithParamType = itb[paramNumber];
					if (ithParamType.isEqualTo(((Expression) ctorCall
							.arguments().get(paramNumber))
							.resolveTypeBinding())) {
						meth = (IMethod) imb.getJavaElement();
						break;
					}
				}
			}
		}
	}

	final IMethod top = Util.getTopMostSourceMethod(meth, this.monitor);

	if (top == null)
		throw new DefinitelyNotEnumerizableException(Messages.ASTNodeProcessor_SourceNotPresent,
				ctorCall);
	else
		this.findFormalsForVariable(top, paramNumber);
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:38,代码来源:ASTNodeProcessor.java

示例12: visit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
public boolean visit(ClassInstanceCreation node) {
  doVisitChildren(node.typeArguments());
  doVisitNode(node.getType());
  evalQualifyingExpression(node.getExpression(), null);
  if (node.getAnonymousClassDeclaration() != null) {
    node.getAnonymousClassDeclaration().accept(this);
  }
  doVisitChildren(node.arguments());
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:ImportReferencesCollector.java

示例13: isFunctionalAnonymous

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
static boolean isFunctionalAnonymous(ClassInstanceCreation node) {
  ITypeBinding typeBinding = node.resolveTypeBinding();
  if (typeBinding == null) return false;
  ITypeBinding[] interfaces = typeBinding.getInterfaces();
  if (interfaces.length != 1) return false;
  if (interfaces[0].getFunctionalInterfaceMethod() == null) return false;

  AnonymousClassDeclaration anonymTypeDecl = node.getAnonymousClassDeclaration();
  if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null) return false;

  List<BodyDeclaration> bodyDeclarations = anonymTypeDecl.bodyDeclarations();
  // cannot convert if there are fields or additional methods
  if (bodyDeclarations.size() != 1) return false;
  BodyDeclaration bodyDeclaration = bodyDeclarations.get(0);
  if (!(bodyDeclaration instanceof MethodDeclaration)) return false;

  MethodDeclaration methodDecl = (MethodDeclaration) bodyDeclaration;
  IMethodBinding methodBinding = methodDecl.resolveBinding();

  if (methodBinding == null) return false;
  // generic lambda expressions are not allowed
  if (methodBinding.isGenericMethod()) return false;

  // lambda cannot refer to 'this'/'super' literals
  if (SuperThisReferenceFinder.hasReference(methodDecl)) return false;

  if (!isInTargetTypeContext(node)) return false;

  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:LambdaExpressionsFix.java

示例14: getNodesToDelete

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
private static ASTNode[] getNodesToDelete(IJavaElement element, CompilationUnit cuNode)
    throws JavaModelException {
  // fields are different because you don't delete the whole declaration but only a fragment of it
  if (element.getElementType() == IJavaElement.FIELD) {
    if (JdtFlags.isEnum((IField) element))
      return new ASTNode[] {
        ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element, cuNode)
      };
    else
      return new ASTNode[] {
        ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) element, cuNode)
      };
  }
  if (element.getElementType() == IJavaElement.TYPE && ((IType) element).isLocal()) {
    IType type = (IType) element;
    if (type.isAnonymous()) {
      if (type.getParent().getElementType() == IJavaElement.FIELD) {
        EnumConstantDeclaration enumDecl =
            ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element.getParent(), cuNode);
        if (enumDecl != null && enumDecl.getAnonymousClassDeclaration() != null) {
          return new ASTNode[] {enumDecl.getAnonymousClassDeclaration()};
        }
      }
      ClassInstanceCreation creation =
          ASTNodeSearchUtil.getClassInstanceCreationNode(type, cuNode);
      if (creation != null) {
        if (creation.getLocationInParent() == ExpressionStatement.EXPRESSION_PROPERTY) {
          return new ASTNode[] {creation.getParent()};
        } else if (creation.getLocationInParent()
            == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
          return new ASTNode[] {creation};
        }
        return new ASTNode[] {creation.getAnonymousClassDeclaration()};
      }
      return new ASTNode[0];
    } else {
      ASTNode[] nodes = ASTNodeSearchUtil.getDeclarationNodes(element, cuNode);
      // we have to delete the TypeDeclarationStatement
      nodes[0] = nodes[0].getParent();
      return nodes;
    }
  }
  return ASTNodeSearchUtil.getDeclarationNodes(element, cuNode);
}
 
开发者ID:eclipse,项目名称:che,代码行数:45,代码来源:ASTNodeDeleteUtil.java

示例15: visit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
public final boolean visit(final ClassInstanceCreation node) {
	Assert.isNotNull(node);
	if (node.getParent() instanceof ClassInstanceCreation) {
		final AnonymousClassDeclaration declaration= node.getAnonymousClassDeclaration();
		if (declaration != null)
			visit(declaration);
		return false;
	}
	return super.visit(node);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:MoveInstanceMethodProcessor.java


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