List of usage examples for org.eclipse.jdt.core.dom ASTNode CLASS_INSTANCE_CREATION
int CLASS_INSTANCE_CREATION
To view the source code for org.eclipse.jdt.core.dom ASTNode CLASS_INSTANCE_CREATION.
Click Source Link
ClassInstanceCreation
. From source file:ca.mcgill.cs.swevo.ppa.PPAIndexer.java
License:Open Source License
private void initStrategies() { strategies.put(FIELD_TYPE, new FieldInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.ASSIGNMENT, new AssignInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.QUALIFIED_NAME, new QNameInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.RETURN_STATEMENT, new ReturnInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.VARIABLE_DECLARATION_FRAGMENT, new VariableDeclarationInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.METHOD_INVOCATION, new MethodInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.SUPER_METHOD_INVOCATION, new MethodInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.FOR_STATEMENT, new ConditionInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.WHILE_STATEMENT, new ConditionInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.DO_STATEMENT, new ConditionInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.IF_STATEMENT, new ConditionInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.INFIX_EXPRESSION, new BinaryInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.ARRAY_ACCESS, new ArrayAccessInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.PREFIX_EXPRESSION, new PrefixInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.POSTFIX_EXPRESSION, new PostfixInferenceStrategy(this, ppaEngine)); strategies.put(ASTNode.CLASS_INSTANCE_CREATION, new ConstructorInferenceStrategy(this, ppaEngine)); }
From source file:ca.uvic.chisel.diver.sequencediagrams.sc.java.model.JavaActivation.java
License:Open Source License
@Override public List<JavaMessage> getMessages() { if (this.messages == null) { this.messages = new ArrayList<JavaMessage>(); if (getAST() == null) { return messages; }//w w w .j av a 2 s .co m MessageFinder finder = new MessageFinder(); getAST().accept(finder); for (ASTNode node : finder.messages) { IMethodBinding binding = null; switch (node.getNodeType()) { case ASTNode.METHOD_INVOCATION: binding = ((MethodInvocation) node).resolveMethodBinding(); break; case ASTNode.SUPER_METHOD_INVOCATION: binding = ((SuperMethodInvocation) node).resolveMethodBinding(); break; case ASTNode.CONSTRUCTOR_INVOCATION: binding = ((ConstructorInvocation) node).resolveConstructorBinding(); break; case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: binding = ((SuperConstructorInvocation) node).resolveConstructorBinding(); break; case ASTNode.CLASS_INSTANCE_CREATION: binding = ((ClassInstanceCreation) node).resolveConstructorBinding(); break; } if (binding != null) { IMethod target = (IMethod) binding.getJavaElement(); if (target != null) { JavaActivation targetActivation = new JavaActivation(tree, target); JavaMessage message = new JavaMessage(tree, node, this, targetActivation); //add catches targetActivation.setCallingMessage(message); message.setTries(finder.invocationTries.get(node)); messages.add(message); } } else if (node instanceof ThrowStatement) { ThrowStatement statement = (ThrowStatement) node; List<IType> throwns = finder.thrownTypes.get(statement); for (IType thrown : throwns) { JavaMessage parentMessage = getCallingMessage(); IJavaActivation root = this; JavaMessage message = null; while (parentMessage != null) { root = parentMessage.getSource(); if (parentMessage.catches(thrown)) { break; } parentMessage = root.getCallingMessage(); } if (root != null && root != this) { message = new JavaMessage(tree, statement, this, root); message.setType(thrown); message.setException(true); messages.add(message); } } } else if (node instanceof ReturnStatement) { if (getCallingMessage() != null) { JavaMessage message = new JavaMessage(tree, node, this, getCallingMessage().getSource()); IJavaProject project = getJavaElement().getJavaProject(); if (project != null) { String returnType; try { returnType = ((IMethod) getJavaElement()).getReturnType(); if (returnType != null) { message.setType(returnType); } } catch (JavaModelException e) { } } messages.add(message); } } } } return messages; }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.DOMFinder.java
License:Open Source License
public boolean visit(AnonymousClassDeclaration node) { ASTNode name;//from w w w. ja v a 2s .com ASTNode parent = node.getParent(); switch (parent.getNodeType()) { case ASTNode.CLASS_INSTANCE_CREATION: name = ((ClassInstanceCreation) parent).getType(); if (name.getNodeType() == ASTNode.PARAMETERIZED_TYPE) { name = ((ParameterizedType) name).getType(); } break; case ASTNode.ENUM_CONSTANT_DECLARATION: name = ((EnumConstantDeclaration) parent).getName(); break; default: return true; } if (found(node, name) && this.resolveBinding) this.foundBinding = node.resolveBinding(); return true; }
From source file:com.google.devtools.j2objc.ast.TreeConverter.java
License:Apache License
public static TreeNode convertInner(ASTNode jdtNode) { switch (jdtNode.getNodeType()) { case ASTNode.ANNOTATION_TYPE_DECLARATION: return new AnnotationTypeDeclaration((org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) jdtNode); case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: return new AnnotationTypeMemberDeclaration( (org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) jdtNode); case ASTNode.ANONYMOUS_CLASS_DECLARATION: return new AnonymousClassDeclaration((org.eclipse.jdt.core.dom.AnonymousClassDeclaration) jdtNode); case ASTNode.ARRAY_ACCESS: return new ArrayAccess((org.eclipse.jdt.core.dom.ArrayAccess) jdtNode); case ASTNode.ARRAY_CREATION: return new ArrayCreation((org.eclipse.jdt.core.dom.ArrayCreation) jdtNode); case ASTNode.ARRAY_INITIALIZER: return new ArrayInitializer((org.eclipse.jdt.core.dom.ArrayInitializer) jdtNode); case ASTNode.ARRAY_TYPE: return new ArrayType((org.eclipse.jdt.core.dom.ArrayType) jdtNode); case ASTNode.ASSERT_STATEMENT: return new AssertStatement((org.eclipse.jdt.core.dom.AssertStatement) jdtNode); case ASTNode.ASSIGNMENT: return new Assignment((org.eclipse.jdt.core.dom.Assignment) jdtNode); case ASTNode.BLOCK: return new Block((org.eclipse.jdt.core.dom.Block) jdtNode); case ASTNode.BLOCK_COMMENT: return new BlockComment((org.eclipse.jdt.core.dom.BlockComment) jdtNode); case ASTNode.BOOLEAN_LITERAL: return new BooleanLiteral((org.eclipse.jdt.core.dom.BooleanLiteral) jdtNode); case ASTNode.BREAK_STATEMENT: return new BreakStatement((org.eclipse.jdt.core.dom.BreakStatement) jdtNode); case ASTNode.CAST_EXPRESSION: return new CastExpression((org.eclipse.jdt.core.dom.CastExpression) jdtNode); case ASTNode.CATCH_CLAUSE: return new CatchClause((org.eclipse.jdt.core.dom.CatchClause) jdtNode); case ASTNode.CHARACTER_LITERAL: return new CharacterLiteral((org.eclipse.jdt.core.dom.CharacterLiteral) jdtNode); case ASTNode.CLASS_INSTANCE_CREATION: return new ClassInstanceCreation((org.eclipse.jdt.core.dom.ClassInstanceCreation) jdtNode); case ASTNode.CONDITIONAL_EXPRESSION: return new ConditionalExpression((org.eclipse.jdt.core.dom.ConditionalExpression) jdtNode); case ASTNode.CONSTRUCTOR_INVOCATION: return new ConstructorInvocation((org.eclipse.jdt.core.dom.ConstructorInvocation) jdtNode); case ASTNode.CONTINUE_STATEMENT: return new ContinueStatement((org.eclipse.jdt.core.dom.ContinueStatement) jdtNode); case ASTNode.DO_STATEMENT: return new DoStatement((org.eclipse.jdt.core.dom.DoStatement) jdtNode); case ASTNode.EMPTY_STATEMENT: return new EmptyStatement((org.eclipse.jdt.core.dom.EmptyStatement) jdtNode); case ASTNode.ENHANCED_FOR_STATEMENT: return new EnhancedForStatement((org.eclipse.jdt.core.dom.EnhancedForStatement) jdtNode); case ASTNode.ENUM_CONSTANT_DECLARATION: return new EnumConstantDeclaration((org.eclipse.jdt.core.dom.EnumConstantDeclaration) jdtNode); case ASTNode.ENUM_DECLARATION: return new EnumDeclaration((org.eclipse.jdt.core.dom.EnumDeclaration) jdtNode); case ASTNode.EXPRESSION_STATEMENT: return new ExpressionStatement((org.eclipse.jdt.core.dom.ExpressionStatement) jdtNode); case ASTNode.FIELD_ACCESS: return new FieldAccess((org.eclipse.jdt.core.dom.FieldAccess) jdtNode); case ASTNode.FIELD_DECLARATION: return new FieldDeclaration((org.eclipse.jdt.core.dom.FieldDeclaration) jdtNode); case ASTNode.FOR_STATEMENT: return new ForStatement((org.eclipse.jdt.core.dom.ForStatement) jdtNode); case ASTNode.IF_STATEMENT: return new IfStatement((org.eclipse.jdt.core.dom.IfStatement) jdtNode); case ASTNode.INFIX_EXPRESSION: return new InfixExpression((org.eclipse.jdt.core.dom.InfixExpression) jdtNode); case ASTNode.INITIALIZER: return new Initializer((org.eclipse.jdt.core.dom.Initializer) jdtNode); case ASTNode.INSTANCEOF_EXPRESSION: return new InstanceofExpression((org.eclipse.jdt.core.dom.InstanceofExpression) jdtNode); case ASTNode.JAVADOC: return new Javadoc((org.eclipse.jdt.core.dom.Javadoc) jdtNode); case ASTNode.LABELED_STATEMENT: return new LabeledStatement((org.eclipse.jdt.core.dom.LabeledStatement) jdtNode); case ASTNode.LINE_COMMENT: return new LineComment((org.eclipse.jdt.core.dom.LineComment) jdtNode); case ASTNode.MARKER_ANNOTATION: return new MarkerAnnotation((org.eclipse.jdt.core.dom.MarkerAnnotation) jdtNode); case ASTNode.MEMBER_VALUE_PAIR: return new MemberValuePair((org.eclipse.jdt.core.dom.MemberValuePair) jdtNode); case ASTNode.METHOD_DECLARATION: return new MethodDeclaration((org.eclipse.jdt.core.dom.MethodDeclaration) jdtNode); case ASTNode.METHOD_INVOCATION: return new MethodInvocation((org.eclipse.jdt.core.dom.MethodInvocation) jdtNode); case ASTNode.NORMAL_ANNOTATION: return new NormalAnnotation((org.eclipse.jdt.core.dom.NormalAnnotation) jdtNode); case ASTNode.NULL_LITERAL: return new NullLiteral((org.eclipse.jdt.core.dom.NullLiteral) jdtNode); case ASTNode.NUMBER_LITERAL: return new NumberLiteral((org.eclipse.jdt.core.dom.NumberLiteral) jdtNode); case ASTNode.PACKAGE_DECLARATION: return new PackageDeclaration((org.eclipse.jdt.core.dom.PackageDeclaration) jdtNode); case ASTNode.PARAMETERIZED_TYPE: return new ParameterizedType((org.eclipse.jdt.core.dom.ParameterizedType) jdtNode); case ASTNode.PARENTHESIZED_EXPRESSION: return new ParenthesizedExpression((org.eclipse.jdt.core.dom.ParenthesizedExpression) jdtNode); case ASTNode.POSTFIX_EXPRESSION: return new PostfixExpression((org.eclipse.jdt.core.dom.PostfixExpression) jdtNode); case ASTNode.PREFIX_EXPRESSION: return new PrefixExpression((org.eclipse.jdt.core.dom.PrefixExpression) jdtNode); case ASTNode.PRIMITIVE_TYPE: return new PrimitiveType((org.eclipse.jdt.core.dom.PrimitiveType) jdtNode); case ASTNode.QUALIFIED_NAME: return new QualifiedName((org.eclipse.jdt.core.dom.QualifiedName) jdtNode); case ASTNode.QUALIFIED_TYPE: return new QualifiedType((org.eclipse.jdt.core.dom.QualifiedType) jdtNode); case ASTNode.RETURN_STATEMENT: return new ReturnStatement((org.eclipse.jdt.core.dom.ReturnStatement) jdtNode); case ASTNode.SIMPLE_NAME: return new SimpleName((org.eclipse.jdt.core.dom.SimpleName) jdtNode); case ASTNode.SIMPLE_TYPE: return new SimpleType((org.eclipse.jdt.core.dom.SimpleType) jdtNode); case ASTNode.SINGLE_MEMBER_ANNOTATION: return new SingleMemberAnnotation((org.eclipse.jdt.core.dom.SingleMemberAnnotation) jdtNode); case ASTNode.SINGLE_VARIABLE_DECLARATION: return new SingleVariableDeclaration((org.eclipse.jdt.core.dom.SingleVariableDeclaration) jdtNode); case ASTNode.STRING_LITERAL: return new StringLiteral((org.eclipse.jdt.core.dom.StringLiteral) jdtNode); case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return new SuperConstructorInvocation((org.eclipse.jdt.core.dom.SuperConstructorInvocation) jdtNode); case ASTNode.SUPER_FIELD_ACCESS: return new SuperFieldAccess((org.eclipse.jdt.core.dom.SuperFieldAccess) jdtNode); case ASTNode.SUPER_METHOD_INVOCATION: return new SuperMethodInvocation((org.eclipse.jdt.core.dom.SuperMethodInvocation) jdtNode); case ASTNode.SWITCH_CASE: return new SwitchCase((org.eclipse.jdt.core.dom.SwitchCase) jdtNode); case ASTNode.SWITCH_STATEMENT: return new SwitchStatement((org.eclipse.jdt.core.dom.SwitchStatement) jdtNode); case ASTNode.SYNCHRONIZED_STATEMENT: return new SynchronizedStatement((org.eclipse.jdt.core.dom.SynchronizedStatement) jdtNode); case ASTNode.TAG_ELEMENT: return new TagElement((org.eclipse.jdt.core.dom.TagElement) jdtNode); case ASTNode.TEXT_ELEMENT: return new TextElement((org.eclipse.jdt.core.dom.TextElement) jdtNode); case ASTNode.THIS_EXPRESSION: return new ThisExpression((org.eclipse.jdt.core.dom.ThisExpression) jdtNode); case ASTNode.THROW_STATEMENT: return new ThrowStatement((org.eclipse.jdt.core.dom.ThrowStatement) jdtNode); case ASTNode.TRY_STATEMENT: return new TryStatement((org.eclipse.jdt.core.dom.TryStatement) jdtNode); case ASTNode.TYPE_DECLARATION: return new TypeDeclaration((org.eclipse.jdt.core.dom.TypeDeclaration) jdtNode); case ASTNode.TYPE_DECLARATION_STATEMENT: return new TypeDeclarationStatement((org.eclipse.jdt.core.dom.TypeDeclarationStatement) jdtNode); case ASTNode.TYPE_LITERAL: return new TypeLiteral((org.eclipse.jdt.core.dom.TypeLiteral) jdtNode); case ASTNode.UNION_TYPE: return new UnionType((org.eclipse.jdt.core.dom.UnionType) jdtNode); case ASTNode.VARIABLE_DECLARATION_EXPRESSION: return new VariableDeclarationExpression( (org.eclipse.jdt.core.dom.VariableDeclarationExpression) jdtNode); case ASTNode.VARIABLE_DECLARATION_FRAGMENT: return new VariableDeclarationFragment((org.eclipse.jdt.core.dom.VariableDeclarationFragment) jdtNode); case ASTNode.VARIABLE_DECLARATION_STATEMENT: return new VariableDeclarationStatement( (org.eclipse.jdt.core.dom.VariableDeclarationStatement) jdtNode); case ASTNode.WHILE_STATEMENT: return new WhileStatement((org.eclipse.jdt.core.dom.WhileStatement) jdtNode); // These nodes only appear in comments and J2ObjC doens't need any // information from their subtree so we just convert them to TextElement. case ASTNode.MEMBER_REF: case ASTNode.METHOD_REF: case ASTNode.METHOD_REF_PARAMETER: return new TextElement(jdtNode); case ASTNode.COMPILATION_UNIT: throw new AssertionError("CompilationUnit must be converted using convertCompilationUnit()"); default://from w w w . ja v a2s . co m throw new AssertionError("Unknown node type: " + jdtNode.getClass().getName()); } }
From source file:com.google.devtools.j2objc.jdt.TreeConverter.java
License:Apache License
private static TreeNode convertInner(ASTNode jdtNode) { switch (jdtNode.getNodeType()) { case ASTNode.ANNOTATION_TYPE_DECLARATION: return convertAnnotationTypeDeclaration((org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) jdtNode); case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: return convertAnnotationTypeMemberDeclaration( (org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) jdtNode); case ASTNode.ARRAY_ACCESS: return convertArrayAccess((org.eclipse.jdt.core.dom.ArrayAccess) jdtNode); case ASTNode.ARRAY_CREATION: return convertArrayCreation((org.eclipse.jdt.core.dom.ArrayCreation) jdtNode); case ASTNode.ARRAY_INITIALIZER: return convertArrayInitializer((org.eclipse.jdt.core.dom.ArrayInitializer) jdtNode); case ASTNode.ARRAY_TYPE: return convertArrayType((org.eclipse.jdt.core.dom.ArrayType) jdtNode); case ASTNode.ASSERT_STATEMENT: return convertAssertStatement((org.eclipse.jdt.core.dom.AssertStatement) jdtNode); case ASTNode.ASSIGNMENT: return convertAssignment((org.eclipse.jdt.core.dom.Assignment) jdtNode); case ASTNode.BLOCK: return convertBlock((org.eclipse.jdt.core.dom.Block) jdtNode); case ASTNode.BLOCK_COMMENT: return new BlockComment(); case ASTNode.BOOLEAN_LITERAL: return convertBooleanLiteral((org.eclipse.jdt.core.dom.BooleanLiteral) jdtNode); case ASTNode.BREAK_STATEMENT: return convertBreakStatement((org.eclipse.jdt.core.dom.BreakStatement) jdtNode); case ASTNode.CAST_EXPRESSION: return convertCastExpression((org.eclipse.jdt.core.dom.CastExpression) jdtNode); case ASTNode.CATCH_CLAUSE: return convertCatchClause((org.eclipse.jdt.core.dom.CatchClause) jdtNode); case ASTNode.CHARACTER_LITERAL: return convertCharacterLiteral((org.eclipse.jdt.core.dom.CharacterLiteral) jdtNode); case ASTNode.CLASS_INSTANCE_CREATION: return convertClassInstanceCreation((org.eclipse.jdt.core.dom.ClassInstanceCreation) jdtNode); case ASTNode.CONDITIONAL_EXPRESSION: return convertConditionalExpression((org.eclipse.jdt.core.dom.ConditionalExpression) jdtNode); case ASTNode.CONSTRUCTOR_INVOCATION: return convertConstructorInvocation((org.eclipse.jdt.core.dom.ConstructorInvocation) jdtNode); case ASTNode.CONTINUE_STATEMENT: return convertContinueStatement((org.eclipse.jdt.core.dom.ContinueStatement) jdtNode); case ASTNode.CREATION_REFERENCE: return convertCreationReference((org.eclipse.jdt.core.dom.CreationReference) jdtNode); case ASTNode.DIMENSION: return convertDimension((org.eclipse.jdt.core.dom.Dimension) jdtNode); case ASTNode.DO_STATEMENT: return convertDoStatement((org.eclipse.jdt.core.dom.DoStatement) jdtNode); case ASTNode.EMPTY_STATEMENT: return new EmptyStatement(); case ASTNode.ENHANCED_FOR_STATEMENT: return convertEnhancedForStatement((org.eclipse.jdt.core.dom.EnhancedForStatement) jdtNode); case ASTNode.ENUM_CONSTANT_DECLARATION: return convertEnumConstantDeclaration((org.eclipse.jdt.core.dom.EnumConstantDeclaration) jdtNode); case ASTNode.ENUM_DECLARATION: return convertEnumDeclaration((org.eclipse.jdt.core.dom.EnumDeclaration) jdtNode); case ASTNode.EXPRESSION_METHOD_REFERENCE: return convertExpressionMethodReference((org.eclipse.jdt.core.dom.ExpressionMethodReference) jdtNode); case ASTNode.EXPRESSION_STATEMENT: return convertExpressionStatement((org.eclipse.jdt.core.dom.ExpressionStatement) jdtNode); case ASTNode.FIELD_ACCESS: return convertFieldAccess((org.eclipse.jdt.core.dom.FieldAccess) jdtNode); case ASTNode.FIELD_DECLARATION: return convertFieldDeclaration((org.eclipse.jdt.core.dom.FieldDeclaration) jdtNode); case ASTNode.FOR_STATEMENT: return convertForStatement((org.eclipse.jdt.core.dom.ForStatement) jdtNode); case ASTNode.IF_STATEMENT: return convertIfStatement((org.eclipse.jdt.core.dom.IfStatement) jdtNode); case ASTNode.INFIX_EXPRESSION: return convertInfixExpression((org.eclipse.jdt.core.dom.InfixExpression) jdtNode); case ASTNode.INTERSECTION_TYPE: return convertIntersectionType((org.eclipse.jdt.core.dom.IntersectionType) jdtNode); case ASTNode.INITIALIZER: return convertInitializer((org.eclipse.jdt.core.dom.Initializer) jdtNode); case ASTNode.INSTANCEOF_EXPRESSION: return convertInstanceofExpression((org.eclipse.jdt.core.dom.InstanceofExpression) jdtNode); case ASTNode.JAVADOC: return convertJavadoc((org.eclipse.jdt.core.dom.Javadoc) jdtNode); case ASTNode.LABELED_STATEMENT: return convertLabeledStatement((org.eclipse.jdt.core.dom.LabeledStatement) jdtNode); case ASTNode.LAMBDA_EXPRESSION: return convertLambdaExpression((org.eclipse.jdt.core.dom.LambdaExpression) jdtNode); case ASTNode.LINE_COMMENT: return new LineComment(); case ASTNode.MARKER_ANNOTATION: return convertMarkerAnnotation((org.eclipse.jdt.core.dom.MarkerAnnotation) jdtNode); case ASTNode.MEMBER_VALUE_PAIR: return convertMemberValuePair((org.eclipse.jdt.core.dom.MemberValuePair) jdtNode); case ASTNode.METHOD_DECLARATION: return convertMethodDeclaration((org.eclipse.jdt.core.dom.MethodDeclaration) jdtNode); case ASTNode.METHOD_INVOCATION: return convertMethodInvocation((org.eclipse.jdt.core.dom.MethodInvocation) jdtNode); case ASTNode.NAME_QUALIFIED_TYPE: return convertNameQualifiedType((org.eclipse.jdt.core.dom.NameQualifiedType) jdtNode); case ASTNode.NORMAL_ANNOTATION: return convertNormalAnnotation((org.eclipse.jdt.core.dom.NormalAnnotation) jdtNode); case ASTNode.NULL_LITERAL: return new NullLiteral(BindingConverter.NULL_TYPE); case ASTNode.NUMBER_LITERAL: return convertNumberLiteral((org.eclipse.jdt.core.dom.NumberLiteral) jdtNode); case ASTNode.PACKAGE_DECLARATION: return convertPackageDeclaration((org.eclipse.jdt.core.dom.PackageDeclaration) jdtNode); case ASTNode.PARAMETERIZED_TYPE: return convertParameterizedType((org.eclipse.jdt.core.dom.ParameterizedType) jdtNode); case ASTNode.PARENTHESIZED_EXPRESSION: return convertParenthesizedExpression((org.eclipse.jdt.core.dom.ParenthesizedExpression) jdtNode); case ASTNode.POSTFIX_EXPRESSION: return convertPostfixExpression((org.eclipse.jdt.core.dom.PostfixExpression) jdtNode); case ASTNode.PREFIX_EXPRESSION: return convertPrefixExpression((org.eclipse.jdt.core.dom.PrefixExpression) jdtNode); case ASTNode.PRIMITIVE_TYPE: return convertPrimitiveType((org.eclipse.jdt.core.dom.PrimitiveType) jdtNode); case ASTNode.QUALIFIED_NAME: return convertQualifiedName((org.eclipse.jdt.core.dom.QualifiedName) jdtNode); case ASTNode.QUALIFIED_TYPE: return convertQualifiedType((org.eclipse.jdt.core.dom.QualifiedType) jdtNode); case ASTNode.RETURN_STATEMENT: return convertReturnStatement((org.eclipse.jdt.core.dom.ReturnStatement) jdtNode); case ASTNode.SIMPLE_NAME: return convertSimpleName((org.eclipse.jdt.core.dom.SimpleName) jdtNode); case ASTNode.SIMPLE_TYPE: return convertSimpleType((org.eclipse.jdt.core.dom.SimpleType) jdtNode); case ASTNode.SINGLE_MEMBER_ANNOTATION: return convertSingleMemberAnnotation((org.eclipse.jdt.core.dom.SingleMemberAnnotation) jdtNode); case ASTNode.SINGLE_VARIABLE_DECLARATION: return convertSingleVariableDeclaration((org.eclipse.jdt.core.dom.SingleVariableDeclaration) jdtNode); case ASTNode.STRING_LITERAL: return convertStringLiteral((org.eclipse.jdt.core.dom.StringLiteral) jdtNode); case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return convertSuperConstructorInvocation((org.eclipse.jdt.core.dom.SuperConstructorInvocation) jdtNode); case ASTNode.SUPER_FIELD_ACCESS: return convertSuperFieldAccess((org.eclipse.jdt.core.dom.SuperFieldAccess) jdtNode); case ASTNode.SUPER_METHOD_INVOCATION: return convertSuperMethodInvocation((org.eclipse.jdt.core.dom.SuperMethodInvocation) jdtNode); case ASTNode.SUPER_METHOD_REFERENCE: return convertSuperMethodReference((org.eclipse.jdt.core.dom.SuperMethodReference) jdtNode); case ASTNode.SWITCH_CASE: return convertSwitchCase((org.eclipse.jdt.core.dom.SwitchCase) jdtNode); case ASTNode.SWITCH_STATEMENT: return convertSwitchStatement((org.eclipse.jdt.core.dom.SwitchStatement) jdtNode); case ASTNode.SYNCHRONIZED_STATEMENT: return convertSynchronizedStatement((org.eclipse.jdt.core.dom.SynchronizedStatement) jdtNode); case ASTNode.TAG_ELEMENT: return convertTagElement((org.eclipse.jdt.core.dom.TagElement) jdtNode); case ASTNode.TEXT_ELEMENT: return convertTextElement(((org.eclipse.jdt.core.dom.TextElement) jdtNode).getText()); case ASTNode.THIS_EXPRESSION: return convertThisExpression((org.eclipse.jdt.core.dom.ThisExpression) jdtNode); case ASTNode.THROW_STATEMENT: return convertThrowStatement((org.eclipse.jdt.core.dom.ThrowStatement) jdtNode); case ASTNode.TRY_STATEMENT: return convertTryStatement((org.eclipse.jdt.core.dom.TryStatement) jdtNode); case ASTNode.TYPE_DECLARATION: return convertTypeDeclaration((org.eclipse.jdt.core.dom.TypeDeclaration) jdtNode); case ASTNode.TYPE_DECLARATION_STATEMENT: return convertTypeDeclarationStatement((org.eclipse.jdt.core.dom.TypeDeclarationStatement) jdtNode); case ASTNode.TYPE_LITERAL: return convertTypeLiteral((org.eclipse.jdt.core.dom.TypeLiteral) jdtNode); case ASTNode.TYPE_METHOD_REFERENCE: return convertTypeMethodReference((org.eclipse.jdt.core.dom.TypeMethodReference) jdtNode); case ASTNode.UNION_TYPE: return convertUnionType((org.eclipse.jdt.core.dom.UnionType) jdtNode); case ASTNode.VARIABLE_DECLARATION_EXPRESSION: return convertVariableDeclarationExpression( (org.eclipse.jdt.core.dom.VariableDeclarationExpression) jdtNode); case ASTNode.VARIABLE_DECLARATION_FRAGMENT: return convertVariableDeclarationFragment( (org.eclipse.jdt.core.dom.VariableDeclarationFragment) jdtNode); case ASTNode.VARIABLE_DECLARATION_STATEMENT: return convertVariableDeclarationStatement( (org.eclipse.jdt.core.dom.VariableDeclarationStatement) jdtNode); case ASTNode.WHILE_STATEMENT: return convertWhileStatement((org.eclipse.jdt.core.dom.WhileStatement) jdtNode); // These nodes only appear in comments and J2ObjC doens't need any // information from their subtree so we just convert them to TextElement. case ASTNode.MEMBER_REF: case ASTNode.METHOD_REF: case ASTNode.METHOD_REF_PARAMETER: return convertTextElement(jdtNode.toString()); case ASTNode.COMPILATION_UNIT: throw new AssertionError("CompilationUnit must be converted using convertCompilationUnit()"); default:/*www.j av a 2 s .c om*/ throw new AssertionError("Unknown node type: " + jdtNode.getClass().getName()); } }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** * Output a "." node./*from w w w. ja v a2 s . co m*/ * @param node0 the "." node */ void visitDot(Expression node0) { Expression node = node0; // collect a flattened list of "."-separated items // e.g. ImmutableList.builder().add(1).build() -> [ImmutableList, builder(), add(1), build()] ArrayDeque<Expression> stack = new ArrayDeque<>(); LOOP: do { stack.addFirst(node); switch (node.getNodeType()) { case ASTNode.FIELD_ACCESS: node = ((FieldAccess) node).getExpression(); break; case ASTNode.METHOD_INVOCATION: node = ((MethodInvocation) node).getExpression(); break; case ASTNode.QUALIFIED_NAME: node = ((QualifiedName) node).getQualifier(); break; case ASTNode.SIMPLE_NAME: node = null; break LOOP; default: // If the dot chain starts with a primary expression // (e.g. a class instance creation, or a conditional expression) // then remove it from the list and deal with it first. stack.removeFirst(); break LOOP; } } while (node != null); List<Expression> items = new ArrayList<>(stack); boolean needDot = false; // The dot chain started with a primary expression: output it normally, and indent // the rest of the chain +4. if (node != null) { // Exception: if it's an anonymous class declaration, we don't need to // break and indent after the trailing '}'. if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION && ((ClassInstanceCreation) node).getAnonymousClassDeclaration() != null) { builder.open(ZERO); node.accept(this); token("."); } else { builder.open(plusFour); node.accept(this); builder.breakOp(); needDot = true; } } // Check if the dot chain has a prefix that looks like a type name, so we can // treat the type name-shaped part as a single syntactic unit. int prefixIndex = TypeNameClassifier.typePrefixLength(simpleNames(stack)); int invocationCount = 0; int firstInvocationIndex = -1; { for (int i = 0; i < items.size(); i++) { Expression expression = items.get(i); if (expression.getNodeType() == ASTNode.METHOD_INVOCATION) { if (i > 0 || node != null) { // we only want dereference invocations invocationCount++; } if (firstInvocationIndex < 0) { firstInvocationIndex = i; } } } } // If there's only one invocation, treat leading field accesses as a single // unit. In the normal case we want to preserve the alignment of subsequent // method calls, and would emit e.g.: // // myField // .foo() // .bar(); // // But if there's no 'bar()' to worry about the alignment of we prefer: // // myField.foo(); // // to: // // myField // .foo(); // if (invocationCount == 1) { prefixIndex = firstInvocationIndex; } if (prefixIndex > 0) { visitDotWithPrefix(items, needDot, prefixIndex); } else { visitRegularDot(items, needDot); } if (node != null) { builder.close(); } }
From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void getConstructorProposals(IInvocationContext context, IProblemLocation problem, Map<String, Map> missingConstructorsMap) throws CoreException { ICompilationUnit cu = context.getCompilationUnit(); CompilationUnit astRoot = context.getASTRoot(); ASTNode selectedNode = problem.getCoveringNode(astRoot); if (selectedNode == null) { return;/*w w w . ja v a 2 s. c o m*/ } ITypeBinding targetBinding = null; List<Expression> arguments = null; IMethodBinding recursiveConstructor = null; int type = selectedNode.getNodeType(); if (type == ASTNode.CLASS_INSTANCE_CREATION) { ClassInstanceCreation creation = (ClassInstanceCreation) selectedNode; IBinding binding = creation.getType().resolveBinding(); if (binding instanceof ITypeBinding) { targetBinding = (ITypeBinding) binding; arguments = creation.arguments(); } } else if (type == ASTNode.SUPER_CONSTRUCTOR_INVOCATION) { ITypeBinding typeBinding = Bindings.getBindingOfParentType(selectedNode); if (typeBinding != null && !typeBinding.isAnonymous()) { targetBinding = typeBinding.getSuperclass(); arguments = ((SuperConstructorInvocation) selectedNode).arguments(); } } else if (type == ASTNode.CONSTRUCTOR_INVOCATION) { ITypeBinding typeBinding = Bindings.getBindingOfParentType(selectedNode); if (typeBinding != null && !typeBinding.isAnonymous()) { targetBinding = typeBinding; arguments = ((ConstructorInvocation) selectedNode).arguments(); recursiveConstructor = ASTResolving.findParentMethodDeclaration(selectedNode).resolveBinding(); } } if (targetBinding == null) { return; } IMethodBinding[] methods = targetBinding.getDeclaredMethods(); ArrayList<IMethodBinding> similarElements = new ArrayList<IMethodBinding>(); for (int i = 0; i < methods.length; i++) { IMethodBinding curr = methods[i]; if (curr.isConstructor() && recursiveConstructor != curr) { similarElements.add(curr); // similar elements can contain a implicit default constructor } } if (targetBinding.isFromSource()) { ITypeBinding targetDecl = targetBinding.getTypeDeclaration(); Map<String, LinkedCorrectionProposal> map = missingConstructorsMap.get(targetDecl.getQualifiedName()); if (map == null) return; ICompilationUnit targetCU = ASTResolving.findCompilationUnitForBinding(cu, astRoot, targetDecl); if (targetCU != null) { String arg = ASTResolving.getMethodSignature(ASTResolving.getTypeSignature(targetDecl), getParameterTypes(arguments), false); String label = Messages.format( CorrectionMessages.UnresolvedElementsSubProcessor_createconstructor_description, arg); Image image = JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC, JavaElementImageDescriptor.CONSTRUCTOR, JavaElementImageProvider.SMALL_SIZE); /** * Make sure constructor of a certain signature is created only once. */ String key = arg; map.put(key, new NewMethodCorrectionProposal(label, targetCU, selectedNode, arguments, targetDecl, IProposalRelevance.CREATE_CONSTRUCTOR, image)); } } }
From source file:com.j2swift.ast.TreeConverter.java
License:Apache License
public static TreeNode convertInner(ASTNode jdtNode) { switch (jdtNode.getNodeType()) { case ASTNode.ANNOTATION_TYPE_DECLARATION: return new AnnotationTypeDeclaration((org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) jdtNode); case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: return new AnnotationTypeMemberDeclaration( (org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) jdtNode); case ASTNode.ANONYMOUS_CLASS_DECLARATION: return new AnonymousClassDeclaration((org.eclipse.jdt.core.dom.AnonymousClassDeclaration) jdtNode); case ASTNode.ARRAY_ACCESS: return new ArrayAccess((org.eclipse.jdt.core.dom.ArrayAccess) jdtNode); case ASTNode.ARRAY_CREATION: return new ArrayCreation((org.eclipse.jdt.core.dom.ArrayCreation) jdtNode); case ASTNode.ARRAY_INITIALIZER: return new ArrayInitializer((org.eclipse.jdt.core.dom.ArrayInitializer) jdtNode); case ASTNode.ARRAY_TYPE: return new ArrayType((org.eclipse.jdt.core.dom.ArrayType) jdtNode); case ASTNode.ASSERT_STATEMENT: return new AssertStatement((org.eclipse.jdt.core.dom.AssertStatement) jdtNode); case ASTNode.ASSIGNMENT: return new Assignment((org.eclipse.jdt.core.dom.Assignment) jdtNode); case ASTNode.BLOCK: return new Block((org.eclipse.jdt.core.dom.Block) jdtNode); case ASTNode.BLOCK_COMMENT: return new BlockComment((org.eclipse.jdt.core.dom.BlockComment) jdtNode); case ASTNode.BOOLEAN_LITERAL: return new BooleanLiteral((org.eclipse.jdt.core.dom.BooleanLiteral) jdtNode); case ASTNode.BREAK_STATEMENT: return new BreakStatement((org.eclipse.jdt.core.dom.BreakStatement) jdtNode); case ASTNode.CAST_EXPRESSION: return new CastExpression((org.eclipse.jdt.core.dom.CastExpression) jdtNode); case ASTNode.CATCH_CLAUSE: return new CatchClause((org.eclipse.jdt.core.dom.CatchClause) jdtNode); case ASTNode.CHARACTER_LITERAL: return new CharacterLiteral((org.eclipse.jdt.core.dom.CharacterLiteral) jdtNode); case ASTNode.CLASS_INSTANCE_CREATION: return new ClassInstanceCreation((org.eclipse.jdt.core.dom.ClassInstanceCreation) jdtNode); case ASTNode.CONDITIONAL_EXPRESSION: return new ConditionalExpression((org.eclipse.jdt.core.dom.ConditionalExpression) jdtNode); case ASTNode.CONSTRUCTOR_INVOCATION: return new ConstructorInvocation((org.eclipse.jdt.core.dom.ConstructorInvocation) jdtNode); case ASTNode.CONTINUE_STATEMENT: return new ContinueStatement((org.eclipse.jdt.core.dom.ContinueStatement) jdtNode); case ASTNode.CREATION_REFERENCE: return new CreationReference((org.eclipse.jdt.core.dom.CreationReference) jdtNode); case ASTNode.DIMENSION: return new Dimension((org.eclipse.jdt.core.dom.Dimension) jdtNode); case ASTNode.DO_STATEMENT: return new DoStatement((org.eclipse.jdt.core.dom.DoStatement) jdtNode); case ASTNode.EMPTY_STATEMENT: return new EmptyStatement((org.eclipse.jdt.core.dom.EmptyStatement) jdtNode); case ASTNode.ENHANCED_FOR_STATEMENT: return new EnhancedForStatement((org.eclipse.jdt.core.dom.EnhancedForStatement) jdtNode); case ASTNode.ENUM_CONSTANT_DECLARATION: return new EnumConstantDeclaration((org.eclipse.jdt.core.dom.EnumConstantDeclaration) jdtNode); case ASTNode.ENUM_DECLARATION: return new EnumDeclaration((org.eclipse.jdt.core.dom.EnumDeclaration) jdtNode); case ASTNode.EXPRESSION_METHOD_REFERENCE: return new ExpressionMethodReference((org.eclipse.jdt.core.dom.ExpressionMethodReference) jdtNode); case ASTNode.EXPRESSION_STATEMENT: return new ExpressionStatement((org.eclipse.jdt.core.dom.ExpressionStatement) jdtNode); case ASTNode.FIELD_ACCESS: return new FieldAccess((org.eclipse.jdt.core.dom.FieldAccess) jdtNode); case ASTNode.FIELD_DECLARATION: return new FieldDeclaration((org.eclipse.jdt.core.dom.FieldDeclaration) jdtNode); case ASTNode.FOR_STATEMENT: return new ForStatement((org.eclipse.jdt.core.dom.ForStatement) jdtNode); case ASTNode.IF_STATEMENT: return new IfStatement((org.eclipse.jdt.core.dom.IfStatement) jdtNode); case ASTNode.INFIX_EXPRESSION: return new InfixExpression((org.eclipse.jdt.core.dom.InfixExpression) jdtNode); case ASTNode.INTERSECTION_TYPE: return new IntersectionType((org.eclipse.jdt.core.dom.IntersectionType) jdtNode); case ASTNode.INITIALIZER: return new Initializer((org.eclipse.jdt.core.dom.Initializer) jdtNode); case ASTNode.INSTANCEOF_EXPRESSION: return new InstanceofExpression((org.eclipse.jdt.core.dom.InstanceofExpression) jdtNode); case ASTNode.JAVADOC: return new Javadoc((org.eclipse.jdt.core.dom.Javadoc) jdtNode); case ASTNode.LABELED_STATEMENT: return new LabeledStatement((org.eclipse.jdt.core.dom.LabeledStatement) jdtNode); case ASTNode.LAMBDA_EXPRESSION: return new LambdaExpression((org.eclipse.jdt.core.dom.LambdaExpression) jdtNode); case ASTNode.LINE_COMMENT: return new LineComment((org.eclipse.jdt.core.dom.LineComment) jdtNode); case ASTNode.MARKER_ANNOTATION: return MarkerAnnotation.convert((org.eclipse.jdt.core.dom.MarkerAnnotation) jdtNode); case ASTNode.MEMBER_VALUE_PAIR: return new MemberValuePair((org.eclipse.jdt.core.dom.MemberValuePair) jdtNode); case ASTNode.METHOD_DECLARATION: return new MethodDeclaration((org.eclipse.jdt.core.dom.MethodDeclaration) jdtNode); case ASTNode.METHOD_INVOCATION: return new MethodInvocation((org.eclipse.jdt.core.dom.MethodInvocation) jdtNode); case ASTNode.NAME_QUALIFIED_TYPE: return new NameQualifiedType((org.eclipse.jdt.core.dom.NameQualifiedType) jdtNode); case ASTNode.NORMAL_ANNOTATION: return new NormalAnnotation((org.eclipse.jdt.core.dom.NormalAnnotation) jdtNode); case ASTNode.NULL_LITERAL: return new NullLiteral((org.eclipse.jdt.core.dom.NullLiteral) jdtNode); case ASTNode.NUMBER_LITERAL: return new NumberLiteral((org.eclipse.jdt.core.dom.NumberLiteral) jdtNode); case ASTNode.PACKAGE_DECLARATION: return new PackageDeclaration((org.eclipse.jdt.core.dom.PackageDeclaration) jdtNode); case ASTNode.PARAMETERIZED_TYPE: return new ParameterizedType((org.eclipse.jdt.core.dom.ParameterizedType) jdtNode); case ASTNode.PARENTHESIZED_EXPRESSION: return new ParenthesizedExpression((org.eclipse.jdt.core.dom.ParenthesizedExpression) jdtNode); case ASTNode.POSTFIX_EXPRESSION: return new PostfixExpression((org.eclipse.jdt.core.dom.PostfixExpression) jdtNode); case ASTNode.PREFIX_EXPRESSION: return new PrefixExpression((org.eclipse.jdt.core.dom.PrefixExpression) jdtNode); case ASTNode.PRIMITIVE_TYPE: return new PrimitiveType((org.eclipse.jdt.core.dom.PrimitiveType) jdtNode); case ASTNode.QUALIFIED_NAME: return new QualifiedName((org.eclipse.jdt.core.dom.QualifiedName) jdtNode); case ASTNode.QUALIFIED_TYPE: return new QualifiedType((org.eclipse.jdt.core.dom.QualifiedType) jdtNode); case ASTNode.RETURN_STATEMENT: return new ReturnStatement((org.eclipse.jdt.core.dom.ReturnStatement) jdtNode); case ASTNode.SIMPLE_NAME: return new SimpleName((org.eclipse.jdt.core.dom.SimpleName) jdtNode); case ASTNode.SIMPLE_TYPE: return new SimpleType((org.eclipse.jdt.core.dom.SimpleType) jdtNode); case ASTNode.SINGLE_MEMBER_ANNOTATION: return SingleMemberAnnotation.convert((org.eclipse.jdt.core.dom.SingleMemberAnnotation) jdtNode); case ASTNode.SINGLE_VARIABLE_DECLARATION: return new SingleVariableDeclaration((org.eclipse.jdt.core.dom.SingleVariableDeclaration) jdtNode); case ASTNode.STRING_LITERAL: return new StringLiteral((org.eclipse.jdt.core.dom.StringLiteral) jdtNode); case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return new SuperConstructorInvocation((org.eclipse.jdt.core.dom.SuperConstructorInvocation) jdtNode); case ASTNode.SUPER_FIELD_ACCESS: return new SuperFieldAccess((org.eclipse.jdt.core.dom.SuperFieldAccess) jdtNode); case ASTNode.SUPER_METHOD_INVOCATION: return new SuperMethodInvocation((org.eclipse.jdt.core.dom.SuperMethodInvocation) jdtNode); case ASTNode.SUPER_METHOD_REFERENCE: return new SuperMethodReference((org.eclipse.jdt.core.dom.SuperMethodReference) jdtNode); case ASTNode.SWITCH_CASE: return new SwitchCase((org.eclipse.jdt.core.dom.SwitchCase) jdtNode); case ASTNode.SWITCH_STATEMENT: return new SwitchStatement((org.eclipse.jdt.core.dom.SwitchStatement) jdtNode); case ASTNode.SYNCHRONIZED_STATEMENT: return new SynchronizedStatement((org.eclipse.jdt.core.dom.SynchronizedStatement) jdtNode); case ASTNode.TAG_ELEMENT: return new TagElement((org.eclipse.jdt.core.dom.TagElement) jdtNode); case ASTNode.TEXT_ELEMENT: return new TextElement((org.eclipse.jdt.core.dom.TextElement) jdtNode); case ASTNode.THIS_EXPRESSION: return new ThisExpression((org.eclipse.jdt.core.dom.ThisExpression) jdtNode); case ASTNode.THROW_STATEMENT: return new ThrowStatement((org.eclipse.jdt.core.dom.ThrowStatement) jdtNode); case ASTNode.TRY_STATEMENT: return new TryStatement((org.eclipse.jdt.core.dom.TryStatement) jdtNode); case ASTNode.TYPE_DECLARATION: return new TypeDeclaration((org.eclipse.jdt.core.dom.TypeDeclaration) jdtNode); case ASTNode.TYPE_DECLARATION_STATEMENT: return new TypeDeclarationStatement((org.eclipse.jdt.core.dom.TypeDeclarationStatement) jdtNode); case ASTNode.TYPE_LITERAL: return new TypeLiteral((org.eclipse.jdt.core.dom.TypeLiteral) jdtNode); case ASTNode.TYPE_METHOD_REFERENCE: return new TypeMethodReference((org.eclipse.jdt.core.dom.TypeMethodReference) jdtNode); case ASTNode.UNION_TYPE: return new UnionType((org.eclipse.jdt.core.dom.UnionType) jdtNode); case ASTNode.VARIABLE_DECLARATION_EXPRESSION: return new VariableDeclarationExpression( (org.eclipse.jdt.core.dom.VariableDeclarationExpression) jdtNode); case ASTNode.VARIABLE_DECLARATION_FRAGMENT: return new VariableDeclarationFragment((org.eclipse.jdt.core.dom.VariableDeclarationFragment) jdtNode); case ASTNode.VARIABLE_DECLARATION_STATEMENT: return new VariableDeclarationStatement( (org.eclipse.jdt.core.dom.VariableDeclarationStatement) jdtNode); case ASTNode.WHILE_STATEMENT: return new WhileStatement((org.eclipse.jdt.core.dom.WhileStatement) jdtNode); // These nodes only appear in comments and J2ObjC doens't need any // information from their subtree so we just convert them to TextElement. case ASTNode.MEMBER_REF: case ASTNode.METHOD_REF: case ASTNode.METHOD_REF_PARAMETER: return new TextElement(jdtNode); case ASTNode.COMPILATION_UNIT: throw new AssertionError("CompilationUnit must be converted using convertCompilationUnit()"); default:/*from w w w . j a va 2s. c o m*/ throw new AssertionError("Unknown node type: " + jdtNode.getClass().getName()); } }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://from www .ja v a 2s . c o m * <ul> * <li>For anonymous classes: * <ul> * <li>Anonymous class entity to <code>IEntityWriter</code>.</li> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Extends relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructor to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Parameters for the synthesized constructor to <code>ILocalVariableWriter</code>.</li> * <li>Implicit superconstructor calls to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * <li>Does nothing for enum constant declarations.</li> * </ul> * * Anonymous class fully qualified names (FQNs) adhere to the following format:<br> * parent fqn + $anonymous- + incrementing counter * */ @Override public boolean visit(AnonymousClassDeclaration node) { // If it's an anonymous class if (node.getParent().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) { ClassInstanceCreation parent = (ClassInstanceCreation) node.getParent(); ITypeBinding binding = node.resolveBinding(); // Get the fqn String fqn = fqnStack.find(EnclosingDeclaredType.class).createAnonymousClassFqn(binding); // String fqn = null; // if (binding == null) { // fqn = fqnStack.find(EnclosingDeclaredType.class).getAnonymousClassFqn(); // } else { // fqn = getTypeFqn(binding); // } // Push the stack String parentFqn = fqnStack.getFqn(); Location parentLocation = createLocation(parent); fqnStack.push(fqn, Entity.CLASS); // Visit the children accept(node.bodyDeclarations()); // Write the entity entityWriter.writeEntity(Entity.CLASS, fqn, 0, createMetrics(node), createLocation(node)); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation()); Type superType = parent.getType(); ITypeBinding superBinding = safeResolve(superType); if (superBinding == null) { // Write the uses relation // Can't do extends/implements because unsure if it's an interface or class type // relationWriter.writeUses(fqn, getTypeFqn(superType), getLocation(superType)); } else { if (superBinding.isInterface()) { // Write the implements relation relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, getTypeFqn(superBinding), createLocation(superType)); relationWriter.writeRelation(Relation.EXTENDS, fqn, "java.lang.Object", createUnknownLocation()); } else { // Write the extends relation relationWriter.writeRelation(Relation.EXTENDS, fqn, getTypeFqn(superBinding), createLocation(superType)); } } if (binding != null) { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isConstructor()) { // Write the entity String args = getMethodArgs(method); String rawArgs = getErasedMethodArgs(method); String basicFqn = fqn + ".<init>"; String constructorFqn = basicFqn + args; if (args.equals(rawArgs)) { entityWriter.writeEntity(Entity.CONSTRUCTOR, basicFqn, args, null, method.getModifiers(), null, createUnknownLocation()); } else { entityWriter.writeEntity(Entity.CONSTRUCTOR, basicFqn, args, rawArgs, method.getModifiers(), null, createUnknownLocation()); } // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, fqn, constructorFqn, createUnknownLocation()); // Write the instantiates relation relationWriter.writeRelation(Relation.INSTANTIATES, parentFqn, fqn, parentLocation); // Write the calls relation relationWriter.writeRelation(Relation.CALLS, parentFqn, constructorFqn, parentLocation); // Write the parameters int count = 0; for (ITypeBinding param : method.getParameterTypes()) { localVariableWriter.writeLocalVariable(LocalVariable.PARAM, "(ANONYMOUS)", 0, getTypeFqn(param), createUnknownLocation(), constructorFqn, count++, createUnknownLocation()); } // Reference the superconstructor ITypeBinding superClassBinding = binding.getSuperclass(); if (superClassBinding != null) { superClassBinding = superClassBinding.getErasure(); } if (superClassBinding != null) { String superFqn = getTypeFqn(superClassBinding); String superConstructorFqn = superFqn + ".<init>" + rawArgs; relationWriter.writeRelation(Relation.CALLS, constructorFqn, superConstructorFqn, createUnknownLocation()); } } } } fqnStack.pop(); } else if (node.getParent().getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION) { ITypeBinding binding = node.resolveBinding(); // Get the fqn String parentFqn = fqnStack.getFqn(); String fqn = fqnStack.find(EnclosingDeclaredType.class).createAnonymousClassFqn(binding); fqnStack.push(fqn, Entity.CLASS); // Write the entity entityWriter.writeEntity(Entity.CLASS, fqn, 0, createMetrics(node), createLocation(node)); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation()); // Write the extends relation relationWriter.writeRelation(Relation.EXTENDS, fqn, fqnStack.find(EnclosingDeclaredType.class).getFqn(), createUnknownLocation()); if (binding != null) { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isConstructor()) { // Write the entity String args = getMethodArgs(method); String rawArgs = getErasedMethodArgs(method); String basicFqn = fqn + ".<init>"; String constructorFqn = basicFqn + args; if (args.equals(rawArgs)) { entityWriter.writeEntity(Entity.CONSTRUCTOR, basicFqn, args, null, method.getModifiers(), null, createUnknownLocation()); } else { entityWriter.writeEntity(Entity.CONSTRUCTOR, basicFqn, args, rawArgs, method.getModifiers(), null, createUnknownLocation()); } // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, fqn, constructorFqn, createUnknownLocation()); // // Write the instantiates relation // relationWriter.writeRelation(Relation.INSTANTIATES, parentFqn, fqn, parentLocation); // // // Write the calls relation // relationWriter.writeRelation(Relation.CALLS, parentFqn, constructorFqn, parentLocation); // Write the parameters int count = 0; for (ITypeBinding param : method.getParameterTypes()) { localVariableWriter.writeLocalVariable(LocalVariable.PARAM, "(ANONYMOUS)", 0, getTypeFqn(param), createUnknownLocation(), constructorFqn, count++, createUnknownLocation()); } // Reference the superconstructor ITypeBinding superClassBinding = binding.getSuperclass(); if (superClassBinding != null) { superClassBinding = superClassBinding.getErasure(); } if (superClassBinding != null) { String superFqn = getTypeFqn(superClassBinding); String superConstructorFqn = superFqn + ".<init>" + args; relationWriter.writeRelation(Relation.CALLS, constructorFqn, superConstructorFqn, createUnknownLocation()); } } } } fqnStack.pop(); } else { throw new IllegalStateException("Unexpected parent node type: " + node); } return false; }
From source file:egovframework.mgt.fit.library.parser.visitor.MethodParsingVisitor.java
License:Apache License
/** * ? ? ? ./*from w w w.j a v a 2 s . c om*/ * @return */ private MethodInvoke processInvocation(MethodInvocation node) { method.addParsedInvocation(node.getStartPosition()); MethodInvoke mi = new MethodInvoke(); UnitList<Variable> args = new UnitList<Variable>(); Project p = method.getProject(); for (Object o : node.arguments()) { if (o instanceof SimpleName) { Variable targetField; String argName = ((SimpleName) o).getFullyQualifiedName(); JavaClass checkType = method.getType(); targetField = method.getLocalVariable(argName); while (true) { if (targetField == null) { targetField = checkType.getField(argName); } if (targetField != null) { args.addUnit(targetField); break; } checkType = checkType.getSuperClass(); if (!checkType.isProjectClass()) { DebugLog.log("Failed!!!!"); break; } } } else if (o instanceof Expression) { Expression e = (Expression) o; switch (e.getNodeType()) { case ASTNode.BOOLEAN_LITERAL: args.addUnit(new Variable(p.BOOLEAN_CLASS, ObjectHelper.getUniqueKey("Literal"), String.valueOf(((BooleanLiteral) e).booleanValue()))); break; case ASTNode.CHARACTER_LITERAL: args.addUnit(new Variable(p.CHAR_CLASS, ObjectHelper.getUniqueKey("Literal"), String.valueOf(((CharacterLiteral) e).charValue()))); break; case ASTNode.FIELD_ACCESS: FieldAccess fa = (FieldAccess) e; break; case ASTNode.NULL_LITERAL: args.addUnit(Variable.getNullVariable(p.OBJECT_CLASS, ObjectHelper.getUniqueKey("Literal"))); break; case ASTNode.NUMBER_LITERAL: args.addUnit(parseNumberLiteral(((NumberLiteral) e).getToken(), p)); break; case ASTNode.STRING_LITERAL: args.addUnit(new Variable(p.STRING_CLASS, ObjectHelper.getUniqueKey("Literal"), String.valueOf(((StringLiteral) e).getLiteralValue()))); break; case ASTNode.SUPER_FIELD_ACCESS: break; case ASTNode.THIS_EXPRESSION: break; case ASTNode.MEMBER_REF: break; case ASTNode.METHOD_REF: break; case ASTNode.TYPE_LITERAL: args.addUnit(new Variable(p.TYPE_CLASS, ObjectHelper.getUniqueKey("Literal"), String.valueOf(((TypeLiteral) e)))); break; case ASTNode.PREFIX_EXPRESSION: PrefixExpression pe = (PrefixExpression) e; if (pe.getOperator().equals(PrefixExpression.Operator.PLUS)) { args.addUnit(parseNumberLiteral(pe.getOperand().toString(), p)); } else if (pe.getOperator().equals(PrefixExpression.Operator.MINUS)) { args.addUnit(parseNumberLiteral("-", pe.getOperand().toString(), p)); } default: break; } } } mi.setFromMethod(method); mi.setArguments(args.clone()); String methodKey = StringHelper.getMethodKeyString(node.getName().getFullyQualifiedName(), args); Expression e = node.getExpression(); if (e == null) { // ?? method super ?? method ? // (? Super Method Invocation? // visit) JavaClass checkType = method.getType(); if (node.toString().equals("getCategory(vo,searchVO)")) { System.out.println("!"); } while (true) { if (checkType.isProjectClass()) { for (Method m : checkType.getMethods()) { if (StringHelper.getMethodKeyString(m).equals(methodKey)) { mi.setToMethod(m); break; } } } else { Method toM = new Method(p); toM.setType(checkType); toM.setName(node.getName().getFullyQualifiedName()); toM.setReturnType(p.UNKNOWN_CLASS); for (Variable v : args) { Variable tempParam = new Variable(); tempParam.setName(v.getName()); tempParam.setType(v.getType()); toM.addParameter(tempParam); } mi.setToMethod(toM); break; } if (mi.getToMethod() != null) { break; } checkType = checkType.getSuperClass(); } } else { // ?? switch (e.getNodeType()) { case ASTNode.SIMPLE_NAME: Variable targetField; String argName = ((SimpleName) e).getFullyQualifiedName(); JavaClass checkType = method.getType(); targetField = method.getLocalVariable(argName); JavaClass callType = null; while (true) { if (targetField == null) { targetField = checkType.getField(argName); } if (targetField != null) { callType = targetField.getType(); break; } checkType = checkType.getSuperClass(); if (!checkType.isProjectClass()) { if ((callType = p.resolveClass(ParsingHelper.getFullNameWithSimpleName(argName, checkType.getPackage(), checkType.getImports()))) != null) { break; } break; } } if (callType != null) { if (callType.isProjectClass()) { for (Method m : callType.getMethods()) { if (StringHelper.getMethodKeyString(m).equals(methodKey)) { mi.setToMethod(m); break; } } } else { Method toM = new Method(p); toM.setType(callType); toM.setName(node.getName().getFullyQualifiedName()); toM.setReturnType(p.UNKNOWN_CLASS); for (Variable v : args) { Variable tempParam = new Variable(); tempParam.setName(v.getName()); tempParam.setType(v.getType()); toM.addParameter(tempParam); } mi.setToMethod(toM); } } break; case ASTNode.METHOD_INVOCATION: MethodInvoke mik = processInvocation((MethodInvocation) e); if (mik.getToMethod() == null) { break; } JavaClass jc = mik.getToMethod().getReturnType(); if (jc == null || jc == p.UNKNOWN_CLASS) { break; } for (Method m : jc.getMethods()) { if (StringHelper.getMethodKeyString(m).equals(methodKey)) { mi.setToMethod(m); break; } } break; case ASTNode.STRING_LITERAL: Method toM = new Method(p); toM.setType(p.STRING_CLASS); toM.setName(node.getName().getFullyQualifiedName()); toM.setReturnType(p.UNKNOWN_CLASS); for (Variable v : args) { Variable tempParam = new Variable(); tempParam.setName(v.getName()); tempParam.setType(v.getType()); toM.addParameter(tempParam); } mi.setToMethod(toM); break; case ASTNode.SUPER_METHOD_INVOCATION: toM = new Method(p); toM.setType(method.getType().getSuperClass()); toM.setName(node.getName().getFullyQualifiedName()); toM.setReturnType(p.UNKNOWN_CLASS); for (Variable v : args) { Variable tempParam = new Variable(); tempParam.setName(v.getName()); tempParam.setType(v.getType()); toM.addParameter(tempParam); } mi.setToMethod(toM); break; case ASTNode.PARENTHESIZED_EXPRESSION: break; case ASTNode.ARRAY_ACCESS: break; case ASTNode.FIELD_ACCESS: break; case ASTNode.THIS_EXPRESSION: break; case ASTNode.QUALIFIED_NAME: break; case ASTNode.CLASS_INSTANCE_CREATION: ClassInstanceCreation cic = (ClassInstanceCreation) e; JavaClass createdType = p.resolveClass(ParsingHelper.getFullNameWithSimpleName( cic.getType().toString(), method.getType().getPackage(), method.getType().getImports())); for (Method m : createdType.getMethods()) { if (StringHelper.getMethodKeyString(m).equals(methodKey)) { mi.setToMethod(m); break; } } break; default: } // System.out.println("--->"+node.getExpression().toString()); } if (mi.getFromMethod() != null && mi.getToMethod() != null) { p.addInvocation(mi); } else { //System.out.println("Fail....TT"); } return mi; // System.out.println("invoke : " + node.toString()); }