List of usage examples for org.eclipse.jdt.core.dom ClassInstanceCreation TYPE_PROPERTY
ChildPropertyDescriptor TYPE_PROPERTY
To view the source code for org.eclipse.jdt.core.dom ClassInstanceCreation TYPE_PROPERTY.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.JavadocFinder.java
License:Open Source License
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); }// w w w . j a v a 2 s. c om return simpleName.resolveBinding(); } else if (node instanceof SuperConstructorInvocation) { return ((SuperConstructorInvocation) node).resolveConstructorBinding(); } else if (node instanceof ConstructorInvocation) { return ((ConstructorInvocation) node).resolveConstructorBinding(); } else { return null; } }
From source file:cz.vutbr.fit.xhriba01.bc.jdt.ui.javaeditor.SemanticHighlightings.java
License:Open Source License
/** * 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> */// w ww . j av a2 s . c o m 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(); }
From source file:nz.ac.massey.cs.care.refactoring.executers.IntroduceFactoryRefactoring.java
License:Open Source License
/** * 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 *//*from w ww. j a v a2 s . c o m*/ 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; if (node.getNodeType() == ASTNode.BLOCK) { ClassInstanceCreation cic = getClassInstanceCreation(node); return cic; } // 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; }
From source file:org.eclipse.objectteams.otdt.debug.ui.internal.actions.OTToggleBreakpointAdapter.java
License:Open Source License
/** * Returns the binary name for the {@link IType} derived from its {@link ITypeBinding}. * <br><br>//from w w w . j a v a 2 s. co m * If the {@link ITypeBinding} cannot be derived this method falls back to calling * {@link #createQualifiedTypeName(IType)} to try and compose the type name. * @param type * @return the binary name for the given {@link IType} * @since 3.6 */ String getQualifiedName(IType type) throws JavaModelException { IJavaProject project = type.getJavaProject(); if (project != null && project.isOnClasspath(type) && needsBindings(type)) { CompilationUnit cuNode = parseCompilationUnit(type.getTypeRoot()); ISourceRange nameRange = type.getNameRange(); if (SourceRange.isAvailable(nameRange)) { ASTNode node = NodeFinder.perform(cuNode, nameRange); if (node instanceof SimpleName) { IBinding binding; if (node.getLocationInParent() == SimpleType.NAME_PROPERTY && node.getParent().getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) { binding = ((ClassInstanceCreation) node.getParent().getParent()).resolveTypeBinding(); } else { binding = ((SimpleName) node).resolveBinding(); } if (binding instanceof ITypeBinding) { String name = ((ITypeBinding) binding).getBinaryName(); if (name != null) { return name; } } } } } return createQualifiedTypeName(type); }
From source file:org.eclipse.scout.sdk.saml.importer.internal.jdt.imports.ScopeAnalyzer.java
License:Open Source License
private static ITypeBinding getQualifier(SimpleName selector) { ASTNode parent = selector.getParent(); switch (parent.getNodeType()) { case ASTNode.METHOD_INVOCATION: MethodInvocation decl = (MethodInvocation) parent; if (selector == decl.getName()) { return getBinding(decl.getExpression()); }//from w ww .j av a2 s . c o m return null; case ASTNode.QUALIFIED_NAME: QualifiedName qualifiedName = (QualifiedName) parent; if (selector == qualifiedName.getName()) { return getBinding(qualifiedName.getQualifier()); } return null; case ASTNode.FIELD_ACCESS: FieldAccess fieldAccess = (FieldAccess) parent; if (selector == fieldAccess.getName()) { return getBinding(fieldAccess.getExpression()); } return null; case ASTNode.SUPER_FIELD_ACCESS: { ITypeBinding curr = OrganizeImportsHelper.getBindingOfParentType(parent); return curr.getSuperclass(); } case ASTNode.SUPER_METHOD_INVOCATION: { SuperMethodInvocation superInv = (SuperMethodInvocation) parent; if (selector == superInv.getName()) { ITypeBinding curr = OrganizeImportsHelper.getBindingOfParentType(parent); return curr.getSuperclass(); } return null; } default: if (parent instanceof Type) { // bug 67644: in 'a.new X()', all member types of A are visible as location of X. ASTNode normalizedNode = OrganizeImportsHelper.getNormalizedNode(parent); if (normalizedNode.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) { ClassInstanceCreation creation = (ClassInstanceCreation) normalizedNode.getParent(); return getBinding(creation.getExpression()); } } return null; } }
From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java
License:Open Source License
/** * @param typeName/*w w w.j a v a2s . c o m*/ * the fully qualified type name. * * @return the {@link TypeDeclaration} with given fully qualified name, or <code>null</code> if * not found. */ public static TypeDeclaration getTypeByQualifiedName(CompilationUnit compilationUnit, final String typeName) { Assert.isNotNull(compilationUnit); Assert.isNotNull(typeName); final TypeDeclaration[] typeDeclaration = new TypeDeclaration[1]; compilationUnit.accept(new ASTVisitor() { @Override public void postVisit(ASTNode node) { if (typeDeclaration[0] == null) { if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY && ((ClassInstanceCreation) node.getParent()).getAnonymousClassDeclaration() != null) { ClassInstanceCreation creation = (ClassInstanceCreation) node.getParent(); String _typeName = getFullyQualifiedName(creation, true); if (_typeName.equals(typeName)) { AnonymousClassDeclaration anonymousClassDeclaration = creation .getAnonymousClassDeclaration(); typeDeclaration[0] = AnonymousTypeDeclaration.create(anonymousClassDeclaration); } } } } @Override public boolean visit(SimpleName node) { if (typeDeclaration[0] == null) { if (node.getLocationInParent() == TypeDeclaration.NAME_PROPERTY) { String _typeName = getFullyQualifiedName(node, true); if (_typeName.equals(typeName)) { typeDeclaration[0] = (TypeDeclaration) node.getParent(); } } } return typeDeclaration[0] == null; } }); // OK, return found TypeDeclaration return typeDeclaration[0]; }
From source file:org.eclipselabs.javainterpreter.ExpressionVisitor.java
License:Open Source License
private Object resolve(ClassInstanceCreation node) { Type type = (Type) node.getStructuralProperty(ClassInstanceCreation.TYPE_PROPERTY); Class<?> clazz = loadClass(type); Object[] args = argsTable.get(node).toArray(); Constructor<?> c = match(clazz, args); if (c != null) { try {/*from ww w . j a va 2s . c o m*/ c.setAccessible(true); return c.newInstance(args); } catch (Exception e) { e.printStackTrace(); } } throw new IllegalArgumentException("Constructor not found"); }
From source file:org.moe.natjgen.MethodEditor.java
License:Apache License
@SuppressWarnings("unchecked") public void setBodyAsProtocolDefaultMethod(Type rettype) { Block code = (Block) getRewrite().get(methodDecl, MethodDeclaration.BODY_PROPERTY); if (code == null) { code = getAST().newBlock();/*from www. ja va2 s . c om*/ getRewrite().set(methodDecl, MethodDeclaration.BODY_PROPERTY, code, getEditGroup()); } ListRewrite statements = getRewrite().getListRewrite(code, Block.STATEMENTS_PROPERTY); for (ASTNode object : (List<ASTNode>) statements.getRewrittenList()) { statements.remove(object, getEditGroup()); } Name uoe = getAST().newName("java.lang.UnsupportedOperationException"); SimpleType uoet = getAST().newSimpleType(uoe); ClassInstanceCreation cic = getAST().newClassInstanceCreation(); getRewrite().set(cic, ClassInstanceCreation.TYPE_PROPERTY, uoet, getEditGroup()); ThrowStatement th = getAST().newThrowStatement(); getRewrite().set(th, ThrowStatement.EXPRESSION_PROPERTY, cic, getEditGroup()); statements.insertLast(th, getEditGroup()); }