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


Java ClassInstanceCreation.TYPE_PROPERTY属性代码示例

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


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

示例1: isIntroduceFactoryAvailable

public static boolean isIntroduceFactoryAvailable(final JavaTextSelection selection)
    throws JavaModelException {
  final IJavaElement[] elements = selection.resolveElementAtOffset();
  if (elements.length == 1 && elements[0] instanceof IMethod)
    return isIntroduceFactoryAvailable((IMethod) elements[0]);

  // there's no IMethod for the default constructor
  if (!Checks.isAvailable(selection.resolveEnclosingElement())) return false;
  ASTNode node = selection.resolveCoveringNode();
  if (node == null) {
    ASTNode[] selectedNodes = selection.resolveSelectedNodes();
    if (selectedNodes != null && selectedNodes.length == 1) {
      node = selectedNodes[0];
      if (node == null) return false;
    } else {
      return false;
    }
  }

  if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) return true;

  node = ASTNodes.getNormalizedNode(node);
  if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) return true;

  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:RefactoringAvailabilityTester.java

示例2: getTargetNode

/**
 * Finds and returns the <code>ASTNode</code> for the given source text selection, if it is an
 * entire constructor call or the class name portion of a constructor call or constructor
 * declaration, or null otherwise.
 *
 * @param unit The compilation unit in which the selection was made
 * @param offset The textual offset of the start of the selection
 * @param length The length of the selection in characters
 * @return ClassInstanceCreation or MethodDeclaration
 */
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
  ASTNode node = ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
  if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) return node;
  if (node.getNodeType() == ASTNode.METHOD_DECLARATION
      && ((MethodDeclaration) node).isConstructor()) return node;
  // we have some sub node. Make sure its the right child of the parent
  StructuralPropertyDescriptor location = node.getLocationInParent();
  ASTNode parent = node.getParent();
  if (location == ClassInstanceCreation.TYPE_PROPERTY) {
    return parent;
  } else if (location == MethodDeclaration.NAME_PROPERTY
      && ((MethodDeclaration) parent).isConstructor()) {
    return parent;
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:IntroduceFactoryRefactoring.java

示例3: resolveBinding

private static IBinding resolveBinding(ASTNode node) {
  if (node instanceof SimpleName) {
    SimpleName simpleName = (SimpleName) node;
    // workaround for https://bugs.eclipse.org/62605 (constructor name resolves to type, not
    // method)
    ASTNode normalized = ASTNodes.getNormalizedNode(simpleName);
    if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
      ClassInstanceCreation cic = (ClassInstanceCreation) normalized.getParent();
      IMethodBinding constructorBinding = cic.resolveConstructorBinding();
      if (constructorBinding == null) return null;
      ITypeBinding declaringClass = constructorBinding.getDeclaringClass();
      if (!declaringClass.isAnonymous()) return constructorBinding;
      ITypeBinding superTypeDeclaration = declaringClass.getSuperclass().getTypeDeclaration();
      return resolveSuperclassConstructor(superTypeDeclaration, constructorBinding);
    }
    return simpleName.resolveBinding();

  } else if (node instanceof SuperConstructorInvocation) {
    return ((SuperConstructorInvocation) node).resolveConstructorBinding();
  } else if (node instanceof ConstructorInvocation) {
    return ((ConstructorInvocation) node).resolveConstructorBinding();
  } else {
    return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:JavadocFinder.java

示例4: getTargetNode

/**
 * Finds and returns the <code>ASTNode</code> for the given source text
 * selection, if it is an entire constructor call or the class name portion
 * of a constructor call or constructor declaration, or null otherwise.
 * @param unit The compilation unit in which the selection was made
 * @param offset The textual offset of the start of the selection
 * @param length The length of the selection in characters
 * @return ClassInstanceCreation or MethodDeclaration
 */
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
	ASTNode node= ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
	if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
		return node;
	if (node.getNodeType() == ASTNode.METHOD_DECLARATION && ((MethodDeclaration)node).isConstructor())
		return node;
	// we have some sub node. Make sure its the right child of the parent
	StructuralPropertyDescriptor location= node.getLocationInParent();
	ASTNode parent= node.getParent();
	if (location == ClassInstanceCreation.TYPE_PROPERTY) {
		return parent;
	} else if (location == MethodDeclaration.NAME_PROPERTY && ((MethodDeclaration)parent).isConstructor()) {
		return parent;
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:IntroduceFactoryRefactoring.java

示例5: resolveBinding

private static IBinding resolveBinding(ASTNode node) {
	if (node instanceof SimpleName) {
		SimpleName simpleName= (SimpleName) node;
		// workaround for https://bugs.eclipse.org/62605 (constructor name resolves to type, not method)
		ASTNode normalized= ASTNodes.getNormalizedNode(simpleName);
		if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
			ClassInstanceCreation cic= (ClassInstanceCreation) normalized.getParent();
			IMethodBinding constructorBinding= cic.resolveConstructorBinding();
			if (constructorBinding == null)
				return null;
			ITypeBinding declaringClass= constructorBinding.getDeclaringClass();
			if (!declaringClass.isAnonymous())
				return constructorBinding;
			ITypeBinding superTypeDeclaration= declaringClass.getSuperclass().getTypeDeclaration();
			return resolveSuperclassConstructor(superTypeDeclaration, constructorBinding);
		}
		return simpleName.resolveBinding();
		
	} else if (node instanceof SuperConstructorInvocation) {
		return ((SuperConstructorInvocation) node).resolveConstructorBinding();
	} else if (node instanceof ConstructorInvocation) {
		return ((ConstructorInvocation) node).resolveConstructorBinding();
	} else {
		return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:JavadocHover.java

示例6: getMethodBinding

/**
 * Extracts the method binding from the token's simple name. The method
 * binding is either the token's binding (if the parent of token is a
 * method call or declaration) or the constructor binding of a class
 * instance creation if the node is the type name of a class instance
 * creation.
 *
 * @param token the token to extract the method binding from
 * @return the corresponding method binding, or <code>null</code>
 */
private IBinding getMethodBinding(SemanticToken token) {
	IBinding binding= null;
	// work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
	ASTNode node= token.getNode();
	ASTNode parent= node.getParent();
	while (isTypePath(node, parent)) {
		node= parent;
		parent= parent.getParent();
	}

	if (parent != null && node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
		binding= ((ClassInstanceCreation) parent).resolveConstructorBinding();
	else
		binding= token.getBinding();
	return binding;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:26,代码来源:SemanticHighlightings.java

示例7: getBinding

/**
 * Extracts the binding from the token's simple name. Works around bug 62605 to return the correct
 * constructor binding in a ClassInstanceCreation.
 *
 * @param token the token to extract the binding from
 * @return the token's binding, or <code>null</code>
 */
private static IBinding getBinding(SemanticToken token) {
  ASTNode node = token.getNode();
  ASTNode normalized = ASTNodes.getNormalizedNode(node);
  if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
    // work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
    return ((ClassInstanceCreation) normalized.getParent()).resolveConstructorBinding();
  }
  return token.getBinding();
}
 
开发者ID:eclipse,项目名称:che,代码行数:16,代码来源:SemanticHighlightings.java

示例8: isIntroduceFactoryAvailable

public static boolean isIntroduceFactoryAvailable(final JavaTextSelection selection) throws JavaModelException {
	final IJavaElement[] elements= selection.resolveElementAtOffset();
	if (elements.length == 1 && elements[0] instanceof IMethod)
		return isIntroduceFactoryAvailable((IMethod) elements[0]);

	// there's no IMethod for the default constructor
	if (!Checks.isAvailable(selection.resolveEnclosingElement()))
		return false;
	ASTNode node= selection.resolveCoveringNode();
	if (node == null) {
		ASTNode[] selectedNodes= selection.resolveSelectedNodes();
		if (selectedNodes != null && selectedNodes.length == 1) {
			node= selectedNodes[0];
			if (node == null)
				return false;
		} else {
			return false;
		}
	}

	if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
		return true;

	node= ASTNodes.getNormalizedNode(node);
	if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
		return true;

	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:RefactoringAvailabilityTester.java

示例9: getBinding

/**
 * Extracts the binding from the token's simple name.
 * Works around bug 62605 to return the correct constructor binding in a ClassInstanceCreation.
 *
 * @param token the token to extract the binding from
 * @return the token's binding, or <code>null</code>
 */
private static IBinding getBinding(SemanticToken token) {
	ASTNode node= token.getNode();
	ASTNode normalized= ASTNodes.getNormalizedNode(node);
	if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
		// work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
		return ((ClassInstanceCreation) normalized.getParent()).resolveConstructorBinding();
	}
	return token.getBinding();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:SemanticHighlightings.java

示例10: getConstructorBindingIfAvailable

/**
 * Checks whether the given name belongs to a {@link ClassInstanceCreation} and if so, returns
 * its constructor binding.
 * 
 * @param nameNode the name node
 * @return the constructor binding or <code>null</code> if not found
 * @since 3.7
 */
private IBinding getConstructorBindingIfAvailable(Name nameNode) {
	ASTNode type= ASTNodes.getNormalizedNode(nameNode);
	StructuralPropertyDescriptor loc= type.getLocationInParent();
	if (loc == ClassInstanceCreation.TYPE_PROPERTY) {
		return ((ClassInstanceCreation) type.getParent()).resolveConstructorBinding();
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:CopyQualifiedNameAction.java

示例11: getConstructorBindingIfAvailable

/**
 * Checks whether the given name belongs to a {@link ClassInstanceCreation} and if so, returns
 * its constructor binding.
 * 
 * @param nameNode the name node
 * @return the constructor binding or <code>null</code> if not found
 * @since 3.7
 */
private IBinding getConstructorBindingIfAvailable(Name nameNode) {
	StructuralPropertyDescriptor loc= nameNode.getLocationInParent();
	if (loc == SimpleType.NAME_PROPERTY) {
		ASTNode parent= nameNode.getParent();
		loc= parent.getLocationInParent();
		if (loc == ClassInstanceCreation.TYPE_PROPERTY)
			return ((ClassInstanceCreation)parent.getParent()).resolveConstructorBinding();
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:18,代码来源:CopyQualifiedNameAction.java

示例12: resolveBinding

private static IBinding resolveBinding(ASTNode node) {
	if (node instanceof SimpleName) {
		// workaround for https://bugs.eclipse.org/62605 (constructor name resolves to type, not method)
		SimpleName simpleName= (SimpleName) node;
		StructuralPropertyDescriptor loc= simpleName.getLocationInParent();
		while (loc == QualifiedType.NAME_PROPERTY || loc == QualifiedName.NAME_PROPERTY|| loc == SimpleType.NAME_PROPERTY || loc == ParameterizedType.TYPE_PROPERTY) {
			node= node.getParent();
			loc= node.getLocationInParent();
		}
		if (loc == ClassInstanceCreation.TYPE_PROPERTY) {
			ClassInstanceCreation cic= (ClassInstanceCreation) node.getParent();
			IMethodBinding constructorBinding= cic.resolveConstructorBinding();
			if (constructorBinding == null)
				return null;
			ITypeBinding declaringClass= constructorBinding.getDeclaringClass();
			if (!declaringClass.isAnonymous())
				return constructorBinding;
			ITypeBinding superTypeDeclaration= declaringClass.getSuperclass().getTypeDeclaration();
			return resolveSuperclassConstructor(superTypeDeclaration, constructorBinding);
		}
		return simpleName.resolveBinding();
		
	} else if (node instanceof SuperConstructorInvocation) {
		return ((SuperConstructorInvocation) node).resolveConstructorBinding();
	} else if (node instanceof ConstructorInvocation) {
		return ((ConstructorInvocation) node).resolveConstructorBinding();
	} else {
		return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:30,代码来源:JavadocHover.java

示例13: checkSelection

private RefactoringStatus checkSelection(IProgressMonitor pm) throws JavaModelException {
  try {
    pm.beginTask("", 8); // $NON-NLS-1$

    IExpressionFragment selectedExpression = getSelectedExpression();

    if (selectedExpression == null) {
      String message = RefactoringCoreMessages.ExtractTempRefactoring_select_expression;
      return CodeRefactoringUtil.checkMethodSyntaxErrors(
          fSelectionStart, fSelectionLength, fCompilationUnitNode, message);
    }
    pm.worked(1);

    if (isUsedInExplicitConstructorCall())
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ExtractTempRefactoring_explicit_constructor);
    pm.worked(1);

    ASTNode associatedNode = selectedExpression.getAssociatedNode();
    if (getEnclosingBodyNode() == null
        || ASTNodes.getParent(associatedNode, Annotation.class) != null)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ExtractTempRefactoring_expr_in_method_or_initializer);
    pm.worked(1);

    if (associatedNode instanceof Name
        && associatedNode.getParent() instanceof ClassInstanceCreation
        && associatedNode.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ExtractTempRefactoring_name_in_new);
    pm.worked(1);

    RefactoringStatus result = new RefactoringStatus();
    result.merge(checkExpression());
    if (result.hasFatalError()) return result;
    pm.worked(1);

    result.merge(checkExpressionFragmentIsRValue());
    if (result.hasFatalError()) return result;
    pm.worked(1);

    if (isUsedInForInitializerOrUpdater(getSelectedExpression().getAssociatedExpression()))
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ExtractTempRefactoring_for_initializer_updater);
    pm.worked(1);

    if (isReferringToLocalVariableFromFor(getSelectedExpression().getAssociatedExpression()))
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ExtractTempRefactoring_refers_to_for_variable);
    pm.worked(1);

    return result;
  } finally {
    pm.done();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:56,代码来源:ExtractTempRefactoring.java

示例14: checkSelection

private RefactoringStatus checkSelection(IProgressMonitor pm) throws JavaModelException {
	try {
		pm.beginTask("", 8); //$NON-NLS-1$

		IExpressionFragment selectedExpression= getSelectedExpression();

		if (selectedExpression == null) {
			String message= RefactoringCoreMessages.ExtractTempRefactoring_select_expression;
			return CodeRefactoringUtil.checkMethodSyntaxErrors(fSelectionStart, fSelectionLength, fCompilationUnitNode, message);
		}
		pm.worked(1);

		if (isUsedInExplicitConstructorCall())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_explicit_constructor);
		pm.worked(1);

		ASTNode associatedNode= selectedExpression.getAssociatedNode();
		if (getEnclosingBodyNode() == null || ASTNodes.getParent(associatedNode, Annotation.class) != null)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_expr_in_method_or_initializer);
		pm.worked(1);

		if (associatedNode instanceof Name && associatedNode.getParent() instanceof ClassInstanceCreation && associatedNode.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_name_in_new);
		pm.worked(1);

		RefactoringStatus result= new RefactoringStatus();
		result.merge(checkExpression());
		if (result.hasFatalError())
			return result;
		pm.worked(1);

		result.merge(checkExpressionFragmentIsRValue());
		if (result.hasFatalError())
			return result;
		pm.worked(1);

		if (isUsedInForInitializerOrUpdater(getSelectedExpression().getAssociatedExpression()))
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_for_initializer_updater);
		pm.worked(1);

		if (isReferringToLocalVariableFromFor(getSelectedExpression().getAssociatedExpression()))
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_refers_to_for_variable);
		pm.worked(1);

		return result;
	} finally {
		pm.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:49,代码来源:ExtractTempRefactoring.java

示例15: addTypeArgumentsFromContext

private static void addTypeArgumentsFromContext(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	// similar to UnresolvedElementsSubProcessor.getTypeProposals(context, problem, proposals);
	
	ICompilationUnit cu= context.getCompilationUnit();

	CompilationUnit root= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(root);
	if (selectedNode == null) {
		return;
	}

	while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
		selectedNode= selectedNode.getParent();
	}

	Name node= null;
	if (selectedNode instanceof SimpleType) {
		node= ((SimpleType) selectedNode).getName();
	} else if (selectedNode instanceof NameQualifiedType) {
		node= ((NameQualifiedType) selectedNode).getName();
	} else if (selectedNode instanceof ArrayType) {
		Type elementType= ((ArrayType) selectedNode).getElementType();
		if (elementType.isSimpleType()) {
			node= ((SimpleType) elementType).getName();
		} else if (elementType.isNameQualifiedType()) {
			node= ((NameQualifiedType) elementType).getName();
		} else {
			return;
		}
	} else if (selectedNode instanceof Name) {
		node= (Name) selectedNode;
	} else {
		return;
	}

	// try to resolve type in context
	ITypeBinding binding= ASTResolving.guessBindingForTypeReference(node);
	if (binding != null) {
		ASTNode parent= node.getParent();
		if (parent instanceof Type && parent.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY && binding.isInterface()) { //bug 351853
			return;
		}
		ITypeBinding simpleBinding= binding;
		if (simpleBinding.isArray()) {
			simpleBinding= simpleBinding.getElementType();
		}
		simpleBinding= simpleBinding.getTypeDeclaration();
	
		if (!simpleBinding.isRecovered()) {
			if (binding.isParameterizedType() && (node.getParent() instanceof SimpleType || node.getParent() instanceof NameQualifiedType) && !(node.getParent().getParent() instanceof Type)) {
				proposals.add(UnresolvedElementsSubProcessor.createTypeRefChangeFullProposal(cu, binding, node, IProposalRelevance.TYPE_ARGUMENTS_FROM_CONTEXT));
			}
		}
	} else {
		ASTNode normalizedNode= ASTNodes.getNormalizedNode(node);
		if (!(normalizedNode.getParent() instanceof Type) && node.getParent() != normalizedNode) {
			ITypeBinding normBinding= ASTResolving.guessBindingForTypeReference(normalizedNode);
			if (normBinding != null && !normBinding.isRecovered()) {
				proposals.add(UnresolvedElementsSubProcessor.createTypeRefChangeFullProposal(cu, normBinding, normalizedNode, IProposalRelevance.TYPE_ARGUMENTS_FROM_CONTEXT));
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:63,代码来源:LocalCorrectionsSubProcessor.java


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