本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall类的典型用法代码示例。如果您正苦于以下问题:Java ExplicitConstructorCall类的具体用法?Java ExplicitConstructorCall怎么用?Java ExplicitConstructorCall使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExplicitConstructorCall类属于org.eclipse.jdt.internal.compiler.ast包,在下文中一共展示了ExplicitConstructorCall类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrapWithExplicitConstructorCallIfNeeded
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
/**
* If the given ast node is inside an explicit constructor call
* then wrap it with a fake constructor call.
* Returns the wrapped completion node or the completion node itself.
*/
protected ASTNode wrapWithExplicitConstructorCallIfNeeded(ASTNode ast) {
int selector;
if (ast != null && topKnownElementKind(ASSIST_PARSER) == K_SELECTOR && ast instanceof Expression &&
(((selector = topKnownElementInfo(ASSIST_PARSER)) == THIS_CONSTRUCTOR) ||
(selector == SUPER_CONSTRUCTOR))) {
ExplicitConstructorCall call = new ExplicitConstructorCall(
(selector == THIS_CONSTRUCTOR) ?
ExplicitConstructorCall.This :
ExplicitConstructorCall.Super
);
call.arguments = new Expression[] {(Expression)ast};
call.sourceStart = ast.sourceStart;
call.sourceEnd = ast.sourceEnd;
return call;
} else {
return ast;
}
}
示例2: unhandledException
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
public void unhandledException(TypeBinding exceptionType, ASTNode location) {
boolean insideDefaultConstructor =
(this.referenceContext instanceof ConstructorDeclaration)
&& ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
boolean insideImplicitConstructorCall =
(location instanceof ExplicitConstructorCall)
&& (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
int sourceEnd = location.sourceEnd;
if (location instanceof LocalDeclaration) {
sourceEnd = ((LocalDeclaration) location).declarationEnd;
}
this.handle(
insideDefaultConstructor
? IProblem.UnhandledExceptionInDefaultConstructor
: (insideImplicitConstructorCall
? IProblem.UndefinedConstructorInImplicitConstructorCall
: IProblem.UnhandledException),
new String[] {new String(exceptionType.readableName())},
new String[] {new String(exceptionType.shortReadableName())},
location.sourceStart,
sourceEnd);
}
示例3: createPrivateDefaultConstructor
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
private void createPrivateDefaultConstructor(EclipseNode typeNode, EclipseNode sourceNode) {
ASTNode source = sourceNode.get();
TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get());
long p = (long) source.sourceStart << 32 | source.sourceEnd;
ConstructorDeclaration constructor = new ConstructorDeclaration(((CompilationUnitDeclaration) typeNode.top().get()).compilationResult);
constructor.modifiers = ClassFileConstants.AccPrivate;
constructor.selector = typeDeclaration.name;
constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
constructor.constructorCall.sourceStart = source.sourceStart;
constructor.constructorCall.sourceEnd = source.sourceEnd;
constructor.thrownExceptions = null;
constructor.typeParameters = null;
constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
constructor.arguments = null;
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length];
Arrays.fill(ps, p);
exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps);
setGeneratedBy(exception.type, source);
exception.arguments = new Expression[] {
new StringLiteral(UNSUPPORTED_MESSAGE, source.sourceStart, source.sourceEnd, 0)
};
setGeneratedBy(exception.arguments[0], source);
ThrowStatement throwStatement = new ThrowStatement(exception, source.sourceStart, source.sourceEnd);
setGeneratedBy(throwStatement, source);
constructor.statements = new Statement[] {throwStatement};
injectMethod(typeNode, constructor);
}
示例4: handleMethod
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
public void handleMethod(EclipseNode annotation, AbstractMethodDeclaration method, List<DeclaredException> exceptions) {
if (method.isAbstract()) {
annotation.addError("@SneakyThrows can only be used on concrete methods.");
return;
}
if (method.statements == null || method.statements.length == 0) {
boolean hasConstructorCall = false;
if (method instanceof ConstructorDeclaration) {
ExplicitConstructorCall constructorCall = ((ConstructorDeclaration) method).constructorCall;
hasConstructorCall = constructorCall != null && !constructorCall.isImplicitSuper() && !constructorCall.isImplicitThis();
}
if (hasConstructorCall) {
annotation.addWarning("Calls to sibling / super constructors are always excluded from @SneakyThrows; @SneakyThrows has been ignored because there is no other code in this constructor.");
} else {
annotation.addWarning("This method or constructor is empty; @SneakyThrows has been ignored.");
}
return;
}
Statement[] contents = method.statements;
for (DeclaredException exception : exceptions) {
contents = new Statement[] { buildTryCatchBlock(contents, exception, exception.node, method) };
}
method.statements = contents;
annotation.up().rebuild();
}
示例5: resolve
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
@Override
@Nullable
public ResolvedNode resolve(@NonNull JavaContext context, @NonNull Node node) {
Object nativeNode = getNativeNode(node);
if (nativeNode == null) {
return null;
}
if (nativeNode instanceof NameReference) {
return resolve(((NameReference) nativeNode).binding);
} else if (nativeNode instanceof TypeReference) {
return resolve(((TypeReference) nativeNode).resolvedType);
} else if (nativeNode instanceof MessageSend) {
return resolve(((MessageSend) nativeNode).binding);
} else if (nativeNode instanceof AllocationExpression) {
return resolve(((AllocationExpression) nativeNode).binding);
} else if (nativeNode instanceof TypeDeclaration) {
return resolve(((TypeDeclaration) nativeNode).binding);
} else if (nativeNode instanceof ExplicitConstructorCall) {
return resolve(((ExplicitConstructorCall) nativeNode).binding);
} else if (nativeNode instanceof Annotation) {
return resolve(((Annotation) nativeNode).resolvedType);
} else if (nativeNode instanceof AbstractMethodDeclaration) {
return resolve(((AbstractMethodDeclaration) nativeNode).binding);
} else if (nativeNode instanceof AbstractVariableDeclaration) {
if (nativeNode instanceof LocalDeclaration) {
return resolve(((LocalDeclaration) nativeNode).binding);
} else if (nativeNode instanceof FieldDeclaration) {
return resolve(((FieldDeclaration) nativeNode).binding);
}
}
// TODO: Handle org.eclipse.jdt.internal.compiler.ast.SuperReference. It
// doesn't contain an actual method binding; the parent node call should contain
// it, but is missing a native node reference; investigate the ECJ bridge's super
// handling.
return null;
}
示例6: resolveConstructor
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
synchronized IMethodBinding resolveConstructor(ConstructorInvocation expression) {
org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
if (node instanceof ExplicitConstructorCall) {
ExplicitConstructorCall explicitConstructorCall = (ExplicitConstructorCall) node;
return getMethodBinding(explicitConstructorCall.binding);
}
return null;
}
示例7: consumeExplicitConstructorInvocation
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
protected void consumeExplicitConstructorInvocation(int flag, int recFlag) {
/* flag allows to distinguish 3 cases :
(0) :
ExplicitConstructorInvocation ::= 'this' '(' ArgumentListopt ')' ';'
ExplicitConstructorInvocation ::= 'super' '(' ArgumentListopt ')' ';'
(1) :
ExplicitConstructorInvocation ::= Primary '.' 'super' '(' ArgumentListopt ')' ';'
ExplicitConstructorInvocation ::= Primary '.' 'this' '(' ArgumentListopt ')' ';'
(2) :
ExplicitConstructorInvocation ::= Name '.' 'super' '(' ArgumentListopt ')' ';'
ExplicitConstructorInvocation ::= Name '.' 'this' '(' ArgumentListopt ')' ';'
*/
int startPosition = this.intStack[this.intPtr--];
ExplicitConstructorCall ecc = new ExplicitConstructorCall(recFlag);
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
this.expressionPtr -= length;
System.arraycopy(this.expressionStack, this.expressionPtr + 1, ecc.arguments = new Expression[length], 0, length);
}
switch (flag) {
case 0 :
ecc.sourceStart = startPosition;
break;
case 1 :
this.expressionLengthPtr--;
ecc.sourceStart = (ecc.qualification = this.expressionStack[this.expressionPtr--]).sourceStart;
break;
case 2 :
ecc.sourceStart = (ecc.qualification = getUnspecifiedReferenceOptimized()).sourceStart;
break;
}
pushOnAstStack(ecc);
ecc.sourceEnd = this.endStatementPosition;
}
示例8: cannotInvokeSuperConstructorInEnum
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
public void cannotInvokeSuperConstructorInEnum(ExplicitConstructorCall constructorCall, MethodBinding enumConstructor) {
this.handle(
IProblem.CannotInvokeSuperConstructorInEnum,
new String[] {
new String(enumConstructor.declaringClass.sourceName()),
typesAsString(enumConstructor, false),
},
new String[] {
new String(enumConstructor.declaringClass.sourceName()),
typesAsString(enumConstructor, true),
},
constructorCall.sourceStart,
constructorCall.sourceEnd);
}
示例9: noSuchEnclosingInstance
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
public void noSuchEnclosingInstance(TypeBinding targetType, ASTNode location, boolean isConstructorCall) {
int id;
if (isConstructorCall) {
//28 = No enclosing instance of type {0} is available due to some intermediate constructor invocation
id = IProblem.EnclosingInstanceInConstructorCall;
} else if ((location instanceof ExplicitConstructorCall)
&& ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
//20 = No enclosing instance of type {0} is accessible to invoke the super constructor. Must define a constructor and explicitly qualify its super constructor invocation with an instance of {0} (e.g. x.super() where x is an instance of {0}).
id = IProblem.MissingEnclosingInstanceForConstructorCall;
} else if (location instanceof AllocationExpression
&& (((AllocationExpression) location).binding.declaringClass.isMemberType()
|| (((AllocationExpression) location).binding.declaringClass.isAnonymousType()
&& ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) {
//21 = No enclosing instance of type {0} is accessible. Must qualify the allocation with an enclosing instance of type {0} (e.g. x.new A() where x is an instance of {0}).
id = IProblem.MissingEnclosingInstance;
} else { // default
//22 = No enclosing instance of the type {0} is accessible in scope
id = IProblem.IncorrectEnclosingInstanceReference;
}
this.handle(
id,
new String[] { new String(targetType.readableName())},
new String[] { new String(targetType.shortReadableName())},
location.sourceStart,
location.sourceEnd);
}
示例10: recursiveConstructorInvocation
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
this.handle(
IProblem.RecursiveConstructorInvocation,
new String[] {
new String(constructorCall.binding.declaringClass.readableName()),
typesAsString(constructorCall.binding, false)
},
new String[] {
new String(constructorCall.binding.declaringClass.shortReadableName()),
typesAsString(constructorCall.binding, true)
},
constructorCall.sourceStart,
constructorCall.sourceEnd);
}
示例11: handleMethod
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
private void handleMethod(EclipseNode annotation, AbstractMethodDeclaration method, List<DeclaredException> exceptions) {
if (method.isAbstract()) {
annotation.addError("@SneakyThrows can only be used on concrete methods.");
return;
}
if (method.statements == null || method.statements.length == 0) {
boolean hasConstructorCall = false;
if (method instanceof ConstructorDeclaration) {
ExplicitConstructorCall constructorCall = ((ConstructorDeclaration) method).constructorCall;
hasConstructorCall = constructorCall != null && !constructorCall.isImplicitSuper() && !constructorCall.isImplicitThis();
}
if (hasConstructorCall) {
annotation.addWarning("Calls to sibling / super constructors are always excluded from @SneakyThrows; @SneakyThrows has been ignored because there is no other code in this constructor.");
} else {
annotation.addWarning("This method or constructor is empty; @SneakyThrows has been ignored.");
}
return;
}
Statement[] contents = method.statements;
for (DeclaredException exception : exceptions) {
contents = new Statement[] { buildTryCatchBlock(contents, exception, exception.node, method) };
}
method.statements = contents;
annotation.up().rebuild();
}
示例12: visit
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
@Override public boolean visit(ExplicitConstructorCall node, BlockScope scope) {
fixPositions(setGeneratedBy(node, source));
return super.visit(node, scope);
}
示例13: createConstructor
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
public static ConstructorDeclaration createConstructor(
AccessLevel level, EclipseNode type, Collection<EclipseNode> fields,
Boolean suppressConstructorProperties, EclipseNode sourceNode, List<Annotation> onConstructor) {
ASTNode source = sourceNode.get();
TypeDeclaration typeDeclaration = ((TypeDeclaration)type.get());
long p = (long)source.sourceStart << 32 | source.sourceEnd;
boolean isEnum = (((TypeDeclaration)type.get()).modifiers & ClassFileConstants.AccEnum) != 0;
if (isEnum) level = AccessLevel.PRIVATE;
if (suppressConstructorProperties == null) {
if (fields.isEmpty()) {
suppressConstructorProperties = false;
} else {
suppressConstructorProperties = Boolean.TRUE.equals(type.getAst().readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES));
}
}
ConstructorDeclaration constructor = new ConstructorDeclaration(
((CompilationUnitDeclaration) type.top().get()).compilationResult);
constructor.modifiers = toEclipseModifier(level);
constructor.selector = typeDeclaration.name;
constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
constructor.constructorCall.sourceStart = source.sourceStart;
constructor.constructorCall.sourceEnd = source.sourceEnd;
constructor.thrownExceptions = null;
constructor.typeParameters = null;
constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
constructor.arguments = null;
List<Argument> params = new ArrayList<Argument>();
List<Statement> assigns = new ArrayList<Statement>();
List<Statement> nullChecks = new ArrayList<Statement>();
for (EclipseNode fieldNode : fields) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
char[] rawName = field.name;
char[] fieldName = removePrefixFromField(fieldNode);
FieldReference thisX = new FieldReference(rawName, p);
thisX.receiver = new ThisReference((int)(p >> 32), (int)p);
SingleNameReference assignmentNameRef = new SingleNameReference(fieldName, p);
Assignment assignment = new Assignment(thisX, assignmentNameRef, (int)p);
assignment.sourceStart = (int)(p >> 32); assignment.sourceEnd = assignment.statementEnd = (int)(p >> 32);
assigns.add(assignment);
long fieldPos = (((long)field.sourceStart) << 32) | field.sourceEnd;
Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source), Modifier.FINAL);
Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
if (nonNulls.length != 0) {
Statement nullCheck = generateNullCheck(field, sourceNode);
if (nullCheck != null) nullChecks.add(nullCheck);
}
parameter.annotations = copyAnnotations(source, nonNulls, nullables);
params.add(parameter);
}
nullChecks.addAll(assigns);
constructor.statements = nullChecks.isEmpty() ? null : nullChecks.toArray(new Statement[nullChecks.size()]);
constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]);
/* Generate annotations that must be put on the generated method, and attach them. */ {
Annotation[] constructorProperties = null;
if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && level != AccessLevel.PACKAGE && !isLocalType(type)) {
constructorProperties = createConstructorProperties(source, fields);
}
constructor.annotations = copyAnnotations(source,
onConstructor.toArray(new Annotation[0]),
constructorProperties);
}
constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope);
return constructor;
}
示例14: consumeMethodInvocationName
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
protected void consumeMethodInvocationName() {
// MethodInvocation ::= Name '(' ArgumentListopt ')'
// when the name is only an identifier...we have a message send to "this" (implicit)
char[] selector = this.identifierStack[this.identifierPtr];
int accessMode;
if(selector == assistIdentifier()) {
if(CharOperation.equals(selector, SUPER)) {
accessMode = ExplicitConstructorCall.Super;
} else if(CharOperation.equals(selector, THIS)) {
accessMode = ExplicitConstructorCall.This;
} else {
super.consumeMethodInvocationName();
return;
}
} else {
super.consumeMethodInvocationName();
return;
}
final ExplicitConstructorCall constructorCall = new SelectionOnExplicitConstructorCall(accessMode);
constructorCall.sourceEnd = this.rParenPos;
constructorCall.sourceStart = (int) (this.identifierPositionStack[this.identifierPtr] >>> 32);
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
this.expressionPtr -= length;
System.arraycopy(this.expressionStack, this.expressionPtr + 1, constructorCall.arguments = new Expression[length], 0, length);
}
if (!this.diet){
pushOnAstStack(constructorCall);
this.restartRecovery = true; // force to restart in recovery mode
this.lastIgnoredToken = -1;
} else {
pushOnExpressionStack(new Expression(){
public TypeBinding resolveType(BlockScope scope) {
constructorCall.resolve(scope);
return null;
}
public StringBuffer printExpression(int indent, StringBuffer output) {
return output;
}
});
}
this.assistNode = constructorCall;
this.lastCheckPoint = constructorCall.sourceEnd + 1;
this.isOrphanCompletionNode = true;
}
示例15: consumeMethodInvocationPrimary
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; //导入依赖的package包/类
protected void consumeMethodInvocationPrimary() {
//optimize the push/pop
//MethodInvocation ::= Primary '.' 'Identifier' '(' ArgumentListopt ')'
char[] selector = this.identifierStack[this.identifierPtr];
int accessMode;
if(selector == assistIdentifier()) {
if(CharOperation.equals(selector, SUPER)) {
accessMode = ExplicitConstructorCall.Super;
} else if(CharOperation.equals(selector, THIS)) {
accessMode = ExplicitConstructorCall.This;
} else {
super.consumeMethodInvocationPrimary();
return;
}
} else {
super.consumeMethodInvocationPrimary();
return;
}
final ExplicitConstructorCall constructorCall = new SelectionOnExplicitConstructorCall(accessMode);
constructorCall.sourceEnd = this.rParenPos;
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
this.expressionPtr -= length;
System.arraycopy(this.expressionStack, this.expressionPtr + 1, constructorCall.arguments = new Expression[length], 0, length);
}
constructorCall.qualification = this.expressionStack[this.expressionPtr--];
constructorCall.sourceStart = constructorCall.qualification.sourceStart;
if (!this.diet){
pushOnAstStack(constructorCall);
this.restartRecovery = true; // force to restart in recovery mode
this.lastIgnoredToken = -1;
} else {
pushOnExpressionStack(new Expression(){
public TypeBinding resolveType(BlockScope scope) {
constructorCall.resolve(scope);
return null;
}
public StringBuffer printExpression(int indent, StringBuffer output) {
return output;
}
});
}
this.assistNode = constructorCall;
this.lastCheckPoint = constructorCall.sourceEnd + 1;
this.isOrphanCompletionNode = true;
}